aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cru/ui/render/canvas_render_object.hpp11
-rw-r--r--include/cru/ui/render/layout_utility.hpp6
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);
+}