|
@@ -1,100 +1,67 @@
|
|
-use std::cell::RefCell;
|
|
|
|
|
|
+use std::rc::Rc;
|
|
|
|
|
|
-use dioxus::prelude::Scope;
|
|
|
|
-use dioxus_core as dioxus;
|
|
|
|
-use dioxus_core::{Context, Element, LazyNodes, NodeFactory, Properties};
|
|
|
|
-use dioxus_core_macro::Props;
|
|
|
|
|
|
+use dioxus_core::ScopeState;
|
|
|
|
+use wry::application::event_loop::EventLoopProxy;
|
|
|
|
|
|
-/*
|
|
|
|
-This module provides a set of Dioxus components to easily manage windows, tabs, etc.
|
|
|
|
|
|
+use crate::UserWindowEvent;
|
|
|
|
|
|
-Windows can be created anywhere in the tree, making them very flexible for things like modals, etc.
|
|
|
|
|
|
+type ProxyType = EventLoopProxy<UserWindowEvent>;
|
|
|
|
|
|
-*/
|
|
|
|
-pub struct DesktopContext {}
|
|
|
|
-
|
|
|
|
-impl DesktopContext {
|
|
|
|
- fn add_window(&mut self) {
|
|
|
|
- //
|
|
|
|
- }
|
|
|
|
- fn close_window(&mut self) {
|
|
|
|
- //
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-enum WindowHandlers {
|
|
|
|
- Resized(Box<dyn Fn()>),
|
|
|
|
- Moved(Box<dyn Fn()>),
|
|
|
|
- CloseRequested(Box<dyn Fn()>),
|
|
|
|
- Destroyed(Box<dyn Fn()>),
|
|
|
|
- DroppedFile(Box<dyn Fn()>),
|
|
|
|
- HoveredFile(Box<dyn Fn()>),
|
|
|
|
- HoverFileCancelled(Box<dyn Fn()>),
|
|
|
|
- ReceivedTimeText(Box<dyn Fn()>),
|
|
|
|
- Focused(Box<dyn Fn()>),
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#[derive(Props)]
|
|
|
|
-pub struct WebviewWindowProps<'a> {
|
|
|
|
- onclose: &'a dyn FnMut(()),
|
|
|
|
-
|
|
|
|
- onopen: &'a dyn FnMut(()),
|
|
|
|
-
|
|
|
|
- /// focuse me
|
|
|
|
- onfocused: &'a dyn FnMut(()),
|
|
|
|
-
|
|
|
|
- children: Element,
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/// A handle to a
|
|
|
|
-///
|
|
|
|
-///
|
|
|
|
-///
|
|
|
|
|
|
+/// Desktop-Window handle api context
|
|
///
|
|
///
|
|
|
|
+/// you can use this context control some window event
|
|
///
|
|
///
|
|
|
|
+/// you can use `cx.consume_context::<DesktopContext>` to get this context
|
|
///
|
|
///
|
|
-///
|
|
|
|
-///
|
|
|
|
-///
|
|
|
|
-pub fn WebviewWindow(cx: Scope<WebviewWindowProps>) -> Element {
|
|
|
|
- let dtcx = cx.consume_state::<RefCell<DesktopContext>>()?;
|
|
|
|
-
|
|
|
|
- cx.use_hook(|_| {});
|
|
|
|
-
|
|
|
|
- // render the children directly
|
|
|
|
- todo!()
|
|
|
|
- // cx.render(LazyNodes::new(move |f: NodeFactory| {
|
|
|
|
- // f.fragment_from_iter(cx.children())
|
|
|
|
- // }))
|
|
|
|
|
|
+/// ```rust
|
|
|
|
+/// let desktop = cx.consume_context::<DesktopContext>().unwrap();
|
|
|
|
+/// ```
|
|
|
|
+#[derive(Clone)]
|
|
|
|
+pub struct DesktopContext {
|
|
|
|
+ proxy: ProxyType,
|
|
}
|
|
}
|
|
|
|
|
|
-pub struct WindowHandle {}
|
|
|
|
|
|
+impl DesktopContext {
|
|
|
|
+ pub(crate) fn new(proxy: ProxyType) -> Self {
|
|
|
|
+ Self { proxy }
|
|
|
|
+ }
|
|
|
|
|
|
-/// Get a handle to the current window from inside a component
|
|
|
|
-pub fn use_current_window(cx: Scope) -> Option<WindowHandle> {
|
|
|
|
- todo!()
|
|
|
|
-}
|
|
|
|
|
|
+ /// trigger the drag-window event
|
|
|
|
+ ///
|
|
|
|
+ /// Moves the window with the left mouse button until the button is released.
|
|
|
|
+ ///
|
|
|
|
+ /// you need use it in `onmousedown` event:
|
|
|
|
+ /// ```rust
|
|
|
|
+ /// onmousedown: move |_| { desktop.drag_window(); }
|
|
|
|
+ /// ```
|
|
|
|
+ pub fn drag(&self) {
|
|
|
|
+ let _ = self.proxy.send_event(UserWindowEvent::DragWindow);
|
|
|
|
+ }
|
|
|
|
|
|
-#[test]
|
|
|
|
-fn syntax_works() {
|
|
|
|
- use dioxus_core as dioxus;
|
|
|
|
- use dioxus_core::prelude::*;
|
|
|
|
- use dioxus_core_macro::*;
|
|
|
|
- use dioxus_hooks::*;
|
|
|
|
- use dioxus_html as dioxus_elements;
|
|
|
|
|
|
+ /// set window minimize state
|
|
|
|
+ pub fn minimize(&self, minimized: bool) {
|
|
|
|
+ let _ = self.proxy.send_event(UserWindowEvent::Minimize(minimized));
|
|
|
|
+ }
|
|
|
|
|
|
- static App: Component = |cx| {
|
|
|
|
- cx.render(rsx! {
|
|
|
|
- // left window
|
|
|
|
- WebviewWindow {
|
|
|
|
- onclose: move |evt| {}
|
|
|
|
- onopen: move |evt| {}
|
|
|
|
- onfocused: move |evt| {}
|
|
|
|
|
|
+ /// set window maximize state
|
|
|
|
+ pub fn maximize(&self, maximized: bool) {
|
|
|
|
+ let _ = self.proxy.send_event(UserWindowEvent::Maximize(maximized));
|
|
|
|
+ }
|
|
|
|
|
|
- div {
|
|
|
|
|
|
+ /// close window
|
|
|
|
+ pub fn close(&self) {
|
|
|
|
+ let _ = self.proxy.send_event(UserWindowEvent::CloseWindow);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// set window to focus
|
|
|
|
+ pub fn focus(&self) {
|
|
|
|
+ let _ = self.proxy.send_event(UserWindowEvent::FocusWindow);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- };
|
|
|
|
|
|
+/// use this function can get the `DesktopContext` context.
|
|
|
|
+pub fn use_window(cx: &ScopeState) -> &Rc<DesktopContext> {
|
|
|
|
+ cx.use_hook(|_| cx.consume_context::<DesktopContext>())
|
|
|
|
+ .as_ref()
|
|
|
|
+ .unwrap()
|
|
}
|
|
}
|