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

'resizable' and 'show_titlebar' options #587

Merged
merged 8 commits into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
26 changes: 26 additions & 0 deletions druid-shell/src/platform/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub struct WindowBuilder {
title: String,
menu: Option<Menu>,
size: Size,
resizable: bool,
show_titlebar: bool,
}

#[derive(Clone)]
Expand Down Expand Up @@ -114,6 +116,8 @@ impl WindowBuilder {
title: String::new(),
menu: None,
size: Size::new(500.0, 400.0),
resizable: true,
show_titlebar: true,
}
}

Expand All @@ -125,6 +129,14 @@ impl WindowBuilder {
self.size = size;
}

pub fn resizable(&mut self, resizable: bool) {
self.resizable = resizable;
}

pub fn show_titlebar(&mut self, show_titlebar: bool) {
self.show_titlebar = show_titlebar;
}

pub fn set_title(&mut self, title: impl Into<String>) {
self.title = title.into();
}
Expand All @@ -143,6 +155,8 @@ impl WindowBuilder {
let window = with_application(|app| ApplicationWindow::new(&app));

window.set_title(&self.title);
window.set_resizable(self.resizable);
window.set_decorated(self.show_titlebar);

let dpi_scale = window
.get_display()
Expand Down Expand Up @@ -415,6 +429,18 @@ impl WindowHandle {
}
}

pub fn set_resizable(&self, resizable: bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general we expect the various platform WindowHandle and other types to be used through the shared WindowHandle struct in druid-shell/src/window.rs, and so I would add these methods there, wrapping the method on each platform type; this will require you to add stubs of these methods to the other platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, I already added the stubs for other platforms, so it should be enough to add the two methods to the WindowHandle right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw you had the methods for builder, but I didn't see them for WindowHandle? I might have missed it. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep you're right, I missed the WindowHandle, adding it now

if let Some(state) = self.state.upgrade() {
state.window.set_resizable(resizable)
}
}

pub fn show_titlebar(&self, show_titlebar: bool) {
if let Some(state) = self.state.upgrade() {
state.window.set_decorated(show_titlebar)
}
}

/// Close the window.
pub fn close(&self) {
if let Some(state) = self.state.upgrade() {
Expand Down
14 changes: 14 additions & 0 deletions druid-shell/src/platform/mac/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ pub(crate) struct WindowBuilder {
title: String,
menu: Option<Menu>,
size: Size,
resizable: bool,
show_titlebar: bool,
}

#[derive(Clone)]
Expand Down Expand Up @@ -105,6 +107,8 @@ impl WindowBuilder {
title: String::new(),
menu: None,
size: Size::new(500.0, 400.0),
resizable: true,
show_titlebar: true,
}
}

Expand All @@ -116,6 +120,16 @@ impl WindowBuilder {
self.size = size;
}

pub fn resizable(&mut self, resizable: bool) {
// TODO: Use this in `self.build`
self.resizable = resizable;
}

pub fn show_titlebar(&mut self, show_titlebar: bool) {
// TODO: Use this in `self.build`
self.show_titlebar = show_titlebar;
}

pub fn set_title(&mut self, title: impl Into<String>) {
self.title = title.into();
}
Expand Down
14 changes: 14 additions & 0 deletions druid-shell/src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub struct WindowBuilder {
title: String,
menu: Option<Menu>,
present_strategy: PresentStrategy,
resizable: bool,
show_titlebar: bool,
size: Size,
}

Expand Down Expand Up @@ -701,6 +703,8 @@ impl WindowBuilder {
dwStyle: WS_OVERLAPPEDWINDOW,
title: String::new(),
menu: None,
resizable: true,
show_titlebar: true,
present_strategy: Default::default(),
size: Size::new(500.0, 400.0),
}
Expand All @@ -715,6 +719,16 @@ impl WindowBuilder {
self.size = size;
}

pub fn resizable(&mut self, resizable: bool) {
// TODO: Use this in `self.build`
self.resizable = resizable;
}

pub fn show_titlebar(&mut self, show_titlebar: bool) {
// TODO: Use this in `self.build`
self.show_titlebar = show_titlebar;
}

pub fn set_title<S: Into<String>>(&mut self, title: S) {
self.title = title.into();
}
Expand Down
10 changes: 10 additions & 0 deletions druid-shell/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ impl WindowBuilder {
self.0.set_size(size)
}

/// Set wheter the window should be resizable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Set wheter the window should be resizable
/// Set whether the window should be resizable

pub fn resizable(&mut self, resizable: bool) {
self.0.resizable(resizable)
}

/// Set wheter the window should have a titlebar and decorations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Set wheter the window should have a titlebar and decorations
/// Set whether the window should have a titlebar and decorations

pub fn show_titlebar(&mut self, show_titlebar: bool) {
self.0.show_titlebar(show_titlebar)
}

/// Set the window's initial title.
pub fn set_title(&mut self, title: impl Into<String>) {
self.0.set_title(title)
Expand Down
17 changes: 17 additions & 0 deletions druid/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub struct WindowDesc<T> {
pub(crate) title: LocalizedString<T>,
pub(crate) size: Option<Size>,
pub(crate) menu: Option<MenuDesc<T>>,
pub(crate) resizable: bool,
pub(crate) show_titlebar: bool,
/// The `WindowId` that will be assigned to this window.
///
/// This can be used to track a window from when it is launched and when
Expand Down Expand Up @@ -144,6 +146,8 @@ impl<T: Data> WindowDesc<T> {
title: LocalizedString::new("app-name"),
size: None,
menu: MenuDesc::platform_default(),
resizable: true,
show_titlebar: true,
id: WindowId::next(),
}
}
Expand Down Expand Up @@ -175,6 +179,16 @@ impl<T: Data> WindowDesc<T> {
self
}

pub fn resizable(mut self, resizable: bool) -> Self {
self.resizable = resizable;
self
}

pub fn show_titlebar(mut self, show_titlebar: bool) -> Self {
self.show_titlebar = show_titlebar;
self
}

/// Attempt to create a platform window from this `WindowDesc`.
pub(crate) fn build_native(
mut self,
Expand All @@ -190,6 +204,9 @@ impl<T: Data> WindowDesc<T> {

let mut builder = WindowBuilder::new();

builder.resizable(self.resizable);
builder.show_titlebar(self.show_titlebar);

builder.set_handler(Box::new(handler));
if let Some(size) = self.size {
builder.set_size(size);
Expand Down