aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/controls/flex_layout.cpp27
1 files changed, 27 insertions, 0 deletions
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);
}