aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui/render/render_object.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/ui/render/render_object.hpp')
-rw-r--r--include/cru/ui/render/render_object.hpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/include/cru/ui/render/render_object.hpp b/include/cru/ui/render/render_object.hpp
index dca254cc..8ea7ca79 100644
--- a/include/cru/ui/render/render_object.hpp
+++ b/include/cru/ui/render/render_object.hpp
@@ -15,6 +15,18 @@ class Painter;
}
namespace cru::ui::render {
+struct IRenderHost : Interface {
+ // Mark the layout as invalid, and arrange a re-layout later.
+ // Note this method might be called more than one times in a message cycle. So
+ // implementation should merge multiple request into once.
+ virtual void InvalidateLayout() = 0;
+
+ // Mark the paint as invalid, and arrange a re-paint later.
+ // Note this method might be called more than one times in a message cycle. So
+ // implementation should merge multiple request into once.
+ virtual void InvalidatePaint() = 0;
+};
+
class RenderObject : public Object {
protected:
RenderObject() = default;
@@ -29,6 +41,9 @@ class RenderObject : public Object {
Control* GetAttachedControl() const { return control_; }
void SetAttachedControl(Control* new_control) { control_ = new_control; }
+ IRenderHost* GetRenderHost() const { return render_host_; }
+ void SetRenderHost(IRenderHost* render_host) { render_host_ = render_host; }
+
RenderObject* GetParent() const { return parent_; }
const std::vector<RenderObject*>& GetChildren() const { return children_; }
@@ -63,10 +78,29 @@ class RenderObject : public Object {
virtual RenderObject* HitTest(const Point& point) = 0;
protected:
+ enum class ChildMode {
+ None,
+ Single,
+ Multiple,
+ };
+
+ void SetChildMode(ChildMode mode) { child_mode_ = mode; }
+
+ void InvalidateLayout() const {
+ if (render_host_ != nullptr) render_host_->InvalidateLayout();
+ }
+
+ void InvalidatePaint() const {
+ if (render_host_ != nullptr) render_host_->InvalidatePaint();
+ }
+
+ protected:
virtual void OnParentChanged(RenderObject* old_parent,
RenderObject* new_parent);
+ // default is to invalidate both layout and paint
virtual void OnAddChild(RenderObject* new_child, int position);
+ // default is to invalidate both layout and paint
virtual void OnRemoveChild(RenderObject* removed_child, int position);
virtual void OnSizeChanged(const Size& old_size, const Size& new_size);
@@ -83,10 +117,13 @@ class RenderObject : public Object {
private:
Control* control_ = nullptr;
+ IRenderHost* render_host_ = nullptr;
RenderObject* parent_ = nullptr;
std::vector<RenderObject*> children_{};
+ ChildMode child_mode_ = ChildMode::None;
+
Point offset_{};
Size size_{};