diff options
author | 杨宇千 <crupest@outlook.com> | 2019-09-17 16:05:17 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-09-17 16:05:17 +0800 |
commit | e8dd10eec26d26c3fb30f2712ccf58ac72edc8a2 (patch) | |
tree | 75293a2bb477fb1872087fab8bfd2c89b6d2051f /include/cru/ui/render | |
parent | 465d89b4207cce929dc8e0b6ac93c3533ba19408 (diff) | |
download | cru-e8dd10eec26d26c3fb30f2712ccf58ac72edc8a2.tar.gz cru-e8dd10eec26d26c3fb30f2712ccf58ac72edc8a2.tar.bz2 cru-e8dd10eec26d26c3fb30f2712ccf58ac72edc8a2.zip |
...
Diffstat (limited to 'include/cru/ui/render')
-rw-r--r-- | include/cru/ui/render/border_render_object.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/render/flex_layout_render_object.hpp | 22 | ||||
-rw-r--r-- | include/cru/ui/render/render_object.hpp | 11 | ||||
-rw-r--r-- | include/cru/ui/render/text_render_object.hpp | 4 | ||||
-rw-r--r-- | include/cru/ui/render/window_render_object.hpp | 2 |
5 files changed, 28 insertions, 15 deletions
diff --git a/include/cru/ui/render/border_render_object.hpp b/include/cru/ui/render/border_render_object.hpp index 18809f91..e21ce34c 100644 --- a/include/cru/ui/render/border_render_object.hpp +++ b/include/cru/ui/render/border_render_object.hpp @@ -106,13 +106,13 @@ class BorderRenderObject : public RenderObject { RenderObject* HitTest(const Point& point) override; protected: - void OnSizeChanged(const Size& old_size, const Size& new_size) override; - void OnMeasureCore(const Size& available_size) override; void OnLayoutCore(const Rect& rect) override; Size OnMeasureContent(const Size& available_size) override; void OnLayoutContent(const Rect& content_rect) override; + void OnAfterLayout() override; + private: RenderObject* GetChild() const { return GetChildren().empty() ? nullptr : GetChildren()[0]; diff --git a/include/cru/ui/render/flex_layout_render_object.hpp b/include/cru/ui/render/flex_layout_render_object.hpp index 68ffc89e..7b71b96e 100644 --- a/include/cru/ui/render/flex_layout_render_object.hpp +++ b/include/cru/ui/render/flex_layout_render_object.hpp @@ -15,7 +15,7 @@ namespace internal { constexpr int align_start = 0; constexpr int align_end = align_start + 1; constexpr int align_center = align_end + 1; -//constexpr int align_stretch = align_center + 1; +// constexpr int align_stretch = align_center + 1; } // namespace internal enum class FlexMainAlignment { @@ -27,7 +27,7 @@ enum class FlexCrossAlignment { Start = internal::align_start, End = internal::align_end, Center = internal::align_center, -// Stretch = internal::align_stretch + // Stretch = internal::align_stretch }; struct FlexChildLayoutData { @@ -50,19 +50,33 @@ class FlexLayoutRenderObject : public RenderObject { ~FlexLayoutRenderObject() override = default; FlexDirection GetFlexDirection() const { return direction_; } - void SetFlexDirection(FlexDirection direction) { direction_ = direction; } + void SetFlexDirection(FlexDirection direction) { + direction_ = direction; + InvalidateLayout(); + } FlexMainAlignment GetContentMainAlign() const { return content_main_align_; } void SetContentMainAlign(FlexMainAlignment align) { content_main_align_ = align; + InvalidateLayout(); } FlexCrossAlignment GetItemCrossAlign() const { return item_cross_align_; } void SetItemCrossAlign(FlexCrossAlignment align) { item_cross_align_ = align; + InvalidateLayout(); + } + + FlexChildLayoutData GetChildLayoutData(int position) { + assert(position >= 0 && position < child_layout_data_.size()); + return child_layout_data_[position]; } - FlexChildLayoutData* GetChildLayoutData(int position); + void SetChildLayoutData(int position, const FlexChildLayoutData& data) { + assert(position >= 0 && position < child_layout_data_.size()); + child_layout_data_[position] = data; + InvalidateLayout(); + } void Draw(platform::graph::Painter* painter) override; diff --git a/include/cru/ui/render/render_object.hpp b/include/cru/ui/render/render_object.hpp index 2394bf97..befaa3ec 100644 --- a/include/cru/ui/render/render_object.hpp +++ b/include/cru/ui/render/render_object.hpp @@ -59,11 +59,7 @@ class RenderObject : public Object { Point GetOffset() const { return offset_; } void SetOffset(const Point& offset) { offset_ = offset; } Size GetSize() const { return size_; } - void SetSize(const Size& size) { - const auto old_size = size_; - size_ = size; - OnSizeChanged(old_size, size); - } + void SetSize(const Size& size) { size_ = size; } Thickness GetMargin() const { return margin_; } void SetMargin(const Thickness& margin) { margin_ = margin; } @@ -109,13 +105,14 @@ class RenderObject : public Object { // 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); - virtual void OnMeasureCore(const Size& available_size); virtual void OnLayoutCore(const Rect& rect); virtual Size OnMeasureContent(const Size& available_size) = 0; virtual void OnLayoutContent(const Rect& content_rect) = 0; + virtual void OnAfterLayout(); + static void NotifyAfterLayoutRecursive(RenderObject* render_object); + Rect GetContentRect() const; private: diff --git a/include/cru/ui/render/text_render_object.hpp b/include/cru/ui/render/text_render_object.hpp index 054d9b47..a10e3b74 100644 --- a/include/cru/ui/render/text_render_object.hpp +++ b/include/cru/ui/render/text_render_object.hpp @@ -53,11 +53,11 @@ class TextRenderObject : public RenderObject { RenderObject* HitTest(const Point& point) override; protected: - void OnSizeChanged(const Size& old_size, const Size& new_size) override; - Size OnMeasureContent(const Size& available_size) override; void OnLayoutContent(const Rect& content_rect) override; + void OnAfterLayout() override; + private: std::shared_ptr<platform::graph::Brush> brush_; std::shared_ptr<platform::graph::Font> font_; diff --git a/include/cru/ui/render/window_render_object.hpp b/include/cru/ui/render/window_render_object.hpp index 431f7025..2260c293 100644 --- a/include/cru/ui/render/window_render_object.hpp +++ b/include/cru/ui/render/window_render_object.hpp @@ -40,6 +40,8 @@ class WindowRenderObject : public RenderObject { private: Window* window_; + EventRevokerGuard after_layout_event_guard_; + std::unique_ptr<IRenderHost> render_host_; }; } // namespace cru::ui::render |