1
0

window_event.rs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. use dioxus::prelude::*;
  2. use dioxus_desktop::{Config, WindowBuilder};
  3. fn main() {
  4. let cfg = Config::new().with_window(
  5. WindowBuilder::new()
  6. .with_title("Borderless Window")
  7. .with_decorations(false),
  8. );
  9. dioxus_desktop::launch_cfg(app, cfg);
  10. }
  11. fn app(cx: Scope) -> Element {
  12. let window = dioxus_desktop::use_window(cx);
  13. // if you want to make window fullscreen, you need close the resizable.
  14. // window.set_fullscreen(true);
  15. // window.set_resizable(false);
  16. let fullscreen = use_state(cx, || false);
  17. let always_on_top = use_state(cx, || false);
  18. let decorations = use_state(cx, || false);
  19. cx.render(rsx!(
  20. link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" }
  21. header {
  22. class: "text-gray-400 bg-gray-900 body-font",
  23. onmousedown: move |_| window.drag(),
  24. div {
  25. class: "container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center",
  26. a { class: "flex title-font font-medium items-center text-white mb-4 md:mb-0",
  27. span { class: "ml-3 text-xl", "Dioxus"}
  28. }
  29. nav { class: "md:ml-auto flex flex-wrap items-center text-base justify-center" }
  30. button {
  31. class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0",
  32. onmousedown: |evt| evt.stop_propagation(),
  33. onclick: move |_| window.set_minimized(true),
  34. "Minimize"
  35. }
  36. button {
  37. class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0",
  38. onmousedown: |evt| evt.stop_propagation(),
  39. onclick: move |_| {
  40. window.set_fullscreen(!**fullscreen);
  41. window.set_resizable(**fullscreen);
  42. fullscreen.modify(|f| !*f);
  43. },
  44. "Fullscreen"
  45. }
  46. button {
  47. class: "inline-flex items-center bg-gray-800 border-0 py-1 px-3 focus:outline-none hover:bg-gray-700 rounded text-base mt-4 md:mt-0",
  48. onmousedown: |evt| evt.stop_propagation(),
  49. onclick: move |_| window.close(),
  50. "Close"
  51. }
  52. }
  53. }
  54. br {}
  55. div {
  56. class: "container mx-auto",
  57. div {
  58. class: "grid grid-cols-5",
  59. div {
  60. button {
  61. class: "inline-flex items-center text-white bg-green-500 border-0 py-1 px-3 hover:bg-green-700 rounded",
  62. onmousedown: |evt| evt.stop_propagation(),
  63. onclick: move |_| {
  64. window.set_always_on_top(!always_on_top);
  65. always_on_top.set(!always_on_top);
  66. },
  67. "Always On Top"
  68. }
  69. }
  70. div {
  71. button {
  72. class: "inline-flex items-center text-white bg-blue-500 border-0 py-1 px-3 hover:bg-green-700 rounded",
  73. onmousedown: |evt| evt.stop_propagation(),
  74. onclick: move |_| {
  75. window.set_decorations(!decorations);
  76. decorations.set(!decorations);
  77. },
  78. "Set Decorations"
  79. }
  80. }
  81. div {
  82. button {
  83. class: "inline-flex items-center text-white bg-blue-500 border-0 py-1 px-3 hover:bg-green-700 rounded",
  84. onmousedown: |evt| evt.stop_propagation(),
  85. onclick: move |_| window.set_title("Dioxus Application"),
  86. "Change Title"
  87. }
  88. }
  89. }
  90. }
  91. ))
  92. }