Render position
This commit is contained in:
+15
-1
@@ -23,7 +23,21 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn app(cx: &Arc<Context>) -> View {
|
fn app(cx: &Arc<Context>) -> View {
|
||||||
cx.child(my_component, None);
|
cx.child(
|
||||||
|
my_component,
|
||||||
|
Some(Arc::new(|ctx, view| {
|
||||||
|
let area = ctx.allocate(0, 0, 0, 0);
|
||||||
|
ctx.draw_view(area, view)
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
cx.child(
|
||||||
|
my_component,
|
||||||
|
Some(Arc::new(|ctx, view| {
|
||||||
|
let area = ctx.allocate(0, 1, 0, 0);
|
||||||
|
ctx.draw_view(area, view)
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
Arc::new({
|
Arc::new({
|
||||||
let cx = cx.clone();
|
let cx = cx.clone();
|
||||||
|
|||||||
+1
-1
@@ -138,7 +138,7 @@ impl Context {
|
|||||||
if let Some(view_wrapper) = view_wrapper {
|
if let Some(view_wrapper) = view_wrapper {
|
||||||
view_wrapper(ctx, view)
|
view_wrapper(ctx, view)
|
||||||
} else {
|
} else {
|
||||||
ctx.draw_view(ctx.allocated.clone(), view);
|
ctx.draw_view(ctx.area.clone(), view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-2
@@ -1,4 +1,9 @@
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::{
|
||||||
|
io::{stdout, Write},
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
};
|
||||||
|
|
||||||
|
use crossterm::{cursor::MoveTo, execute, terminal::Clear};
|
||||||
|
|
||||||
use crate::{prelude::Context, render::Area, DrawContext, View};
|
use crate::{prelude::Context, render::Area, DrawContext, View};
|
||||||
|
|
||||||
@@ -37,6 +42,10 @@ impl Console {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (width, height) = crossterm::terminal::size().unwrap();
|
let (width, height) = crossterm::terminal::size().unwrap();
|
||||||
|
|
||||||
|
execute!(stdout(), Clear(crossterm::terminal::ClearType::Purge)).unwrap();
|
||||||
|
execute!(stdout(), Clear(crossterm::terminal::ClearType::All)).unwrap();
|
||||||
|
|
||||||
self.draw_context(&self.render_view(
|
self.draw_context(&self.render_view(
|
||||||
&Area {
|
&Area {
|
||||||
x: 0,
|
x: 0,
|
||||||
@@ -62,7 +71,12 @@ impl Engine for Console {
|
|||||||
fn draw_context(&self, ctx: &DrawContext) {
|
fn draw_context(&self, ctx: &DrawContext) {
|
||||||
for inst in &ctx.drawing {
|
for inst in &ctx.drawing {
|
||||||
match inst {
|
match inst {
|
||||||
crate::render::DrawInstruction::Text(_point, text) => println!("{text}"),
|
crate::render::DrawInstruction::Text(point, text) => {
|
||||||
|
let (x, y) = (ctx.area.x + point.x, ctx.area.y + point.y);
|
||||||
|
execute!(stdout(), MoveTo(x, y),).unwrap();
|
||||||
|
print!("{text}");
|
||||||
|
stdout().flush().unwrap();
|
||||||
|
}
|
||||||
crate::render::DrawInstruction::Child(_point, child) => self.draw_context(child),
|
crate::render::DrawInstruction::Child(_point, child) => self.draw_context(child),
|
||||||
crate::render::DrawInstruction::View(area, view) => {
|
crate::render::DrawInstruction::View(area, view) => {
|
||||||
self.draw_context(&self.render_view(area, view))
|
self.draw_context(&self.render_view(area, view))
|
||||||
|
|||||||
Reference in New Issue
Block a user