diff options
| author | crupest <crupest@outlook.com> | 2018-11-07 18:54:41 +0800 |
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2018-11-07 18:54:41 +0800 |
| commit | 2b5b89e9483063f3af05fb5485043868d447994b (patch) | |
| tree | afb0bff66420d0a631416149142549adb5c45dc2 /src/ui/layout_base.h | |
| parent | 9f7de7f0775b86e3c82d4c5e3427a6f2fd98810b (diff) | |
| download | cru-2b5b89e9483063f3af05fb5485043868d447994b.tar.gz cru-2b5b89e9483063f3af05fb5485043868d447994b.tar.bz2 cru-2b5b89e9483063f3af05fb5485043868d447994b.zip | |
Add min max.
Diffstat (limited to 'src/ui/layout_base.h')
| -rw-r--r-- | src/ui/layout_base.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/ui/layout_base.h b/src/ui/layout_base.h index 662210bd..4a4c09ea 100644 --- a/src/ui/layout_base.h +++ b/src/ui/layout_base.h @@ -101,12 +101,27 @@ namespace cru constexpr bool Validate() const { - return length >= 0.0; + if (length < 0.0) + return false; + if (min.has_value() && min.value() < 0.0) + return false; + if (max.has_value() && max.value() < 0.0) + return false; + if (min.has_value() && max.has_value() && min.value() > max.value()) + return false; + return true; } + // only used in exactly mode, specify the exactly side length of content. float length = 0.0; MeasureMode mode = MeasureMode::Content; Alignment alignment = Alignment::Center; + + // min and max specify the min/max side length of content. + // they are used as hint and respect the actual size that content needs. + // when mode is exactly, length is coerced into the min-max range. + std::optional<float> min = std::nullopt; + std::optional<float> max = std::nullopt; }; struct BasicLayoutParams final |
