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

Added BoxConstraints::UNBOUNDED #1126

Merged
merged 3 commits into from
Aug 18, 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ You can find its changes [documented below](#060---2020-06-01).
- Export `Image` and `ImageData` by default. ([#1011] by [@covercash2])
- Re-export `druid_shell::Scalable` under `druid` namespace. ([#1075] by [@ForLoveOfCats])
- `TextBox` now supports ctrl and shift hotkeys. ([#1076] by [@vkahl])
- Added selection text color to textbox. ([#1093] by [@sysint64])
- Selection text color to textbox. ([#1093] by [@sysint64])
- `BoxConstraints::UNBOUNDED` constant. ([#1126] by [@danieldulaney])
- Close requests from the shell can now be intercepted ([#1118] by [@jneem])

### Changed
Expand Down Expand Up @@ -386,6 +387,7 @@ Last release without a changelog :(
[#1118]: https://github.com/linebender/druid/pull/1118
[#1119]: https://github.com/linebender/druid/pull/1119
[#1120]: https://github.com/linebender/druid/pull/1120
[#1126]: https://github.com/linebender/druid/pull/1120

[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
21 changes: 21 additions & 0 deletions druid/src/box_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ pub struct BoxConstraints {
}

impl BoxConstraints {
/// An unbounded box constraints object.
///
/// Can be satisfied by any nonnegative size.
pub const UNBOUNDED: BoxConstraints = BoxConstraints {
min: Size::ZERO,
max: Size::new(f64::INFINITY, f64::INFINITY),
};

/// Create a new box constraints object.
///
/// Create constraints based on minimum and maximum size.
Expand Down Expand Up @@ -156,3 +164,16 @@ impl BoxConstraints {
BoxConstraints::new(min, max)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn unbounded() {
assert!(!BoxConstraints::UNBOUNDED.is_width_bounded());
assert!(!BoxConstraints::UNBOUNDED.is_height_bounded());

assert_eq!(BoxConstraints::UNBOUNDED.min(), Size::ZERO);
}
}