View plugins

This commit is contained in:
2026-02-01 16:34:27 +01:00
parent d40a032bc1
commit b0eaa76398
3 changed files with 73 additions and 3 deletions
+7
View File
@@ -8,6 +8,7 @@ pub fn main() {
#[component]
fn App(cx: &Arc<Context>) -> View {
rsx! {
impl my_center(11, 1)
Card { content: "Hello World".to_string() }
}
.view(&cx)
@@ -22,3 +23,9 @@ fn Card(cx: &Arc<Context>, content: String) -> View {
}
.view(&cx)
}
fn my_center(ctx: &mut DrawContext, view: View, w: u16, h: u16) {
let (x, y) = ((ctx.area.width - w) / 2, (ctx.area.height - h) / 2);
let area = ctx.allocate(x, y, w, h);
ctx.draw_view(area, view);
}