dioxus/examples/window_focus.rs

36 lines
967 B
Rust
Raw Normal View History

2024-01-20 00:36:40 +00: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-13 00:48:23 +00:00
use dioxus::prelude::*;
fn main() {
LaunchBuilder::desktop()
.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 {
2024-01-20 08:11:55 +00:00
let mut focused = use_signal(|| true);
2023-01-13 00:48:23 +00:00
2024-01-31 02:29:49 +00:00
use_wry_event_handler(move |event, _| {
if let WryEvent::WindowEvent {
2024-01-14 05:12:21 +00:00
event: WindowEvent::Focused(new_focused),
..
2024-01-31 02:29:49 +00:00
} = event
{
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
}