diff options
author | 杨宇千 <crupest@outlook.com> | 2019-09-15 00:22:59 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-09-15 00:22:59 +0800 |
commit | 55d98d3259e9f3e184ad6323d1d49d298bd1723b (patch) | |
tree | b986e6e4bc7e0dbfe5f00784722615bc365e7893 | |
parent | f9f2fa5ab0c92ed27337ba4894f13f61a7b7cc15 (diff) | |
download | cru-55d98d3259e9f3e184ad6323d1d49d298bd1723b.tar.gz cru-55d98d3259e9f3e184ad6323d1d49d298bd1723b.tar.bz2 cru-55d98d3259e9f3e184ad6323d1d49d298bd1723b.zip |
...
-rw-r--r-- | include/cru/ui/controls/flex_layout.hpp | 15 | ||||
-rw-r--r-- | include/cru/win/native/platform_id.hpp | 4 | ||||
-rw-r--r-- | src/ui/controls/flex_layout.cpp | 27 |
3 files changed, 43 insertions, 3 deletions
diff --git a/include/cru/ui/controls/flex_layout.hpp b/include/cru/ui/controls/flex_layout.hpp index 46c4ea55..128a79b0 100644 --- a/include/cru/ui/controls/flex_layout.hpp +++ b/include/cru/ui/controls/flex_layout.hpp @@ -42,9 +42,22 @@ class FlexLayout : public LayoutControl { void SetContentMainAlign(FlexMainAlignment value) { if (value == GetContentMainAlign()) return; render_object_->SetContentMainAlign(value); - GetWindow()->InvalidateLayout(); + if (const auto window = GetWindow()) window->InvalidateLayout(); } + FlexDirection GetFlexDirection() const { + return render_object_->GetFlexDirection(); + } + + void SetFlexDirection(FlexDirection direction) { + if (direction == GetFlexDirection()) return; + render_object_->SetFlexDirection(direction); + if (const auto window = GetWindow()) window->InvalidateLayout(); + } + + FlexChildLayoutData GetChildLayoutData(Control* control); + void SetChildLayoutData(Control* control, const FlexChildLayoutData& data); + protected: void OnAddChild(Control* child, int position) override; void OnRemoveChild(Control* child, int position) override; diff --git a/include/cru/win/native/platform_id.hpp b/include/cru/win/native/platform_id.hpp index 4b018d51..e1899ad4 100644 --- a/include/cru/win/native/platform_id.hpp +++ b/include/cru/win/native/platform_id.hpp @@ -13,7 +13,7 @@ inline bool IsWindowsResource(NativeResource* resource) { } // namespace cru::platform::native::win -#define CRU_PLATFORMID_IMPLEMENT_WIN \ - std::wstring_view GetPlatformId() const override { \ +#define CRU_PLATFORMID_IMPLEMENT_WIN \ + std::wstring_view GetPlatformId() const override { \ return ::cru::platform::native::win::win_platform_id; \ } 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); } |