diff options
author | crupest <crupest@outlook.com> | 2020-06-25 23:44:43 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-06-25 23:44:43 +0800 |
commit | a48ff30f9d4ac8ae6cc9adef4a07f8d9beb69e7a (patch) | |
tree | 077a74943214da7627cca2ba9966d90d5bed144a /include/cru/ui/render/TextRenderObject.hpp | |
parent | ce0ae2c3727f83f1943d528b006eec94ad80ece9 (diff) | |
download | cru-a48ff30f9d4ac8ae6cc9adef4a07f8d9beb69e7a.tar.gz cru-a48ff30f9d4ac8ae6cc9adef4a07f8d9beb69e7a.tar.bz2 cru-a48ff30f9d4ac8ae6cc9adef4a07f8d9beb69e7a.zip |
Write layout logic at half way.
Diffstat (limited to 'include/cru/ui/render/TextRenderObject.hpp')
-rw-r--r-- | include/cru/ui/render/TextRenderObject.hpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/include/cru/ui/render/TextRenderObject.hpp b/include/cru/ui/render/TextRenderObject.hpp index 96bb5997..efa8c2b8 100644 --- a/include/cru/ui/render/TextRenderObject.hpp +++ b/include/cru/ui/render/TextRenderObject.hpp @@ -4,6 +4,19 @@ #include <string> namespace cru::ui::render { +// Layout logic: +// 1. If preferred width is set then it is taken to do a text measure. If not +// set, then max width is taken to do that. +// 2. If the actual width of text after measure exceeds the required width, +// coerced value is returned and an error is reported. If preferred width is set +// and actual width is smaller than that, then preferred width is used. If +// preferred width is not set, then the same thing is applied to min width. +// 3. If actual height of text is bigger than max height, an error is reported +// and coerced value is returned. Or height is lifted up to be at least +// preferred size if set or min height. +// +// If the result layout box is bigger than actual text box, then text is center +// aligned. class TextRenderObject : public RenderObject { public: constexpr static float default_caret_width = 2; @@ -64,7 +77,9 @@ class TextRenderObject : public RenderObject { RenderObject* HitTest(const Point& point) override; protected: - Size OnMeasureContent(const MeasureRequirement& requirement) override; + // See remarks of this class. + Size OnMeasureContent(const MeasureRequirement& requirement, + const MeasureSize& preferred_size) override; void OnLayoutContent(const Rect& content_rect) override; void OnAfterLayout() override; |