Skip to content

Commit

Permalink
Merge pull request #1438 from colinfruit/default-min-window-size
Browse files Browse the repository at this point in the history
Add default minimum size to `WindowConfig`
  • Loading branch information
richard-uk1 authored Nov 30, 2020
2 parents 60ea802 + 0b87e4e commit d23a024
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
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

0 comments on commit d23a024

Please sign in to comment.