diff options
-rw-r--r-- | include/cru/ui/controls/FlexLayout.hpp | 2 | ||||
-rw-r--r-- | include/cru/ui/render/LayoutRenderObject.hpp | 13 | ||||
-rw-r--r-- | src/ui/controls/FlexLayout.cpp | 13 |
3 files changed, 18 insertions, 10 deletions
diff --git a/include/cru/ui/controls/FlexLayout.hpp b/include/cru/ui/controls/FlexLayout.hpp index beacd1f9..3d6087c2 100644 --- a/include/cru/ui/controls/FlexLayout.hpp +++ b/include/cru/ui/controls/FlexLayout.hpp @@ -29,7 +29,7 @@ class FlexLayout : public LayoutControl { void SetFlexDirection(FlexDirection direction); FlexChildLayoutData GetChildLayoutData(Control* control); - void SetChildLayoutData(Control* control, const FlexChildLayoutData& data); + void SetChildLayoutData(Control* control, FlexChildLayoutData data); protected: void OnAddChild(Control* child, Index position) override; diff --git a/include/cru/ui/render/LayoutRenderObject.hpp b/include/cru/ui/render/LayoutRenderObject.hpp index f99eb4ca..1eb9a816 100644 --- a/include/cru/ui/render/LayoutRenderObject.hpp +++ b/include/cru/ui/render/LayoutRenderObject.hpp @@ -22,10 +22,17 @@ class LayoutRenderObject : public RenderObject { return this->child_layout_data_; } - ChildLayoutData* GetChildLayoutData(Index position) { + void SetChildLayoutData(Index position, ChildLayoutData data) { Expects(position >= 0 && - position < static_cast<Index>(child_layout_data_.size())); - return &child_layout_data_[position]; + position < static_cast<Index>(this->child_layout_data_.size())); + this->child_layout_data_[position] = std::move(data); + this->InvalidateLayout(); + } + + const ChildLayoutData& GetChildLayoutData(Index position) const { + Expects(position >= 0 && + position < static_cast<Index>(this->child_layout_data_.size())); + return this->child_layout_data_[position]; } void Draw(platform::graph::IPainter* painter) override; diff --git a/src/ui/controls/FlexLayout.cpp b/src/ui/controls/FlexLayout.cpp index 25f30558..b7f350dc 100644 --- a/src/ui/controls/FlexLayout.cpp +++ b/src/ui/controls/FlexLayout.cpp @@ -17,28 +17,29 @@ render::RenderObject* FlexLayout::GetRenderObject() const { } namespace { -int FindPosition(render::RenderObject* parent, render::RenderObject* child) { +Index FindPosition(render::RenderObject* parent, render::RenderObject* child) { const auto& render_objects = parent->GetChildren(); const auto find_result = std::find(render_objects.cbegin(), render_objects.cend(), child); if (find_result == render_objects.cend()) { throw std::logic_error("Control is not a child of FlexLayout."); } - return static_cast<int>(find_result - render_objects.cbegin()); + return static_cast<Index>(find_result - render_objects.cbegin()); } } // namespace FlexChildLayoutData FlexLayout::GetChildLayoutData(Control* control) { Expects(control); - return *render_object_->GetChildLayoutData( + return render_object_->GetChildLayoutData( FindPosition(render_object_.get(), control->GetRenderObject())); } void FlexLayout::SetChildLayoutData(Control* control, - const FlexChildLayoutData& data) { + FlexChildLayoutData data) { Expects(control); - *render_object_->GetChildLayoutData( - FindPosition(render_object_.get(), control->GetRenderObject())) = data; + render_object_->SetChildLayoutData( + FindPosition(render_object_.get(), control->GetRenderObject()), + std::move(data)); } FlexMainAlignment FlexLayout::GetContentMainAlign() const { |