From 862278ddac74788875989b2a67a76d2e09b17eba Mon Sep 17 00:00:00 2001 From: Muhammad Ragib Hasin Date: Sat, 8 Jan 2022 23:06:12 +0600 Subject: [PATCH] Add methods WindowHandle::is_resizable etc --- druid-shell/src/backend/gtk/window.rs | 18 ++++++++++++++++++ druid-shell/src/backend/mac/window.rs | 15 +++++++++++++++ druid-shell/src/backend/wayland/window.rs | 15 +++++++++++++++ druid-shell/src/backend/web/window.rs | 15 +++++++++++++++ druid-shell/src/backend/windows/window.rs | 21 +++++++++++++++++++++ druid-shell/src/backend/x11/window.rs | 15 +++++++++++++++ druid-shell/src/window.rs | 15 +++++++++++++++ 7 files changed, 114 insertions(+) diff --git a/druid-shell/src/backend/gtk/window.rs b/druid-shell/src/backend/gtk/window.rs index f1421b740e..5068210f2f 100644 --- a/druid-shell/src/backend/gtk/window.rs +++ b/druid-shell/src/backend/gtk/window.rs @@ -974,12 +974,30 @@ impl WindowHandle { } } + pub fn is_resizable(&self) -> bool { + self.state + .upgrade() + .map(true, |state| state.window.is_resizable()) + } + + pub fn is_transparent(&self) -> bool { + self.state + .upgrade() + .map_or(false, |state| state.is_transparent) + } + pub fn show_titlebar(&self, show_titlebar: bool) { if let Some(state) = self.state.upgrade() { state.window.set_decorated(show_titlebar) } } + pub fn has_titlebar(&self) -> bool { + self.state + .upgrade() + .map(true, |state| state.window.is_decorated()) + } + pub fn set_position(&self, mut position: Point) { if let Some(state) = self.state.upgrade() { if let Some(parent_state) = &state.parent { diff --git a/druid-shell/src/backend/mac/window.rs b/druid-shell/src/backend/mac/window.rs index 836f49543f..d31ed9fded 100644 --- a/druid-shell/src/backend/mac/window.rs +++ b/druid-shell/src/backend/mac/window.rs @@ -1223,6 +1223,11 @@ impl WindowHandle { // TODO: Implement this pub fn show_titlebar(&self, _show_titlebar: bool) {} + pub fn has_titlebar(&self) -> bool { + tracing::warn!("WindowHandle::has_titlebar is currently unimplemented for Mac."); + true + } + // Need to translate mac y coords, as they start from bottom left pub fn set_position(&self, mut position: Point) { // TODO: Maybe @cmyr can get this into a state where modal windows follow the parent? @@ -1371,6 +1376,16 @@ impl WindowHandle { } } + pub fn is_resizable(&self) -> bool { + tracing::warn!("WindowHandle::is_resizable is currently unimplemented for Mac."); + true + } + + pub fn is_transparent(&self) -> bool { + tracing::warn!("WindowHandle::is_transparent is currently unimplemented for Mac."); + false + } + pub fn set_menu(&self, menu: Menu) { unsafe { NSApp().setMainMenu_(menu.menu); diff --git a/druid-shell/src/backend/wayland/window.rs b/druid-shell/src/backend/wayland/window.rs index 26946a2b65..614b739fc0 100644 --- a/druid-shell/src/backend/wayland/window.rs +++ b/druid-shell/src/backend/wayland/window.rs @@ -106,10 +106,25 @@ impl WindowHandle { tracing::warn!("resizable is unimplemented on wayland"); } + pub fn is_resizable(&self) -> bool { + tracing::warn!("is_resizable is unimplemented on wayland"); + true + } + + pub fn is_transparent(&self) -> bool { + tracing::warn!("is_transparent is unimplemented on wayland"); + false + } + pub fn show_titlebar(&self, _show_titlebar: bool) { tracing::warn!("show_titlebar is unimplemented on wayland"); } + pub fn has_titlebar(&self) -> bool { + tracing::warn!("has_titlebar is unimplemented on wayland"); + true + } + pub fn set_position(&self, _position: Point) { tracing::warn!("set_position is unimplemented on wayland"); } diff --git a/druid-shell/src/backend/web/window.rs b/druid-shell/src/backend/web/window.rs index 92a0326f52..b1d54baab9 100644 --- a/druid-shell/src/backend/web/window.rs +++ b/druid-shell/src/backend/web/window.rs @@ -377,14 +377,29 @@ impl WindowBuilder { // Ignored } + pub fn is_resizable(&self) -> bool { + warn!("is_resizable is unimplemented on web"); + true + } + pub fn show_titlebar(&mut self, _show_titlebar: bool) { // Ignored } + pub fn has_titlebar(&self) -> bool { + warn!("has_titlebar is unimplemented on web"); + true + } + pub fn set_transparent(&mut self, _transparent: bool) { // Ignored } + pub fn is_transparent(&self) -> bool { + warn!("is_transparent is unimplemented on web"); + true + } + pub fn set_position(&mut self, _position: Point) { // Ignored } diff --git a/druid-shell/src/backend/windows/window.rs b/druid-shell/src/backend/windows/window.rs index ba982146b4..3820aa386a 100644 --- a/druid-shell/src/backend/windows/window.rs +++ b/druid-shell/src/backend/windows/window.rs @@ -1880,6 +1880,13 @@ impl WindowHandle { self.defer(DeferredOp::ShowTitlebar(show_titlebar)); } + pub fn has_titlebar(&self) -> bool { + self.state + .upgrade() + .map(|state| state.has_titlebar.get()) + .unwrap_or_default() + } + pub fn set_position(&self, position: Point) { self.defer(DeferredOp::SetWindowState(window::WindowState::Restored)); if let Some(w) = self.state.upgrade() { @@ -1986,6 +1993,20 @@ impl WindowHandle { self.defer(DeferredOp::SetResizable(resizable)); } + pub fn is_resizable(&self) -> bool { + self.state + .upgrade() + .map(|state| state.is_resizable.get()) + .unwrap_or_default() + } + + pub fn is_transparent(&self) -> bool { + self.state + .upgrade() + .map(|state| state.is_transparent.get()) + .unwrap_or_default() + } + // Sets the window state. pub fn set_window_state(&self, state: window::WindowState) { self.defer(DeferredOp::SetWindowState(state)); diff --git a/druid-shell/src/backend/x11/window.rs b/druid-shell/src/backend/x11/window.rs index 0201c6917c..cb62f44a42 100644 --- a/druid-shell/src/backend/x11/window.rs +++ b/druid-shell/src/backend/x11/window.rs @@ -1610,6 +1610,16 @@ impl WindowHandle { } } + pub fn is_resizable(&self) -> bool { + warn!("is_resizable is unimplemented on x11"); + true + } + + pub fn is_transparent(&self) -> bool { + warn!("is_transparent is unimplemented on x11"); + false + } + pub fn show_titlebar(&self, show_titlebar: bool) { if let Some(w) = self.window.upgrade() { w.show_titlebar(show_titlebar); @@ -1618,6 +1628,11 @@ impl WindowHandle { } } + pub fn has_titlebar(&self) -> bool { + warn!("has_titlebar is unimplemented on x11"); + true + } + pub fn set_position(&self, position: Point) { if let Some(w) = self.window.upgrade() { w.set_position(position); diff --git a/druid-shell/src/window.rs b/druid-shell/src/window.rs index d3c1080e24..891477cb2c 100644 --- a/druid-shell/src/window.rs +++ b/druid-shell/src/window.rs @@ -191,6 +191,16 @@ impl WindowHandle { self.0.resizable(resizable) } + /// Get whether the window is resizable + pub fn is_resizable(&self) -> bool { + self.0.is_resizable() + } + + /// Get whether the window is transparent + pub fn is_transparent(&self) -> bool { + self.0.is_transparent() + } + /// Sets the state of the window. pub fn set_window_state(&mut self, state: WindowState) { self.0.set_window_state(state); @@ -216,6 +226,11 @@ impl WindowHandle { self.0.show_titlebar(show_titlebar) } + /// Get whether the window has titlebar. + pub fn has_titlebar(&self) -> bool { + self.0.has_titlebar() + } + /// Sets the position of the window. /// /// The position is given in [display points], measured relative to the parent window if there