From d3ab397ad31d7ebb8606b5941e19f5a4601ddaf8 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 30 Dec 2022 22:30:04 -0500 Subject: [PATCH] chore: add transparency and overlay --- Cargo.toml | 2 +- examples/overlay.rs | 65 ++++++++++++++++++------- packages/desktop/src/desktop_context.rs | 4 +- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 606aef6be..af5e8a733 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ publish = false [dev-dependencies] dioxus = { path = "./packages/dioxus" } -dioxus-desktop = { path = "./packages/desktop" } +dioxus-desktop = { path = "./packages/desktop", features = ["transparent"] } dioxus-ssr = { path = "./packages/ssr" } dioxus-router = { path = "./packages/router" } fermi = { path = "./packages/fermi" } diff --git a/examples/overlay.rs b/examples/overlay.rs index 6ec3ef56f..359fa5169 100644 --- a/examples/overlay.rs +++ b/examples/overlay.rs @@ -1,8 +1,8 @@ use dioxus::prelude::*; -use dioxus_desktop::{use_window, WindowBuilder}; +use dioxus_desktop::{tao::dpi::PhysicalPosition, use_window, Config, LogicalSize, WindowBuilder}; fn main() { - dioxus_desktop::launch(app); + dioxus_desktop::launch_cfg(app, make_config()); } fn app(cx: Scope) -> Element { @@ -10,25 +10,54 @@ fn app(cx: Scope) -> Element { cx.render(rsx! { div { - button { - onclick: move |_| { - let dom = VirtualDom::new(app); - window.new_window(dom, Default::default()); - }, - "Open overlay" + width: "100%", + height: "100%", + background_color: "red", + border: "1px solid black", + + div { + width: "100%", + height: "10px", + background_color: "black", + onmousedown: move |_| window.drag(), } + + "This is an overlay!" } }) } -fn popup(cx: Scope) -> Element { - cx.render(rsx! { - div { - width: "200px", - height: "200px", - background: "white", - border: "1px solid black", - "This is a popup!" - } - }) +fn make_config() -> dioxus_desktop::Config { + dioxus_desktop::Config::default() + .with_window(make_window()) + .with_custom_head( + r#" + +"# + .to_owned(), + ) +} + +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)) } diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 7ea8f234e..0fb340c25 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -96,7 +96,9 @@ impl DesktopContext { let window = self.webview.window(); // if the drag_window has any errors, we don't do anything - window.fullscreen().is_none().then(|| window.drag_window()); + if window.fullscreen().is_none() { + window.drag_window().unwrap(); + } } /// Toggle whether the window is maximized or not