From 0f12a371e5a694f2499feda5122360f0700281ea Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 24 Jan 2026 14:47:53 +0100 Subject: [PATCH] Renderer --- examples/hello_world.rs | 8 ++++++++ src/render.rs | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 7e30dd4..8e8f787 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -35,5 +35,13 @@ fn app(cx: &Arc) -> View { Arc::new(move |ctx| { ctx.draw_text(Point { x: 0, y: 0 }, &format!("Count: {count}")); + let area = ctx.allocate(0, 0, 10, 10); + ctx.draw_view(area, Arc::new(my_view)); }) } + +fn my_view(ctx: &mut DrawContext) { + let count = 67; + + ctx.draw_text(Point { x: 0, y: 0 }, &format!("Count: {count}")); +} diff --git a/src/render.rs b/src/render.rs index efed6ec..fadbe84 100644 --- a/src/render.rs +++ b/src/render.rs @@ -30,7 +30,7 @@ pub struct Area { #[derive(Clone)] pub struct DrawContext { pub area: Area, - pub allocated: Size, + pub allocated: Area, pub drawing: Vec, } @@ -38,7 +38,9 @@ impl DrawContext { pub fn new(area: Area) -> Self { Self { area, - allocated: Size { + allocated: Area { + x: u16::MAX, + y: u16::MAX, width: 0, height: 0, }, @@ -46,9 +48,18 @@ impl DrawContext { } } - pub fn allocate(&mut self, width: u16, height: u16) { - self.allocated.width += width; - self.allocated.height += height; + pub fn allocate(&mut self, x: u16, y: u16, width: u16, height: u16) -> Area { + self.allocated.x = self.allocated.x.min(x); + self.allocated.y = self.allocated.y.min(y); + self.allocated.width = self.allocated.width.max(width); + self.allocated.height = self.allocated.height.max(height); + + Area { + x, + y, + width, + height, + } } pub fn draw(&mut self, inst: DrawInstruction) {