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

Add default minimum size to WindowConfig #1438

Merged
merged 3 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ You can find its changes [documented below](#060---2020-06-01).
- `set_cursor` can be called in the `update` method. ([#1361] by [@jneem])
- `WidgetPod::is_initialized` to check if a widget has received `WidgetAdded`. ([#1259] by [@finnerale])
- `TextBox::with_text_alignment` and `TextBox::set_text_alignment` ([#1371] by [@cmyr])
- Add default minimum size to `WindowConfig`. ([#1438] by [@colinfruit])

### Changed

Expand Down Expand Up @@ -355,6 +356,7 @@ Last release without a changelog :(
[@tay64]: https://github.com/tay64
[@JAicewizard]: https://github.com/JAicewizard
[@andrewhickman]: https://github.com/andrewhickman
[@colinfruit]: https://github.com/colinfruit

[#599]: https://github.com/linebender/druid/pull/599
[#611]: https://github.com/linebender/druid/pull/611
Expand Down Expand Up @@ -538,6 +540,7 @@ Last release without a changelog :(
[#1361]: https://github.com/linebender/druid/pull/1361
[#1371]: https://github.com/linebender/druid/pull/1371
[#1410]: https://github.com/linebender/druid/pull/1410
[#1438]: https://github.com/linebender/druid/pull/1438

[Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master
[0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0
Expand Down
13 changes: 7 additions & 6 deletions druid/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use crate::{AppDelegate, Data, Env, LocalizedString, MenuDesc, Widget};

use druid_shell::WindowState;

const WINDOW_MIN_SIZE: Size = Size::new(400., 400.);

/// A function that modifies the initial environment.
type EnvSetupFn<T> = dyn FnOnce(&mut Env, &T);

Expand All @@ -39,7 +41,7 @@ pub struct AppLauncher<T> {
/// It does not include anything related to app data.
pub struct WindowConfig {
pub(crate) size: Option<Size>,
pub(crate) min_size: Option<Size>,
pub(crate) min_size: Size,
pub(crate) position: Option<Point>,
pub(crate) resizable: Option<bool>,
pub(crate) show_titlebar: Option<bool>,
Expand Down Expand Up @@ -187,7 +189,7 @@ impl Default for WindowConfig {
fn default() -> Self {
WindowConfig {
size: None,
min_size: None,
min_size: WINDOW_MIN_SIZE,
position: None,
resizable: None,
show_titlebar: None,
Expand Down Expand Up @@ -231,7 +233,7 @@ impl WindowConfig {
/// [`window_size`]: #method.window_size
/// [display points]: struct.Scale.html
pub fn with_min_size(mut self, size: impl Into<Size>) -> Self {
self.min_size = Some(size.into());
self.min_size = size.into();
self
}

Expand Down Expand Up @@ -285,9 +287,6 @@ impl WindowConfig {
if let Some(size) = self.size {
builder.set_size(size);
}
if let Some(min_size) = self.min_size {
builder.set_min_size(min_size);
}

if let Some(position) = self.position {
builder.set_position(position);
Expand All @@ -300,6 +299,8 @@ impl WindowConfig {
if let Some(state) = self.state {
builder.set_window_state(state);
}

builder.set_min_size(self.min_size);
}

/// Apply this window configuration to the passed in WindowHandle
Expand Down