diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/platform/GraphicsBase.h | 7 | ||||
-rw-r--r-- | include/cru/ui/render/RenderObject.h | 27 |
2 files changed, 32 insertions, 2 deletions
diff --git a/include/cru/platform/GraphicsBase.h b/include/cru/platform/GraphicsBase.h index 62a8bf29..f134e74d 100644 --- a/include/cru/platform/GraphicsBase.h +++ b/include/cru/platform/GraphicsBase.h @@ -1,5 +1,5 @@ #pragma once -#include "cru/common/Base.h" +#include "Base.h" #include "cru/common/Format.h" #include "cru/common/Range.h" @@ -51,7 +51,10 @@ inline String ToString(const Point& point) { return Format(u"(x: {}, y: {})", point.x, point.y); } -struct Size final { +struct CRU_PLATFORM_API Size final { + static const Size kMax; + static const Size kZero; + constexpr Size() = default; constexpr Size(const float width, const float height) : width(width), height(height) {} diff --git a/include/cru/ui/render/RenderObject.h b/include/cru/ui/render/RenderObject.h index 9f2b69d9..134fb935 100644 --- a/include/cru/ui/render/RenderObject.h +++ b/include/cru/ui/render/RenderObject.h @@ -5,6 +5,18 @@ #include "cru/common/String.h" namespace cru::ui::render { +struct BoxConstraint { + static const BoxConstraint kNotLimit; + + Size max; + Size min; + + constexpr bool Validate() const { + return max.width >= min.width && max.height >= min.height && + min.width >= 0 && min.height >= 0; + } +}; + /** * ### Layout * @@ -82,6 +94,12 @@ class CRU_UI_API RenderObject : public Object { return custom_measure_requirement_; } + Size GetMinSize1() const { return min_size_; } + void SetMinSize1(const Size& min_size); + + Size GetMaxSize1() const { return max_size_; } + void SetMaxSize1(const Size& max_size); + // This method will merge requirement passed by argument and requirement of // the render object using MeasureRequirement::Merge and then call // MeasureRequirement::Normalize on it. And it will use preferred size of the @@ -94,6 +112,8 @@ 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); + virtual Thickness GetTotalSpaceThickness() const; virtual Thickness GetInnerSpaceThickness() const; @@ -125,6 +145,8 @@ class CRU_UI_API RenderObject : public Object { virtual Size OnMeasureCore(const MeasureRequirement& requirement, const MeasureSize& preferred_size); + virtual Size OnMeasureCore1(const BoxConstraint& constraint); + // Please reduce margin and padding or other custom things and pass the result // content rect to OnLayoutContent. virtual void OnLayoutCore(); @@ -136,6 +158,8 @@ class CRU_UI_API RenderObject : public Object { virtual Size OnMeasureContent(const MeasureRequirement& requirement, const MeasureSize& preferred_size) = 0; + virtual Size OnMeasureContent1(const BoxConstraint& constraint); + // Layout all content and children(Call Layout on them). // Lefttop of content_rect should be added when calculated children's offset. virtual void OnLayoutContent(const Rect& content_rect) = 0; @@ -160,5 +184,8 @@ class CRU_UI_API RenderObject : public Object { MeasureSize preferred_size_{}; MeasureRequirement custom_measure_requirement_{}; + + Size min_size_ = Size::kZero; + Size max_size_ = Size::kMax; }; } // namespace cru::ui::render |