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 /src/ui/controls | |
parent | 465d89b4207cce929dc8e0b6ac93c3533ba19408 (diff) | |
download | cru-e8dd10eec26d26c3fb30f2712ccf58ac72edc8a2.tar.gz cru-e8dd10eec26d26c3fb30f2712ccf58ac72edc8a2.tar.bz2 cru-e8dd10eec26d26c3fb30f2712ccf58ac72edc8a2.zip |
...
Diffstat (limited to 'src/ui/controls')
-rw-r--r-- | src/ui/controls/flex_layout.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/ui/controls/flex_layout.cpp b/src/ui/controls/flex_layout.cpp index a8200a12..cf6d4aad 100644 --- a/src/ui/controls/flex_layout.cpp +++ b/src/ui/controls/flex_layout.cpp @@ -14,31 +14,29 @@ render::RenderObject* FlexLayout::GetRenderObject() const { return render_object_.get(); } -FlexChildLayoutData FlexLayout::GetChildLayoutData(Control* control) { - const auto& render_objects = render_object_->GetChildren(); +namespace { +int 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(), - control->GetRenderObject()); + 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."); } - int position = static_cast<int>(find_result - render_objects.cbegin()); - return *(render_object_->GetChildLayoutData(position)); + return static_cast<int>(find_result - render_objects.cbegin()); +} +} // namespace + +FlexChildLayoutData FlexLayout::GetChildLayoutData(Control* control) { + assert(control); + return render_object_->GetChildLayoutData( + FindPosition(render_object_.get(), control->GetRenderObject())); } void FlexLayout::SetChildLayoutData(Control* control, const FlexChildLayoutData& data) { - const auto& render_objects = render_object_->GetChildren(); - const auto find_result = - std::find(render_objects.cbegin(), render_objects.cend(), - control->GetRenderObject()); - if (find_result == render_objects.cend()) { - throw std::logic_error("Control is not a child of FlexLayout."); - } - int position = static_cast<int>(find_result - render_objects.cbegin()); - const auto d = render_object_->GetChildLayoutData(position); - *d = data; - if (const auto window = GetWindow()) window->InvalidateLayout(); + assert(control); + render_object_->SetChildLayoutData( + FindPosition(render_object_.get(), control->GetRenderObject()), data); } void FlexLayout::OnAddChild(Control* child, int position) { |