overlay.rs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. use dioxus::prelude::*;
  2. use dioxus_desktop::{tao::dpi::PhysicalPosition, use_window, Config, LogicalSize, WindowBuilder};
  3. fn main() {
  4. dioxus_desktop::launch_cfg(app, make_config());
  5. }
  6. fn app(cx: Scope) -> Element {
  7. let window = use_window(cx);
  8. cx.render(rsx! {
  9. div {
  10. width: "100%",
  11. height: "100%",
  12. background_color: "red",
  13. border: "1px solid black",
  14. div {
  15. width: "100%",
  16. height: "10px",
  17. background_color: "black",
  18. onmousedown: move |_| window.drag(),
  19. }
  20. "This is an overlay!"
  21. }
  22. })
  23. }
  24. fn make_config() -> dioxus_desktop::Config {
  25. dioxus_desktop::Config::default()
  26. .with_window(make_window())
  27. .with_custom_head(
  28. r#"
  29. <style type="text/css">
  30. html, body {
  31. height: 100px;
  32. margin: 0;
  33. overscroll-behavior-y: none;
  34. overscroll-behavior-x: none;
  35. overflow: hidden;
  36. }
  37. #main, #bodywrap {
  38. height: 100%;
  39. margin: 0;
  40. overscroll-behavior-x: none;
  41. overscroll-behavior-y: none;
  42. }
  43. </style>
  44. "#
  45. .to_owned(),
  46. )
  47. }
  48. fn make_window() -> WindowBuilder {
  49. WindowBuilder::new()
  50. .with_transparent(true)
  51. .with_decorations(false)
  52. .with_resizable(false)
  53. .with_always_on_top(true)
  54. .with_position(PhysicalPosition::new(0, 0))
  55. .with_max_inner_size(LogicalSize::new(100000, 50))
  56. }