Renderer
This commit is contained in:
@@ -35,5 +35,13 @@ fn app(cx: &Arc<Context>) -> 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}"));
|
||||
}
|
||||
|
||||
+16
-5
@@ -30,7 +30,7 @@ pub struct Area {
|
||||
#[derive(Clone)]
|
||||
pub struct DrawContext {
|
||||
pub area: Area,
|
||||
pub allocated: Size,
|
||||
pub allocated: Area,
|
||||
pub drawing: Vec<DrawInstruction>,
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user