Skip to content

Commit

Permalink
Support maximize toggle and devtool
Browse files Browse the repository at this point in the history
  • Loading branch information
asaaki committed Feb 13, 2022
1 parent 2828f45 commit 934d599
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions packages/desktop/src/desktop_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::rc::Rc;
use dioxus_core::ScopeState;
use wry::application::event_loop::EventLoopProxy;

use crate::UserWindowEvent;
use crate::user_window_events::UserWindowEvent;
use UserWindowEvent::*;

type ProxyType = EventLoopProxy<UserWindowEvent>;

Expand Down Expand Up @@ -35,75 +36,77 @@ impl DesktopContext {
/// onmousedown: move |_| { desktop.drag_window(); }
/// ```
pub fn drag(&self) {
let _ = self.proxy.send_event(UserWindowEvent::DragWindow);
let _ = self.proxy.send_event(DragWindow);
}

/// set window minimize state
pub fn set_minimized(&self, minimized: bool) {
let _ = self.proxy.send_event(UserWindowEvent::Minimize(minimized));
let _ = self.proxy.send_event(Minimize(minimized));
}

/// set window maximize state
pub fn set_maximized(&self, maximized: bool) {
let _ = self.proxy.send_event(UserWindowEvent::Maximize(maximized));
let _ = self.proxy.send_event(Maximize(maximized));
}

/// toggle window maximize state
pub fn toggle_maximized(&self) {
let _ = self.proxy.send_event(MaximizeToggle);
}

/// set window visible or not
pub fn set_visible(&self, visible: bool) {
let _ = self.proxy.send_event(UserWindowEvent::Visible(visible));
let _ = self.proxy.send_event(Visible(visible));
}

/// close window
pub fn close(&self) {
let _ = self.proxy.send_event(UserWindowEvent::CloseWindow);
let _ = self.proxy.send_event(CloseWindow);
}

/// set window to focus
pub fn focus(&self) {
let _ = self.proxy.send_event(UserWindowEvent::FocusWindow);
let _ = self.proxy.send_event(FocusWindow);
}

/// change window to fullscreen
pub fn set_fullscreen(&self, fullscreen: bool) {
let _ = self
.proxy
.send_event(UserWindowEvent::Fullscreen(fullscreen));
let _ = self.proxy.send_event(Fullscreen(fullscreen));
}

/// set resizable state
pub fn set_resizable(&self, resizable: bool) {
let _ = self.proxy.send_event(UserWindowEvent::Resizable(resizable));
let _ = self.proxy.send_event(Resizable(resizable));
}

/// set the window always on top
pub fn set_always_on_top(&self, top: bool) {
let _ = self.proxy.send_event(UserWindowEvent::AlwaysOnTop(top));
let _ = self.proxy.send_event(AlwaysOnTop(top));
}

// set cursor visible or not
pub fn set_cursor_visible(&self, visible: bool) {
let _ = self
.proxy
.send_event(UserWindowEvent::CursorVisible(visible));
let _ = self.proxy.send_event(CursorVisible(visible));
}

// set cursor grab
pub fn set_cursor_grab(&self, grab: bool) {
let _ = self.proxy.send_event(UserWindowEvent::CursorGrab(grab));
let _ = self.proxy.send_event(CursorGrab(grab));
}

/// set window title
pub fn set_title(&self, title: &str) {
let _ = self
.proxy
.send_event(UserWindowEvent::SetTitle(String::from(title)));
let _ = self.proxy.send_event(SetTitle(String::from(title)));
}

/// change window to borderless
pub fn set_decorations(&self, decoration: bool) {
let _ = self
.proxy
.send_event(UserWindowEvent::SetDecorations(decoration));
let _ = self.proxy.send_event(SetDecorations(decoration));
}

/// opens DevTool window
pub fn devtool(&self) {
let _ = self.proxy.send_event(DevTool);
}
}

Expand Down

0 comments on commit 934d599

Please sign in to comment.