Skip to content

Commit

Permalink
Add methods WindowHandle::is_resizable etc
Browse files Browse the repository at this point in the history
  • Loading branch information
RagibHasin committed Jan 8, 2022
1 parent b11f8ed commit 862278d
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
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 @@ -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 {
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 @@ -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?
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 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,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");
}
Expand Down
15 changes: 15 additions & 0 deletions druid-shell/src/backend/web/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
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 @@ -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() {
Expand Down Expand Up @@ -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));
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 @@ -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);
Expand All @@ -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);
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

0 comments on commit 862278d

Please sign in to comment.