aboutsummaryrefslogtreecommitdiff
path: root/include/cru/ui
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/ui')
-rw-r--r--include/cru/ui/controls/flex_layout.hpp22
-rw-r--r--include/cru/ui/render/flex_layout_render_object.hpp39
-rw-r--r--include/cru/ui/ui_manager.hpp1
-rw-r--r--include/cru/ui/window.hpp10
4 files changed, 61 insertions, 11 deletions
diff --git a/include/cru/ui/controls/flex_layout.hpp b/include/cru/ui/controls/flex_layout.hpp
index 7422bc05..46c4ea55 100644
--- a/include/cru/ui/controls/flex_layout.hpp
+++ b/include/cru/ui/controls/flex_layout.hpp
@@ -1,13 +1,17 @@
#pragma once
#include "../layout_control.hpp"
-#include <memory>
+#include "../render/flex_layout_render_object.hpp"
+#include "../window.hpp"
-namespace cru::ui::render {
-class FlexLayoutRenderObject;
-}
+#include <memory>
namespace cru::ui::controls {
+// import these basic entities
+using render::FlexChildLayoutData;
+using render::FlexCrossAlignment;
+using render::FlexDirection;
+using render::FlexMainAlignment;
class FlexLayout : public LayoutControl {
public:
@@ -31,6 +35,16 @@ class FlexLayout : public LayoutControl {
render::RenderObject* GetRenderObject() const override;
+ FlexMainAlignment GetContentMainAlign() const {
+ return render_object_->GetContentMainAlign();
+ }
+
+ void SetContentMainAlign(FlexMainAlignment value) {
+ if (value == GetContentMainAlign()) return;
+ render_object_->SetContentMainAlign(value);
+ GetWindow()->InvalidateLayout();
+ }
+
protected:
void OnAddChild(Control* child, int position) override;
void OnRemoveChild(Control* child, int position) override;
diff --git a/include/cru/ui/render/flex_layout_render_object.hpp b/include/cru/ui/render/flex_layout_render_object.hpp
index 99ec1247..8d881239 100644
--- a/include/cru/ui/render/flex_layout_render_object.hpp
+++ b/include/cru/ui/render/flex_layout_render_object.hpp
@@ -11,13 +11,32 @@ enum class FlexDirection {
VertivalReverse
};
-enum class Alignment { Start, End, Center };
+namespace internal {
+constexpr int align_start = 0;
+constexpr int align_end = align_start + 1;
+constexpr int align_center = align_end + 1;
+//constexpr int align_stretch = align_center + 1;
+} // namespace internal
+
+enum class FlexMainAlignment {
+ Start = internal::align_start,
+ End = internal::align_end,
+ Center = internal::align_center
+};
+enum class FlexCrossAlignment {
+ Start = internal::align_start,
+ End = internal::align_end,
+ Center = internal::align_center,
+// Stretch = internal::align_stretch
+};
struct FlexChildLayoutData {
- std::optional<float> flex_basis; // nullopt stands for content
+ // nullopt stands for looking at my content
+ std::optional<float> flex_basis = std::nullopt;
float flex_grow = 0;
float flex_shrink = 0;
- Alignment alignment = Alignment::Center;
+ // nullopt stands for looking at parent's setting
+ std::optional<FlexCrossAlignment> cross_alignment = std::nullopt;
};
class FlexLayoutRenderObject : public RenderObject {
@@ -33,8 +52,15 @@ class FlexLayoutRenderObject : public RenderObject {
FlexDirection GetFlexDirection() const { return direction_; }
void SetFlexDirection(FlexDirection direction) { direction_ = direction; }
- Alignment GetContentMainAlign() const { return content_main_align_; }
- void SetContentMainAlign(Alignment align) { content_main_align_ = align; }
+ FlexMainAlignment GetContentMainAlign() const { return content_main_align_; }
+ void SetContentMainAlign(FlexMainAlignment align) {
+ content_main_align_ = align;
+ }
+
+ FlexCrossAlignment GetItemCrossAlign() const { return item_cross_align_; }
+ void SetItemCrossAlign(FlexCrossAlignment align) {
+ item_cross_align_ = align;
+ }
FlexChildLayoutData* GetChildLayoutData(int position);
@@ -51,7 +77,8 @@ class FlexLayoutRenderObject : public RenderObject {
private:
FlexDirection direction_ = FlexDirection::Horizontal;
- Alignment content_main_align_ = Alignment::Start;
+ FlexMainAlignment content_main_align_ = FlexMainAlignment::Start;
+ FlexCrossAlignment item_cross_align_ = FlexCrossAlignment::Center;
std::vector<FlexChildLayoutData> child_layout_data_{};
};
} // namespace cru::ui::render
diff --git a/include/cru/ui/ui_manager.hpp b/include/cru/ui/ui_manager.hpp
index 2dc9cf6b..f3f78722 100644
--- a/include/cru/ui/ui_manager.hpp
+++ b/include/cru/ui/ui_manager.hpp
@@ -9,6 +9,7 @@ struct IFontDescriptor;
} // namespace cru::platform
namespace cru::ui {
+//TODO: Make this theme resource.
class PredefineResources : public Object {
public:
PredefineResources();
diff --git a/include/cru/ui/window.hpp b/include/cru/ui/window.hpp
index 4bc0e41d..e175b234 100644
--- a/include/cru/ui/window.hpp
+++ b/include/cru/ui/window.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "content_control.hpp"
+#include "cru/common/self_resolvable.hpp"
#include "cru/platform/native/native_event.hpp"
#include "event/ui_event.hpp"
@@ -16,7 +17,7 @@ namespace render {
class WindowRenderObject;
}
-class Window final : public ContentControl {
+class Window final : public ContentControl, public SelfResovable<Window> {
public:
static constexpr auto control_type = L"Window";
@@ -46,6 +47,11 @@ class Window final : public ContentControl {
Control* GetMouseHoverControl() const { return mouse_hover_control_; }
+ //*************** region: layout ***************
+ void Relayout();
+
+ void InvalidateLayout();
+
//*************** region: focus ***************
// Request focus for specified control.
@@ -93,5 +99,7 @@ class Window final : public ContentControl {
Control* mouse_hover_control_;
Control* focus_control_; // "focus_control_" can't be nullptr
+
+ bool need_layout_ = false;
};
} // namespace cru::ui