dioxus/examples/window_focus.rs

34 lines
945 B
Rust
Raw Normal View History

2023-01-13 00:48:23 +00:00
use dioxus::prelude::*;
2024-01-05 20:54:39 +00:00
use dioxus_desktop::tao::event::Event as WryEvent;
2023-01-13 00:48:23 +00:00
use dioxus_desktop::tao::event::WindowEvent;
use dioxus_desktop::use_wry_event_handler;
2023-07-04 12:48:05 +00:00
use dioxus_desktop::{Config, WindowCloseBehaviour};
2023-01-13 00:48:23 +00:00
fn main() {
2024-01-18 20:32:01 +00:00
LaunchBuilder::new()
.with_cfg(Config::new().with_close_behaviour(WindowCloseBehaviour::CloseWindow))
2024-01-18 20:32:01 +00:00
.launch(app)
2023-01-13 00:48:23 +00:00
}
fn app() -> Element {
let mut focused = use_signal(|| false);
2023-01-13 00:48:23 +00:00
2024-01-15 21:06:05 +00:00
use_wry_event_handler(move |event, _| match event {
WryEvent::WindowEvent {
2024-01-14 05:12:21 +00:00
event: WindowEvent::Focused(new_focused),
..
2024-01-15 21:06:05 +00:00
} => focused.set(*new_focused),
_ => {}
2023-01-13 00:48:23 +00:00
});
2024-01-16 19:18:46 +00:00
rsx! {
div { width: "100%", height: "100%", display: "flex", flex_direction: "column", align_items: "center",
if focused() {
2024-01-15 21:06:05 +00:00
"This window is focused!"
} else {
"This window is not focused!"
2023-01-13 00:48:23 +00:00
}
}
2024-01-14 05:12:21 +00:00
}
2023-01-13 00:48:23 +00:00
}