From f1da8e06253748887ae769845a6e605d56d5789b Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Mon, 16 Sep 2019 21:45:01 +0800 Subject: ... --- include/cru/ui/render/render_object.hpp | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'include/cru/ui/render/render_object.hpp') 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& GetChildren() const { return children_; } @@ -62,11 +77,30 @@ 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 children_{}; + ChildMode child_mode_ = ChildMode::None; + Point offset_{}; Size size_{}; -- cgit v1.2.3