diff options
author | crupest <crupest@outlook.com> | 2022-03-12 21:43:40 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-12 21:43:40 +0800 |
commit | 3ce391f85443ce8bb47a7e0ff3bef0051cf4006e (patch) | |
tree | 59f8c4b4a6c66676d206bda5bfce3ff5020e4d26 /include/cru/ui/render/RenderObject.h | |
parent | f3b5009040a05e8efd15c385cacf5dd594ecf801 (diff) | |
download | cru-3ce391f85443ce8bb47a7e0ff3bef0051cf4006e.tar.gz cru-3ce391f85443ce8bb47a7e0ff3bef0051cf4006e.tar.bz2 cru-3ce391f85443ce8bb47a7e0ff3bef0051cf4006e.zip |
...
Diffstat (limited to 'include/cru/ui/render/RenderObject.h')
-rw-r--r-- | include/cru/ui/render/RenderObject.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/include/cru/ui/render/RenderObject.h b/include/cru/ui/render/RenderObject.h index 134fb935..8a0ba511 100644 --- a/include/cru/ui/render/RenderObject.h +++ b/include/cru/ui/render/RenderObject.h @@ -15,6 +15,16 @@ struct BoxConstraint { return max.width >= min.width && max.height >= min.height && min.width >= 0 && min.height >= 0; } + + constexpr bool Satisfy(const Size& size) const { + return size.width <= max.width && size.height <= max.height && + size.width >= min.width && size.height >= min.height; + } + + constexpr Size Coerce(const Size& size) const { + return Size{std::min(std::max(size.width, min.width), max.width), + std::min(std::max(size.height, min.height), max.height)}; + } }; /** @@ -96,9 +106,10 @@ class CRU_UI_API RenderObject : public Object { Size GetMinSize1() const { return min_size_; } void SetMinSize1(const Size& min_size); - Size GetMaxSize1() const { return max_size_; } void SetMaxSize1(const Size& max_size); + BoxConstraint CalculateMergedConstraint( + const BoxConstraint& constraint) const; // This method will merge requirement passed by argument and requirement of // the render object using MeasureRequirement::Merge and then call @@ -112,7 +123,7 @@ class CRU_UI_API RenderObject : public Object { // This will set offset of this render object and call OnLayoutCore. void Layout(const Point& offset); - void Measure1(const BoxConstraint& constraint); + Size Measure1(const BoxConstraint& constraint); virtual Thickness GetTotalSpaceThickness() const; virtual Thickness GetInnerSpaceThickness() const; |