feat: add window api

This commit is contained in:
mrxiaozhuox committed 2022-02-10 23:33:02 +08:00
1 parent 01435d6aff
commit 81ea7a1428
2 files changed
+37

No files matched your search

+14
View File
@@ -48,6 +48,10 @@ impl DesktopContext {
let _ = self.proxy.send_event(UserWindowEvent::Maximize(maximized));
}
pub fn visible(&self, visible: bool) {
let _ = self.proxy.send_event(UserWindowEvent::Visible(visible));
}
/// close window
pub fn close(&self) {
let _ = self.proxy.send_event(UserWindowEvent::CloseWindow);
@@ -63,6 +67,16 @@ impl DesktopContext {
let _ = self.proxy.send_event(UserWindowEvent::Resizable(resizable));
}
pub fn always_on_top(&self, top: bool) {
let _ = self.proxy.send_event(UserWindowEvent::AlwaysOnTop(top));
}
pub fn cursor_visible(&self, visible: bool) {
let _ = self
.proxy
.send_event(UserWindowEvent::CursorVisible(visible));
}
/// set window title
pub fn set_title(&self, title: &str) {
let _ = self
+23
View File
@@ -299,6 +299,12 @@ pub fn launch_with_props<P: 'static + Send>(
// close window
*control_flow = ControlFlow::Exit;
}
UserWindowEvent::Visible(state) => {
for webview in desktop.webviews.values() {
let window = webview.window();
window.set_visible(state);
}
}
UserWindowEvent::Minimize(state) => {
// this loop just run once, because dioxus-desktop is unsupport multi-window.
for webview in desktop.webviews.values() {
@@ -333,6 +339,19 @@ pub fn launch_with_props<P: 'static + Send>(
window.set_resizable(state);
}
}
UserWindowEvent::AlwaysOnTop(state) => {
for webview in desktop.webviews.values() {
let window = webview.window();
window.set_always_on_top(state);
}
}
UserWindowEvent::CursorVisible(state) => {
for webview in desktop.webviews.values() {
let window = webview.window();
window.set_cursor_visible(state);
}
}
UserWindowEvent::SetTitle(content) => {
for webview in desktop.webviews.values() {
@@ -363,11 +382,15 @@ pub enum UserWindowEvent {
DragWindow,
CloseWindow,
FocusWindow,
Visible(bool),
Minimize(bool),
Maximize(bool),
Resizable(bool),
AlwaysOnTop(bool),
Fullscreen(Box<Option<Fullscreen>>),
CursorVisible(bool),
SetTitle(String),
SetDecorations(bool),
}