diff options
author | crupest <crupest@outlook.com> | 2020-03-03 20:22:36 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-03-03 20:22:36 +0800 |
commit | 47053829c322c43032244937cb63f9da178b852d (patch) | |
tree | d17b81cdf61b3a48eb978176cfb57dda841da9d1 /include/cru/ui/render | |
parent | b0946c0e6dc163fe981f230302a1976449150907 (diff) | |
download | cru-47053829c322c43032244937cb63f9da178b852d.tar.gz cru-47053829c322c43032244937cb63f9da178b852d.tar.bz2 cru-47053829c322c43032244937cb63f9da178b852d.zip |
Write canvas render object layout logic.
Diffstat (limited to 'include/cru/ui/render')
-rw-r--r-- | include/cru/ui/render/canvas_render_object.hpp | 11 | ||||
-rw-r--r-- | include/cru/ui/render/layout_utility.hpp | 6 |
2 files changed, 17 insertions, 0 deletions
diff --git a/include/cru/ui/render/canvas_render_object.hpp b/include/cru/ui/render/canvas_render_object.hpp index 5fea8755..e3388014 100644 --- a/include/cru/ui/render/canvas_render_object.hpp +++ b/include/cru/ui/render/canvas_render_object.hpp @@ -21,6 +21,9 @@ class CanvasPaintEventArgs { Rect paint_rect_; }; +// The measure logic for `CanvasRenderObject` is that you set a desired size by +// `SetDesiredSize` (not `SetPreferredSize`) and it will compare desired size +// and available size and use the smaller one (by `Min`). class CanvasRenderObject : public RenderObject { public: CanvasRenderObject(); @@ -35,6 +38,12 @@ class CanvasRenderObject : public RenderObject { RenderObject* HitTest(const Point& point) override; + Size GetDesiredSize() const { return desired_size_; } + + // Set the desired size. This is the content size excluding padding and + // margin. + void SetDesiredSize(const Size& new_size) { desired_size_ = new_size; } + IEvent<CanvasPaintEventArgs>* PaintEvent() { return &paint_event_; } protected: @@ -42,6 +51,8 @@ class CanvasRenderObject : public RenderObject { void OnLayoutContent(const Rect& content_rect) override; private: + Size desired_size_{}; + Event<CanvasPaintEventArgs> paint_event_; }; } // namespace cru::ui::render diff --git a/include/cru/ui/render/layout_utility.hpp b/include/cru/ui/render/layout_utility.hpp new file mode 100644 index 00000000..38191ad5 --- /dev/null +++ b/include/cru/ui/render/layout_utility.hpp @@ -0,0 +1,6 @@ +#include "../base.hpp" + +namespace cru::ui::render { + Size Min(const Size& left, const Size& right); + Size Max(const Size& left, const Size& right); +} |