aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/cru/ui/render/FlexLayoutRenderObject.hpp9
-rw-r--r--include/cru/ui/render/LayoutHelper.hpp13
-rw-r--r--include/cru/ui/render/StackLayoutRenderObject.hpp19
3 files changed, 34 insertions, 7 deletions
diff --git a/include/cru/ui/render/FlexLayoutRenderObject.hpp b/include/cru/ui/render/FlexLayoutRenderObject.hpp
index 83d1e268..4b1e079d 100644
--- a/include/cru/ui/render/FlexLayoutRenderObject.hpp
+++ b/include/cru/ui/render/FlexLayoutRenderObject.hpp
@@ -3,8 +3,9 @@
namespace cru::ui::render {
// Measure Logic (v0.1):
-// 1. Layout all children with unspecified(infinate) max main axis length. If
-// max cross axis length of parent is specified, then it is passed to children.
+// Cross axis measure logic is the same as stack layout.
+//
+// 1. Layout all children with unspecified(infinate) max main axis length.
//
// 2. Add up main axis length of children to get total main length.
//
@@ -72,10 +73,6 @@ namespace cru::ui::render {
// (if specified), then coerce the length to the min value but not report error
// and just fill the rest space with blank.
//
-// 5. Result cross axis length is the max cross axis length of all children. If
-// min cross axis length is specified and result length is smaller than it, then
-// result length is coerced to it.
-//
class FlexLayoutRenderObject : public LayoutRenderObject<FlexChildLayoutData> {
public:
FlexLayoutRenderObject() = default;
diff --git a/include/cru/ui/render/LayoutHelper.hpp b/include/cru/ui/render/LayoutHelper.hpp
new file mode 100644
index 00000000..8536c451
--- /dev/null
+++ b/include/cru/ui/render/LayoutHelper.hpp
@@ -0,0 +1,13 @@
+#pragma once
+#include "Base.hpp"
+
+#include "MeasureRequirement.hpp"
+
+namespace cru::ui::render {
+float CalculateAnchorByAlignment(Alignment alignment, float start_point,
+ float content_length, float child_length);
+
+MeasureLength StackLayoutCalculateChildMaxLength(
+ MeasureLength parent_preferred_size, MeasureLength parent_max_size,
+ MeasureLength child_min_size, std::string_view exceeds_message);
+} // namespace cru::ui::render
diff --git a/include/cru/ui/render/StackLayoutRenderObject.hpp b/include/cru/ui/render/StackLayoutRenderObject.hpp
index e89e5346..f6b4ffb7 100644
--- a/include/cru/ui/render/StackLayoutRenderObject.hpp
+++ b/include/cru/ui/render/StackLayoutRenderObject.hpp
@@ -3,7 +3,24 @@
namespace cru::ui::render {
// Measure Logic:
-//
+// Following rules are applied both horizontally and vertically.
+//
+// 1. Measure each children with min size not specified and max size as
+// following rules:
+//
+// 1.1. If parent's preferred size is set and it is not less than child's min
+// size, then it is used as child's max size.
+//
+// 1.2. Or if parent's max size is set, then it is used as child's max size.
+// If it is less than child's min size, then log an warning about that.
+//
+// 2. Result size is children's max size.
+//
+// 3. If preferred size is specified and result size is smaller than it, coerce
+// result size to preferred size.
+//
+// 4. If result size is smaller than min size (if specified), coerce result size
+// to min size.
class StackLayoutRenderObject
: public LayoutRenderObject<StackChildLayoutData> {
public: