2024-02-14 20:33:07 +00:00
|
|
|
//! This example demonstrates how to create an overlay window with dioxus.
|
|
|
|
//!
|
|
|
|
//! Basically, we just create a new window with a transparent background and no decorations, size it to the screen, and
|
|
|
|
//! then we can draw whatever we want on it. In this case, we're drawing a simple overlay with a draggable header.
|
|
|
|
//!
|
|
|
|
//! We also add a global shortcut to toggle the overlay on and off, so you could build a raycast-type app with this.
|
|
|
|
|
|
|
|
use dioxus::desktop::{
|
2024-02-14 21:50:10 +00:00
|
|
|
tao::dpi::PhysicalPosition, use_global_shortcut, LogicalSize, WindowBuilder,
|
2024-02-14 20:33:07 +00:00
|
|
|
};
|
2022-12-31 03:14:28 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
2024-01-31 01:59:57 +00:00
|
|
|
LaunchBuilder::desktop().with_cfg(make_config()).launch(app);
|
2022-12-31 03:14:28 +00:00
|
|
|
}
|
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn app() -> Element {
|
2024-02-14 20:33:07 +00:00
|
|
|
let mut show_overlay = use_signal(|| true);
|
2022-12-31 03:30:04 +00:00
|
|
|
|
2024-02-14 21:50:10 +00:00
|
|
|
_ = use_global_shortcut("cmd+g", move || show_overlay.toggle());
|
2024-02-14 20:33:07 +00:00
|
|
|
|
|
|
|
rsx! {
|
2024-07-25 21:58:00 +00:00
|
|
|
head::Link {
|
|
|
|
rel: "stylesheet",
|
|
|
|
href: asset!("./examples/assets/overlay.css"),
|
|
|
|
}
|
2024-02-14 20:33:07 +00:00
|
|
|
if show_overlay() {
|
2022-12-31 03:30:04 +00:00
|
|
|
div {
|
|
|
|
width: "100%",
|
2024-02-14 20:33:07 +00:00
|
|
|
height: "100%",
|
|
|
|
background_color: "red",
|
|
|
|
border: "1px solid black",
|
|
|
|
|
|
|
|
div {
|
|
|
|
width: "100%",
|
|
|
|
height: "10px",
|
|
|
|
background_color: "black",
|
|
|
|
onmousedown: move |_| dioxus::desktop::window().drag(),
|
|
|
|
}
|
2022-12-31 03:30:04 +00:00
|
|
|
|
2024-02-14 20:33:07 +00:00
|
|
|
"This is an overlay!"
|
|
|
|
}
|
2022-12-31 03:14:28 +00:00
|
|
|
}
|
2024-01-14 05:12:21 +00:00
|
|
|
}
|
2022-12-31 03:14:28 +00:00
|
|
|
}
|
|
|
|
|
2024-01-20 00:36:40 +00:00
|
|
|
fn make_config() -> dioxus::desktop::Config {
|
2024-07-25 21:58:00 +00:00
|
|
|
dioxus::desktop::Config::default().with_window(make_window())
|
2022-12-31 03:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn make_window() -> WindowBuilder {
|
|
|
|
WindowBuilder::new()
|
|
|
|
.with_transparent(true)
|
|
|
|
.with_decorations(false)
|
|
|
|
.with_resizable(false)
|
|
|
|
.with_always_on_top(true)
|
|
|
|
.with_position(PhysicalPosition::new(0, 0))
|
|
|
|
.with_max_inner_size(LogicalSize::new(100000, 50))
|
2022-12-31 03:14:28 +00:00
|
|
|
}
|