Honoring Window::inner_size's initial value

Refs #160
This commit is contained in:
Jonathan Johnson 2024-07-08 16:50:50 -07:00
parent 4d6196f4e7
commit 60c7ef8859
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
3 changed files with 11 additions and 0 deletions

View file

@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
persist function. persist function.
- Fixed a deadlock that could occur when multiple threads were attempting to - Fixed a deadlock that could occur when multiple threads were attempting to
execute change callbacks for the same dynamic at the same time. execute change callbacks for the same dynamic at the same time.
- The initial `inner_size` of a `Window` is now used if it is non-zero and
`WindowAttributes::inner_size` is `None`.
### Added ### Added

View file

@ -3,13 +3,16 @@ use cushy::{
widget::MakeWidget, widget::MakeWidget,
Run, Run,
}; };
use figures::{units::UPx, Size};
fn main() -> cushy::Result { fn main() -> cushy::Result {
let has_unsaved_changes = Dynamic::new(true); let has_unsaved_changes = Dynamic::new(true);
let inner_size = Dynamic::new(Size::new(UPx::new(1000), UPx::new(800)));
"Prevent Closing" "Prevent Closing"
.into_checkbox(has_unsaved_changes.clone()) .into_checkbox(has_unsaved_changes.clone())
.into_window() .into_window()
.on_close_requested(move |()| !has_unsaved_changes.get()) .on_close_requested(move |()| !has_unsaved_changes.get())
.inner_size(inner_size)
.run() .run()
} }

View file

@ -1828,6 +1828,12 @@ where
attrs.preferred_theme = Some((*theme_mode).into()); attrs.preferred_theme = Some((*theme_mode).into());
} }
attrs.title = settings.title.get(); attrs.title = settings.title.get();
if attrs.inner_size.is_none() {
let dynamic_inner = settings.inner_size.get();
if !dynamic_inner.is_zero() {
attrs.inner_size = Some(winit::dpi::Size::Physical(dynamic_inner.into()));
}
}
attrs attrs
} }