This commit is contained in:
2026-01-24 14:47:53 +01:00
parent 1f9bf48bb4
commit 0f12a371e5
2 changed files with 24 additions and 5 deletions
+8
View File
@@ -35,5 +35,13 @@ fn app(cx: &Arc<Context>) -> View {
Arc::new(move |ctx| { Arc::new(move |ctx| {
ctx.draw_text(Point { x: 0, y: 0 }, &format!("Count: {count}")); 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}"));
}
+16 -5
View File
@@ -30,7 +30,7 @@ pub struct Area {
#[derive(Clone)] #[derive(Clone)]
pub struct DrawContext { pub struct DrawContext {
pub area: Area, pub area: Area,
pub allocated: Size, pub allocated: Area,
pub drawing: Vec<DrawInstruction>, pub drawing: Vec<DrawInstruction>,
} }
@@ -38,7 +38,9 @@ impl DrawContext {
pub fn new(area: Area) -> Self { pub fn new(area: Area) -> Self {
Self { Self {
area, area,
allocated: Size { allocated: Area {
x: u16::MAX,
y: u16::MAX,
width: 0, width: 0,
height: 0, height: 0,
}, },
@@ -46,9 +48,18 @@ impl DrawContext {
} }
} }
pub fn allocate(&mut self, width: u16, height: u16) { pub fn allocate(&mut self, x: u16, y: u16, width: u16, height: u16) -> Area {
self.allocated.width += width; self.allocated.x = self.allocated.x.min(x);
self.allocated.height += height; 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) { pub fn draw(&mut self, inst: DrawInstruction) {