View plugins
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user