From 55d98d3259e9f3e184ad6323d1d49d298bd1723b Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Sun, 15 Sep 2019 00:22:59 +0800 Subject: ... --- src/ui/controls/flex_layout.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/ui/controls') diff --git a/src/ui/controls/flex_layout.cpp b/src/ui/controls/flex_layout.cpp index 340710cc..bb8e3c14 100644 --- a/src/ui/controls/flex_layout.cpp +++ b/src/ui/controls/flex_layout.cpp @@ -14,6 +14,33 @@ render::RenderObject* FlexLayout::GetRenderObject() const { return render_object_.get(); } +FlexChildLayoutData FlexLayout::GetChildLayoutData(Control* control) { + 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 = find_result - render_objects.cbegin(); + return *(render_object_->GetChildLayoutData(position)); +} + +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 = find_result - render_objects.cbegin(); + const auto d = render_object_->GetChildLayoutData(position); + *d = data; + if (const auto window = GetWindow()) window->InvalidateLayout(); +} + void FlexLayout::OnAddChild(Control* child, int position) { render_object_->AddChild(child->GetRenderObject(), position); } -- cgit v1.2.3