Skip to content

Commit 0c80db6

Browse files
committed
make AxisScaling::grow shrink to initial size if needed
1 parent 665a000 commit 0c80db6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

loader/src/cocos2d-ext/SimpleAxisLayout.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ class SimpleAxisLayout::Impl {
6161
std::optional<float> m_maxRelativeScale = 2.f;
6262
SimpleAxisLayout* m_layout = nullptr;
6363

64+
std::optional<float> m_minMainAxis;
65+
std::optional<float> m_minCrossAxis;
66+
// max sizes are currently unused, max layout size is planned
67+
std::optional<float> m_maxMainAxis;
68+
std::optional<float> m_maxCrossAxis;
69+
6470
std::unordered_map<CCNode*, float> m_originalScalesPerNode;
6571
std::unordered_map<CCNode*, float> m_relativeScalesPerNode;
6672

@@ -227,8 +233,9 @@ std::unordered_map<CCNode*, float> SimpleAxisLayout::Impl::calculateCrossScaling
227233

228234
switch (m_crossAxisScaling) {
229235
case AxisScaling::Grow:
236+
if (m_minCrossAxis == std::nullopt) m_minCrossAxis = layoutWidth;
230237
// grow the layout to fit the widest node
231-
if (maxWidth > layoutWidth) layoutWidth = maxWidth;
238+
layoutWidth = std::min(m_minCrossAxis.value(), maxWidth);
232239
break;
233240
case AxisScaling::Fit:
234241
// fit the layout to the widest node
@@ -286,8 +293,9 @@ std::unordered_map<CCNode*, float> SimpleAxisLayout::Impl::calculateMainScaling(
286293

287294
switch (m_mainAxisScaling) {
288295
case AxisScaling::Grow:
296+
if (m_minMainAxis == std::nullopt) m_minMainAxis = layoutHeight;
289297
// grow the layout to fit all the nodes
290-
if (totalHeight > layoutHeight) layoutHeight = totalHeight;
298+
layoutHeight = std::min(m_minMainAxis.value(), totalHeight);
291299
break;
292300
case AxisScaling::Fit:
293301
// fit the layout to all the nodes
@@ -503,7 +511,8 @@ void SimpleAxisLayout::Impl::applyCrossPositioning(CCNode* layout, std::vector<C
503511
// reapply grow/fit since main scaling may have changed the max width
504512
switch (m_crossAxisScaling) {
505513
case AxisScaling::Grow:
506-
if (maxWidth > layoutWidth) layoutWidth = maxWidth;
514+
if (m_minCrossAxis == std::nullopt) m_minCrossAxis = layoutWidth;
515+
layoutWidth = std::min(m_minCrossAxis.value(), maxWidth);
507516
break;
508517
case AxisScaling::Fit:
509518
layoutWidth = maxWidth;

0 commit comments

Comments
 (0)