From 20ab1ad029147ed0fe6a730df8554a3c1d6dc8b7 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Fri, 13 Sep 2024 10:12:01 -0700 Subject: [PATCH] Fixed initial window settings These aren't entries in the changelog since they're bug fixes for new code since the last release -- the entries on the changelog are unaffected. - focused and occluded no longer is explicitly set to false. Now, once the window has been fully initialized, the values are read from winit which will cause callbacks to be fired if the value has changed. - The automatic_layout parameter if outer_position had its meaning inverted. Passing true now properly ensures the window is automatically positioned. --- CHANGELOG.md | 2 ++ Cargo.lock | 12 +++++----- examples/window-properties.rs | 2 +- src/styles/components.rs | 2 +- src/window.rs | 42 ++++++++++++++++++++++++++++------- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01ab09d..1432372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -142,6 +142,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 session. - `App::prevent_shutdown()` returns a guard that prevents the application from closing automatically when the final window is closed. +- `WindowBehavior::initialized` is invoked once the window has been fully + initialized. [139]: https://github.com/khonsulabs/cushy/issues/139 diff --git a/Cargo.lock b/Cargo.lock index 67bef7a..42a6f5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,7 +124,7 @@ checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" [[package]] name = "appit" version = "0.3.2" -source = "git+https://github.com/khonsulabs/appit#331bfdd3534a2f6a7c44f24017b4d52aee40da5b" +source = "git+https://github.com/khonsulabs/appit#57acfd2e15523a160fbfd0db4c91d2407ed8d4c5" dependencies = [ "winit", ] @@ -1311,7 +1311,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" [[package]] name = "kludgine" version = "0.10.0" -source = "git+https://github.com/khonsulabs/kludgine#eb700333d12b201b0e6af2396898839b2f7a04a8" +source = "git+https://github.com/khonsulabs/kludgine#236c9773a323ee63dc38bdfa78476ff336547640" dependencies = [ "ahash", "alot", @@ -1523,9 +1523,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "memmap2" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" +checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" dependencies = [ "libc", ] @@ -3089,9 +3089,9 @@ checksum = "ad8d71f5726e5f285a935e9fe8edfd53f0491eb6e9a5774097fdabee7cd8c9cd" [[package]] name = "unicode-segmentation" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "unicode-width" diff --git a/examples/window-properties.rs b/examples/window-properties.rs index cbc39a0..9656a55 100644 --- a/examples/window-properties.rs +++ b/examples/window-properties.rs @@ -7,7 +7,7 @@ use figures::{IntoSigned, Point, Px2D, UPx2D}; #[cushy::main] fn main(app: &mut App) { - let focused = Dynamic::new(false); + let focused = Dynamic::new(true); let occluded = Dynamic::new(false); let maximized = Dynamic::new(false); let minimized = Dynamic::new(false); diff --git a/src/styles/components.rs b/src/styles/components.rs index bcc10a9..00ffa66 100644 --- a/src/styles/components.rs +++ b/src/styles/components.rs @@ -244,7 +244,7 @@ define_components! { /// opaque background. OpaqueWidgetColor(Color, "opaque_color", .surface.opaque_widget) /// A [`Color`] to be use for the transparent surface behind an overlay. - ScrimColor(Color, "scrim_color", |context| context.theme_pair().scrim.with_alpha(50)) + ScrimColor(Color, "scrim_color", |context| context.theme_pair().scrim.with_alpha(70)) /// A set of radius descriptions for how much roundness to apply to the /// shapes of widgets. CornerRadius(CornerRadii, "corner_radius", CornerRadii::from(Dimension::Lp(Lp::points(6)))) diff --git a/src/window.rs b/src/window.rs index 3678533..1a3dc99 100644 --- a/src/window.rs +++ b/src/window.rs @@ -714,14 +714,11 @@ where /// `true`. /// /// The current value of `focused` will inform the OS whether the window - /// should be activated upon opening. To prevent state mismatches, if - /// `focused` is a dynamic, it will be initialized with `false` so that the - /// transition to focused can be observed. + /// should be activated upon opening. pub fn focused(mut self, focused: impl IntoValue) -> Self { let focused = focused.into_value(); self.attributes.active = focused.get(); if let Value::Dynamic(focused) = focused { - focused.set(false); self.focused = Some(focused); } self @@ -733,11 +730,8 @@ where /// When the window is occluded (completely hidden/offscreen/minimized), the /// dynamic will contain `true`. If the window is at least partially /// visible, this value will contain `true`. - /// - /// `occluded` will be initialized with an initial state of `false`. pub fn occluded(mut self, occluded: impl IntoDynamic) -> Self { let occluded = occluded.into_dynamic(); - occluded.set(false); self.occluded = Some(occluded); self } @@ -794,7 +788,7 @@ where ) -> Self { let position = position.into_value(); - if let Some(initial_position) = automatic_layout.then(|| position.get()) { + if let Some(initial_position) = (!automatic_layout).then(|| position.get()) { self.attributes.position = Some(winit::dpi::Position::Physical(initial_position.into())); } @@ -1183,6 +1177,14 @@ pub trait WindowBehavior: Sized + 'static { /// Create the window's root widget. This function is only invoked once. fn make_root(&mut self) -> WidgetInstance; + /// Invoked once the window has been fully initialized. + #[allow(unused_variables)] + fn initialized(&mut self, window: &mut W) + where + W: PlatformWindow, + { + } + /// The window has been requested to close. If this function returns true, /// the window will be closed. Returning false prevents the window from /// closing. @@ -2363,6 +2365,30 @@ where ) } + fn initialized( + &mut self, + window: kludgine::app::Window<'_, WindowCommand>, + kludgine: &mut Kludgine, + ) { + let cushy = self.cushy.clone(); + let _guard = cushy.enter_runtime(); + self.focused.set(window.focused()); + self.occluded.set(window.occluded()); + let inner_size = window.inner_size(); + self.resized(inner_size, &window); + + self.behavior.initialized(&mut RunningWindow::new( + window, + kludgine.id(), + &self.redraw_status, + &self.cushy, + &self.focused, + &self.occluded, + self.inner_size.source(), + &self.close_requested, + )); + } + fn prepare( &mut self, window: kludgine::app::Window<'_, WindowCommand>,