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-16 14:42:16 +00:00
|
|
|
LaunchBuilder::new(app)
|
|
|
|
.cfg(Config::new().with_close_behaviour(WindowCloseBehaviour::CloseWindow))
|
2024-01-16 17:45:02 +00:00
|
|
|
.launch_desktop()
|
2023-01-13 00:48:23 +00:00
|
|
|
}
|
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-16 07:24:59 +00:00
|
|
|
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! {
|
2024-01-16 14:42:16 +00:00
|
|
|
div { width: "100%", height: "100%", display: "flex", flex_direction: "column", align_items: "center",
|
2024-01-16 05:12:44 +00:00
|
|
|
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
|
|
|
}
|