aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/cru/ui/controls/flex_layout.hpp15
-rw-r--r--include/cru/win/native/platform_id.hpp4
-rw-r--r--src/ui/controls/flex_layout.cpp27
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);
}