aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-29 22:09:29 +0800
committercrupest <crupest@outlook.com>2022-01-29 22:09:29 +0800
commit592f3f3f25f00232234399f4c5f51318a3fa49d2 (patch)
tree9ff928062aab8598bbbd00aa243d234e80aa6406 /include/cru
parenta2c2089c8d97b4910d4287c14c82e20d33366c24 (diff)
downloadcru-592f3f3f25f00232234399f4c5f51318a3fa49d2.tar.gz
cru-592f3f3f25f00232234399f4c5f51318a3fa49d2.tar.bz2
cru-592f3f3f25f00232234399f4c5f51318a3fa49d2.zip
...
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/ui/Base.hpp6
-rw-r--r--include/cru/ui/controls/StackLayout.hpp4
-rw-r--r--include/cru/ui/render/StackLayoutRenderObject.hpp14
3 files changed, 22 insertions, 2 deletions
diff --git a/include/cru/ui/Base.hpp b/include/cru/ui/Base.hpp
index db360c07..e99c956f 100644
--- a/include/cru/ui/Base.hpp
+++ b/include/cru/ui/Base.hpp
@@ -62,12 +62,14 @@ 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 Alignment {
Start = internal::align_start,
End = internal::align_end,
Center = internal::align_center,
+ Stretch = internal::align_stretch
};
struct CornerRadius {
@@ -144,7 +146,7 @@ struct FlexChildLayoutData {
};
struct StackChildLayoutData {
- Alignment horizontal = Alignment::Start;
- Alignment vertical = Alignment::Start;
+ std::optional<Alignment> horizontal;
+ std::optional<Alignment> vertical;
};
} // namespace cru::ui
diff --git a/include/cru/ui/controls/StackLayout.hpp b/include/cru/ui/controls/StackLayout.hpp
index 657cadc6..5d90dfda 100644
--- a/include/cru/ui/controls/StackLayout.hpp
+++ b/include/cru/ui/controls/StackLayout.hpp
@@ -1,5 +1,6 @@
#pragma once
#include "LayoutControl.hpp"
+#include "cru/ui/Base.hpp"
namespace cru::ui::controls {
class CRU_UI_API StackLayout : public LayoutControl {
@@ -21,6 +22,9 @@ class CRU_UI_API StackLayout : public LayoutControl {
render::RenderObject* GetRenderObject() const override;
+ const StackChildLayoutData& GetChildLayoutData(Index position);
+ void SetChildLayoutData(Index position, StackChildLayoutData data);
+
private:
std::shared_ptr<render::StackLayoutRenderObject> render_object_;
};
diff --git a/include/cru/ui/render/StackLayoutRenderObject.hpp b/include/cru/ui/render/StackLayoutRenderObject.hpp
index b7b1502c..2f832e55 100644
--- a/include/cru/ui/render/StackLayoutRenderObject.hpp
+++ b/include/cru/ui/render/StackLayoutRenderObject.hpp
@@ -1,5 +1,6 @@
#pragma once
#include "LayoutRenderObject.hpp"
+#include "cru/ui/Base.hpp"
namespace cru::ui::render {
// Measure Logic:
@@ -35,9 +36,22 @@ class CRU_UI_API StackLayoutRenderObject
return u"StackLayoutRenderObject";
}
+ Alignment GetDefaultHorizontalAlignment() const {
+ return default_vertical_alignment_;
+ }
+ void SetDefaultHorizontalAlignment(Alignment alignment);
+ Alignment GetDefaultVerticalAlignment() {
+ return default_horizontal_alignment_;
+ }
+ void SetDefaultVertialAlignment(Alignment alignment);
+
protected:
Size OnMeasureContent(const MeasureRequirement& requirement,
const MeasureSize& preferred_size) override;
void OnLayoutContent(const Rect& content_rect) override;
+
+ private:
+ Alignment default_horizontal_alignment_ = Alignment::Start;
+ Alignment default_vertical_alignment_ = Alignment::Start;
};
} // namespace cru::ui::render