Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods WindowHandle::is_resizable etc #2115

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions druid-shell/src/backend/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,12 +972,30 @@ impl WindowHandle {
}
}

pub fn is_resizable(&self) -> bool {
self.state
.upgrade()
.map_or(true, |state| state.window.is_resizable())
}

pub fn is_transparent(&self) -> bool {
self.state
.upgrade()
.map_or(false, |state| state.is_transparent.get())
}

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_or(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 {
Expand Down
15 changes: 15 additions & 0 deletions druid-shell/src/backend/mac/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,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?
Expand Down Expand Up @@ -1380,6 +1385,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);
Expand Down
14 changes: 14 additions & 0 deletions druid-shell/src/backend/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,24 @@ 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 {
true
}

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");
}
Expand Down
18 changes: 16 additions & 2 deletions druid-shell/src/backend/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,27 @@ impl WindowHandle {
}

pub fn resizable(&self, _resizable: bool) {
warn!("resizable unimplemented for web");
warn!("WindowHandle::resizable unimplemented for web");
}

pub fn is_resizable(&self) -> bool {
warn!("WindowHandle::is_resizable is unimplemented on web");
true
}

pub fn show_titlebar(&self, _show_titlebar: bool) {
warn!("show_titlebar unimplemented for web");
warn!("WindowHandle::show_titlebar unimplemented for web");
}

pub fn has_titlebar(&self) -> bool {
warn!("WindowHandle::has_titlebar is unimplemented on web");
true
}

pub fn is_transparent(&self) -> bool {
warn!("WindowHandle::is_transparent is unimplemented on web");
true
}
pub fn set_position(&self, _position: Point) {
warn!("WindowHandle::set_position unimplemented for web");
}
Expand Down
21 changes: 21 additions & 0 deletions druid-shell/src/backend/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,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() {
Expand Down Expand Up @@ -2032,6 +2039,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));
Expand Down
15 changes: 15 additions & 0 deletions druid-shell/src/backend/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,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);
Expand All @@ -1633,6 +1643,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);
Expand Down
15 changes: 15 additions & 0 deletions druid-shell/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down