feat: add DesktopContext

This commit is contained in:
mrxiaozhuox committed 2022-01-31 01:06:43 +08:00
1 parent 169028705d
commit 31a2f8f63a
2 files changed
+41 -9

No files matched your search

+27 -4
View File
@@ -4,25 +4,48 @@ use crate::UserWindowEvent;
type ProxyType = EventLoopProxy<UserWindowEvent>;
/// 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
///
/// ```rust
/// let desktop = cx.consume_context::<DesktopContext>().unwrap();
/// ```
#[derive(Clone)]
pub struct DesktopContext {
proxy: ProxyType,
}
impl DesktopContext {
pub fn new(proxy: ProxyType) -> Self {
Self { proxy }
}
/// 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_window(&self) {
let _ = self.proxy.send_event(UserWindowEvent::DragWindow);
}
pub fn minimized(&self, minimized: bool) {
let _ = self.proxy.send_event(UserWindowEvent::Minimized(minimized));
pub fn minimize(&self, minimized: bool) {
let _ = self.proxy.send_event(UserWindowEvent::Minimize(minimized));
}
pub fn maximized(&self, maximized: bool) {
let _ = self.proxy.send_event(UserWindowEvent::Maximized(maximized));
pub fn maximize(&self, maximized: bool) {
let _ = self.proxy.send_event(UserWindowEvent::Maximize(maximized));
}
pub fn close(&self) {
let _ = self.proxy.send_event(UserWindowEvent::CloseWindow);
}
}