dioxus/examples/window_focus.rs

34 lines
952 B
Rust
Raw Normal View History

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