Floyd Wang 2025-03-29 11:02:15 +08:00 committed by GitHub
parent f86977e2a7
commit b4254a33e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 111 additions and 2 deletions

View file

@ -75,7 +75,7 @@ impl Render for WindowDemo {
.bg(rgb(0xffffff))
.size_full()
.justify_center()
.items_center()
.content_center()
.gap_2()
.child(button("Normal", move |_, cx| {
cx.open_window(
@ -165,18 +165,32 @@ impl Render for WindowDemo {
})
.detach();
}))
.child(button("Resize", |window, _| {
let content_size = window.bounds().size;
window.resize(size(content_size.height, content_size.width));
}))
}
}
fn main() {
Application::new().run(|cx: &mut App| {
let bounds = Bounds::centered(None, size(px(800.0), px(600.0)), cx);
cx.open_window(
WindowOptions {
window_bounds: Some(WindowBounds::Windowed(bounds)),
..Default::default()
},
|_, cx| cx.new(|_| WindowDemo {}),
|window, cx| {
cx.new(|cx| {
cx.observe_window_bounds(window, move |_, window, _| {
println!("Window bounds changed: {:?}", window.bounds());
})
.detach();
WindowDemo {}
})
},
)
.unwrap();
});