diff options
author | crupest <crupest@outlook.com> | 2022-02-09 23:53:18 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-09 23:53:18 +0800 |
commit | b8863c403a44c1c7ac35f1a1da92bbf3c8858552 (patch) | |
tree | 7e38f029f0657e6c1210a53f1cba331cdb8feab6 /src/ui/controls/FlexLayout.cpp | |
parent | d18b5453d7ffd19667ee8ac125b34ab5328f0dc3 (diff) | |
download | cru-b8863c403a44c1c7ac35f1a1da92bbf3c8858552.tar.gz cru-b8863c403a44c1c7ac35f1a1da92bbf3c8858552.tar.bz2 cru-b8863c403a44c1c7ac35f1a1da92bbf3c8858552.zip |
...
Diffstat (limited to 'src/ui/controls/FlexLayout.cpp')
-rw-r--r-- | src/ui/controls/FlexLayout.cpp | 53 |
1 files changed, 7 insertions, 46 deletions
diff --git a/src/ui/controls/FlexLayout.cpp b/src/ui/controls/FlexLayout.cpp index ecf4d428..8d71cfdb 100644 --- a/src/ui/controls/FlexLayout.cpp +++ b/src/ui/controls/FlexLayout.cpp @@ -1,70 +1,31 @@ #include "cru/ui/controls/FlexLayout.h" namespace cru::ui::controls { -using render::FlexLayoutRenderObject; - -FlexLayout::FlexLayout() { - render_object_.reset(new FlexLayoutRenderObject()); - render_object_->SetAttachedControl(this); - SetContainerRenderObject(render_object_.get()); -} +FlexLayout::FlexLayout() = default; FlexLayout::~FlexLayout() = default; -render::RenderObject* FlexLayout::GetRenderObject() const { - return render_object_.get(); -} - -namespace { -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<Index>(find_result - render_objects.cbegin()); -} -} // namespace - -FlexChildLayoutData FlexLayout::GetChildLayoutData(Control* control) { - Expects(control); - return render_object_->GetChildLayoutData( - FindPosition(render_object_.get(), control->GetRenderObject())); -} - -void FlexLayout::SetChildLayoutData(Control* control, - FlexChildLayoutData data) { - Expects(control); - render_object_->SetChildLayoutData( - FindPosition(render_object_.get(), control->GetRenderObject()), - std::move(data)); -} - FlexMainAlignment FlexLayout::GetContentMainAlign() const { - return render_object_->GetContentMainAlign(); + return GetContainerRenderObject()->GetContentMainAlign(); } void FlexLayout::SetContentMainAlign(FlexMainAlignment value) { - if (value == GetContentMainAlign()) return; - render_object_->SetContentMainAlign(value); + GetContainerRenderObject()->SetContentMainAlign(value); } FlexDirection FlexLayout::GetFlexDirection() const { - return render_object_->GetFlexDirection(); + return GetContainerRenderObject()->GetFlexDirection(); } void FlexLayout::SetFlexDirection(FlexDirection direction) { - if (direction == GetFlexDirection()) return; - render_object_->SetFlexDirection(direction); + GetContainerRenderObject()->SetFlexDirection(direction); } FlexCrossAlignment FlexLayout::GetItemCrossAlign() const { - return render_object_->GetItemCrossAlign(); + return GetContainerRenderObject()->GetItemCrossAlign(); } void FlexLayout::SetItemCrossAlign(FlexCrossAlignment alignment) { - if (alignment == GetItemCrossAlign()) return; - render_object_->SetItemCrossAlign(alignment); + GetContainerRenderObject()->SetItemCrossAlign(alignment); } } // namespace cru::ui::controls |