From 1bafd7c01a8524c67b9fff7285766bdb1d396c80 Mon Sep 17 00:00:00 2001 From: Federico Dolce Date: Sat, 29 Feb 2020 19:46:06 +0100 Subject: [PATCH 1/8] Added resizable and decorated options to window --- druid-shell/src/platform/gtk/window.rs | 26 ++++++++++++++++++++++ druid-shell/src/platform/mac/window.rs | 12 ++++++++++ druid-shell/src/platform/windows/window.rs | 14 ++++++++++++ druid-shell/src/window.rs | 10 +++++++++ druid/src/app.rs | 17 ++++++++++++++ 5 files changed, 79 insertions(+) diff --git a/druid-shell/src/platform/gtk/window.rs b/druid-shell/src/platform/gtk/window.rs index e92bf78f79..351a56539c 100644 --- a/druid-shell/src/platform/gtk/window.rs +++ b/druid-shell/src/platform/gtk/window.rs @@ -86,6 +86,8 @@ pub struct WindowBuilder { title: String, menu: Option, size: Size, + resizable: bool, + decorated: bool, } #[derive(Clone)] @@ -114,6 +116,8 @@ impl WindowBuilder { title: String::new(), menu: None, size: Size::new(500.0, 400.0), + resizable: true, + decorated: true, } } @@ -125,6 +129,14 @@ impl WindowBuilder { self.size = size; } + pub fn set_resizable(&mut self, resizable: bool) { + self.resizable = resizable; + } + + pub fn set_decorated(&mut self, decorated: bool) { + self.decorated = decorated; + } + pub fn set_title(&mut self, title: impl Into) { self.title = title.into(); } @@ -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.decorated); let dpi_scale = window .get_display() @@ -415,6 +429,18 @@ impl WindowHandle { } } + pub fn set_resizable(&self, resizable: bool) { + if let Some(state) = self.state.upgrade() { + state.window.set_resizable(resizable) + } + } + + pub fn set_decorated(&self, decorated: bool) { + if let Some(state) = self.state.upgrade() { + state.window.set_decorated(decorated) + } + } + /// Close the window. pub fn close(&self) { if let Some(state) = self.state.upgrade() { diff --git a/druid-shell/src/platform/mac/window.rs b/druid-shell/src/platform/mac/window.rs index 32d93ace83..4bb2425ce9 100644 --- a/druid-shell/src/platform/mac/window.rs +++ b/druid-shell/src/platform/mac/window.rs @@ -76,6 +76,8 @@ pub(crate) struct WindowBuilder { title: String, menu: Option, size: Size, + resizable: bool, + decorated: bool, } #[derive(Clone)] @@ -116,6 +118,16 @@ impl WindowBuilder { self.size = size; } + pub fn set_resizable(&mut self, resizable: bool) { + // TODO: Use this in `self.build` + self.resizable = resizable; + } + + pub fn set_decorated(&mut self, decorated: bool) { + // TODO: Use this in `self.build` + self.decorated = decorated; + } + pub fn set_title(&mut self, title: impl Into) { self.title = title.into(); } diff --git a/druid-shell/src/platform/windows/window.rs b/druid-shell/src/platform/windows/window.rs index 8945853dd4..40746338ec 100644 --- a/druid-shell/src/platform/windows/window.rs +++ b/druid-shell/src/platform/windows/window.rs @@ -72,6 +72,8 @@ pub struct WindowBuilder { title: String, menu: Option, present_strategy: PresentStrategy, + resizable: bool, + decorated: bool, size: Size, } @@ -701,6 +703,8 @@ impl WindowBuilder { dwStyle: WS_OVERLAPPEDWINDOW, title: String::new(), menu: None, + resizable: true, + decorated: true, present_strategy: Default::default(), size: Size::new(500.0, 400.0), } @@ -715,6 +719,16 @@ impl WindowBuilder { self.size = size; } + pub fn set_resizable(&mut self, resizable: bool) { + // TODO: Use this in `self.build` + self.resizable = resizable; + } + + pub fn set_decorated(&mut self, decorated: bool) { + // TODO: Use this in `self.build` + self.decorated = decorated; + } + pub fn set_title>(&mut self, title: S) { self.title = title.into(); } diff --git a/druid-shell/src/window.rs b/druid-shell/src/window.rs index 251ce23c69..cfc1efe562 100644 --- a/druid-shell/src/window.rs +++ b/druid-shell/src/window.rs @@ -213,6 +213,16 @@ impl WindowBuilder { self.0.set_size(size) } + /// Set wheter the window should be resizable + pub fn set_resizable(&mut self, resizable: bool) { + self.0.set_resizable(resizable) + } + + /// Set wheter the window should be decorated + pub fn set_decorated(&mut self, decorated: bool) { + self.0.set_decorated(decorated) + } + /// Set the window's initial title. pub fn set_title(&mut self, title: impl Into) { self.0.set_title(title) diff --git a/druid/src/app.rs b/druid/src/app.rs index 45039a9b7a..f9d95039d3 100644 --- a/druid/src/app.rs +++ b/druid/src/app.rs @@ -42,6 +42,8 @@ pub struct WindowDesc { pub(crate) title: LocalizedString, pub(crate) size: Option, pub(crate) menu: Option>, + pub(crate) resizable: bool, + pub(crate) decorated: 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 @@ -144,6 +146,8 @@ impl WindowDesc { title: LocalizedString::new("app-name"), size: None, menu: MenuDesc::platform_default(), + resizable: true, + decorated: true, id: WindowId::next(), } } @@ -175,6 +179,16 @@ impl WindowDesc { self } + pub fn set_resizable(mut self, resizable: bool) -> Self { + self.resizable = resizable; + self + } + + pub fn set_decorated(mut self, decorated: bool) -> Self { + self.decorated = decorated; + self + } + /// Attempt to create a platform window from this `WindowDesc`. pub(crate) fn build_native( mut self, @@ -190,6 +204,9 @@ impl WindowDesc { let mut builder = WindowBuilder::new(); + builder.set_resizable(self.resizable); + builder.set_decorated(self.decorated); + builder.set_handler(Box::new(handler)); if let Some(size) = self.size { builder.set_size(size); From 69ab25ad9a6ccbc185301cb5858901a31bca30b7 Mon Sep 17 00:00:00 2001 From: Federico Dolce Date: Sun, 1 Mar 2020 17:26:12 +0100 Subject: [PATCH 2/8] Rename set_resizable to resizable and set_decorated to show_titlebar --- druid-shell/src/platform/gtk/window.rs | 16 ++++++++-------- druid-shell/src/platform/mac/window.rs | 6 +++--- druid-shell/src/platform/windows/window.rs | 6 +++--- druid-shell/src/window.rs | 10 +++++----- druid/src/app.rs | 14 +++++++------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/druid-shell/src/platform/gtk/window.rs b/druid-shell/src/platform/gtk/window.rs index 351a56539c..e2bf300fc5 100644 --- a/druid-shell/src/platform/gtk/window.rs +++ b/druid-shell/src/platform/gtk/window.rs @@ -87,7 +87,7 @@ pub struct WindowBuilder { menu: Option, size: Size, resizable: bool, - decorated: bool, + show_titlebar: bool, } #[derive(Clone)] @@ -117,7 +117,7 @@ impl WindowBuilder { menu: None, size: Size::new(500.0, 400.0), resizable: true, - decorated: true, + show_titlebar: true, } } @@ -129,12 +129,12 @@ impl WindowBuilder { self.size = size; } - pub fn set_resizable(&mut self, resizable: bool) { + pub fn resizable(&mut self, resizable: bool) { self.resizable = resizable; } - pub fn set_decorated(&mut self, decorated: bool) { - self.decorated = decorated; + pub fn show_titlebar(&mut self, show_titlebar: bool) { + self.show_titlebar = show_titlebar; } pub fn set_title(&mut self, title: impl Into) { @@ -156,7 +156,7 @@ impl WindowBuilder { window.set_title(&self.title); window.set_resizable(self.resizable); - window.set_decorated(self.decorated); + window.set_decorated(self.show_titlebar); let dpi_scale = window .get_display() @@ -435,9 +435,9 @@ impl WindowHandle { } } - pub fn set_decorated(&self, decorated: bool) { + pub fn show_titlebar(&self, show_titlebar: bool) { if let Some(state) = self.state.upgrade() { - state.window.set_decorated(decorated) + state.window.set_decorated(show_titlebar) } } diff --git a/druid-shell/src/platform/mac/window.rs b/druid-shell/src/platform/mac/window.rs index 4bb2425ce9..2f2cba7616 100644 --- a/druid-shell/src/platform/mac/window.rs +++ b/druid-shell/src/platform/mac/window.rs @@ -118,14 +118,14 @@ impl WindowBuilder { self.size = size; } - pub fn set_resizable(&mut self, resizable: bool) { + pub fn resizable(&mut self, resizable: bool) { // TODO: Use this in `self.build` self.resizable = resizable; } - pub fn set_decorated(&mut self, decorated: bool) { + pub fn show_titlebar(&mut self, show_titlebar: bool) { // TODO: Use this in `self.build` - self.decorated = decorated; + self.show_titlebar = show_titlebar; } pub fn set_title(&mut self, title: impl Into) { diff --git a/druid-shell/src/platform/windows/window.rs b/druid-shell/src/platform/windows/window.rs index 40746338ec..5405f696e2 100644 --- a/druid-shell/src/platform/windows/window.rs +++ b/druid-shell/src/platform/windows/window.rs @@ -719,14 +719,14 @@ impl WindowBuilder { self.size = size; } - pub fn set_resizable(&mut self, resizable: bool) { + pub fn resizable(&mut self, resizable: bool) { // TODO: Use this in `self.build` self.resizable = resizable; } - pub fn set_decorated(&mut self, decorated: bool) { + pub fn show_titlebar(&mut self, show_titlebar: bool) { // TODO: Use this in `self.build` - self.decorated = decorated; + self.show_titlebar = show_titlebar; } pub fn set_title>(&mut self, title: S) { diff --git a/druid-shell/src/window.rs b/druid-shell/src/window.rs index cfc1efe562..50d88dd641 100644 --- a/druid-shell/src/window.rs +++ b/druid-shell/src/window.rs @@ -214,13 +214,13 @@ impl WindowBuilder { } /// Set wheter the window should be resizable - pub fn set_resizable(&mut self, resizable: bool) { - self.0.set_resizable(resizable) + pub fn resizable(&mut self, resizable: bool) { + self.0.resizable(resizable) } - /// Set wheter the window should be decorated - pub fn set_decorated(&mut self, decorated: bool) { - self.0.set_decorated(decorated) + /// Set wheter 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. diff --git a/druid/src/app.rs b/druid/src/app.rs index f9d95039d3..ea7a422bea 100644 --- a/druid/src/app.rs +++ b/druid/src/app.rs @@ -43,7 +43,7 @@ pub struct WindowDesc { pub(crate) size: Option, pub(crate) menu: Option>, pub(crate) resizable: bool, - pub(crate) decorated: 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 @@ -147,7 +147,7 @@ impl WindowDesc { size: None, menu: MenuDesc::platform_default(), resizable: true, - decorated: true, + show_titlebar: true, id: WindowId::next(), } } @@ -179,13 +179,13 @@ impl WindowDesc { self } - pub fn set_resizable(mut self, resizable: bool) -> Self { + pub fn resizable(mut self, resizable: bool) -> Self { self.resizable = resizable; self } - pub fn set_decorated(mut self, decorated: bool) -> Self { - self.decorated = decorated; + pub fn show_titlebar(mut self, show_titlebar: bool) -> Self { + self.show_titlebar = show_titlebar; self } @@ -204,8 +204,8 @@ impl WindowDesc { let mut builder = WindowBuilder::new(); - builder.set_resizable(self.resizable); - builder.set_decorated(self.decorated); + builder.resizable(self.resizable); + builder.show_titlebar(self.show_titlebar); builder.set_handler(Box::new(handler)); if let Some(size) = self.size { From ec27613e4fc438c39f78584d5bd51bbca1186dcb Mon Sep 17 00:00:00 2001 From: Federico Dolce Date: Sun, 1 Mar 2020 17:41:38 +0100 Subject: [PATCH 3/8] Fixed mac windowbuilder --- druid-shell/src/platform/mac/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/druid-shell/src/platform/mac/window.rs b/druid-shell/src/platform/mac/window.rs index 2f2cba7616..7baddcd8de 100644 --- a/druid-shell/src/platform/mac/window.rs +++ b/druid-shell/src/platform/mac/window.rs @@ -77,7 +77,7 @@ pub(crate) struct WindowBuilder { menu: Option, size: Size, resizable: bool, - decorated: bool, + show_titlebar: bool, } #[derive(Clone)] From bee134e731895ba64b1b8e0798d606acc23bf7e0 Mon Sep 17 00:00:00 2001 From: Federico Dolce Date: Sun, 1 Mar 2020 17:48:13 +0100 Subject: [PATCH 4/8] Fix mac again, and windows too --- druid-shell/src/platform/mac/window.rs | 2 ++ druid-shell/src/platform/windows/window.rs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/druid-shell/src/platform/mac/window.rs b/druid-shell/src/platform/mac/window.rs index 7baddcd8de..209cd946dd 100644 --- a/druid-shell/src/platform/mac/window.rs +++ b/druid-shell/src/platform/mac/window.rs @@ -107,6 +107,8 @@ impl WindowBuilder { title: String::new(), menu: None, size: Size::new(500.0, 400.0), + resizable: true, + show_titlebar: true, } } diff --git a/druid-shell/src/platform/windows/window.rs b/druid-shell/src/platform/windows/window.rs index 5405f696e2..5ed2903aa7 100644 --- a/druid-shell/src/platform/windows/window.rs +++ b/druid-shell/src/platform/windows/window.rs @@ -73,7 +73,7 @@ pub struct WindowBuilder { menu: Option, present_strategy: PresentStrategy, resizable: bool, - decorated: bool, + show_titlebar: bool, size: Size, } @@ -704,7 +704,7 @@ impl WindowBuilder { title: String::new(), menu: None, resizable: true, - decorated: true, + show_titlebar: true, present_strategy: Default::default(), size: Size::new(500.0, 400.0), } From c86e9a615cdbc223dca007355846cb01373ba0f8 Mon Sep 17 00:00:00 2001 From: Federico Dolce Date: Sun, 1 Mar 2020 20:42:25 +0100 Subject: [PATCH 5/8] Fixed typos, added methods to generic WindowHandle --- druid-shell/src/window.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/druid-shell/src/window.rs b/druid-shell/src/window.rs index 50d88dd641..e9cb8b2207 100644 --- a/druid-shell/src/window.rs +++ b/druid-shell/src/window.rs @@ -110,6 +110,16 @@ impl WindowHandle { self.0.close() } + /// Set whether the window should be resizable + pub fn resizable(&self, resizable: bool) { + self.0.set_resizable(resizable) + } + + /// Set whether the window should show titlebar + pub fn show_titlebar(&self, show_titlebar: bool) { + self.0.show_titlebar(show_titlebar) + } + /// Bring this window to the front of the window stack and give it focus. pub fn bring_to_front_and_focus(&self) { self.0.bring_to_front_and_focus() @@ -213,12 +223,12 @@ impl WindowBuilder { self.0.set_size(size) } - /// 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 + /// 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) } From a05d3195f300ebfcbef9dbb287937579c25cf20b Mon Sep 17 00:00:00 2001 From: Federico Dolce Date: Sun, 1 Mar 2020 20:54:26 +0100 Subject: [PATCH 6/8] Added stubs for windows and mac --- druid-shell/src/platform/mac/window.rs | 6 ++++++ druid-shell/src/platform/windows/window.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/druid-shell/src/platform/mac/window.rs b/druid-shell/src/platform/mac/window.rs index 209cd946dd..e094805d00 100644 --- a/druid-shell/src/platform/mac/window.rs +++ b/druid-shell/src/platform/mac/window.rs @@ -677,6 +677,12 @@ impl WindowHandle { } } + // TODO: Implement this + pub fn show_titlebar(&self, show_titlebar: bool) {} + + // TODO: Implement this + pub fn resizable(&self, resizable: bool) {} + pub fn set_menu(&self, menu: Menu) { unsafe { NSApp().setMainMenu_(menu.menu); diff --git a/druid-shell/src/platform/windows/window.rs b/druid-shell/src/platform/windows/window.rs index 5ed2903aa7..9c617f222e 100644 --- a/druid-shell/src/platform/windows/window.rs +++ b/druid-shell/src/platform/windows/window.rs @@ -1073,6 +1073,12 @@ impl WindowHandle { } } + // TODO: Implement this + pub fn show_titlebar(&self, show_titlebar: bool) {} + + // TODO: Implement this + pub fn resizable(&self, resizable: bool) {} + pub fn set_menu(&self, menu: Menu) { let accels = menu.accels(); let hmenu = menu.into_hmenu(); From 95688593a93a06f6ea98380da5c79683b3b111e8 Mon Sep 17 00:00:00 2001 From: Federico Dolce Date: Sun, 1 Mar 2020 20:59:54 +0100 Subject: [PATCH 7/8] Maybe last fix? --- druid-shell/src/platform/gtk/window.rs | 2 +- druid-shell/src/window.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/druid-shell/src/platform/gtk/window.rs b/druid-shell/src/platform/gtk/window.rs index e2bf300fc5..511927b9b3 100644 --- a/druid-shell/src/platform/gtk/window.rs +++ b/druid-shell/src/platform/gtk/window.rs @@ -429,7 +429,7 @@ impl WindowHandle { } } - pub fn set_resizable(&self, resizable: bool) { + pub fn resizable(&self, resizable: bool) { if let Some(state) = self.state.upgrade() { state.window.set_resizable(resizable) } diff --git a/druid-shell/src/window.rs b/druid-shell/src/window.rs index e9cb8b2207..386a04a783 100644 --- a/druid-shell/src/window.rs +++ b/druid-shell/src/window.rs @@ -112,7 +112,7 @@ impl WindowHandle { /// Set whether the window should be resizable pub fn resizable(&self, resizable: bool) { - self.0.set_resizable(resizable) + self.0.resizable(resizable) } /// Set whether the window should show titlebar From e6ccd9bc3b8042cc507adeae02e57529215e852c Mon Sep 17 00:00:00 2001 From: Federico Dolce Date: Sun, 1 Mar 2020 21:05:54 +0100 Subject: [PATCH 8/8] Nope, it wasn't --- druid-shell/src/platform/mac/window.rs | 4 ++-- druid-shell/src/platform/windows/window.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/druid-shell/src/platform/mac/window.rs b/druid-shell/src/platform/mac/window.rs index e094805d00..b2bc37f2d3 100644 --- a/druid-shell/src/platform/mac/window.rs +++ b/druid-shell/src/platform/mac/window.rs @@ -678,10 +678,10 @@ impl WindowHandle { } // TODO: Implement this - pub fn show_titlebar(&self, show_titlebar: bool) {} + pub fn show_titlebar(&self, _show_titlebar: bool) {} // TODO: Implement this - pub fn resizable(&self, resizable: bool) {} + pub fn resizable(&self, _resizable: bool) {} pub fn set_menu(&self, menu: Menu) { unsafe { diff --git a/druid-shell/src/platform/windows/window.rs b/druid-shell/src/platform/windows/window.rs index 9c617f222e..5197f3a422 100644 --- a/druid-shell/src/platform/windows/window.rs +++ b/druid-shell/src/platform/windows/window.rs @@ -1074,10 +1074,10 @@ impl WindowHandle { } // TODO: Implement this - pub fn show_titlebar(&self, show_titlebar: bool) {} + pub fn show_titlebar(&self, _show_titlebar: bool) {} // TODO: Implement this - pub fn resizable(&self, resizable: bool) {} + pub fn resizable(&self, _resizable: bool) {} pub fn set_menu(&self, menu: Menu) { let accels = menu.accels();