Skip to content

Commit 493629a

Browse files
authored
(v5) Improve Layout::ignoreInvisibleChilren usability (#1567)
Made it virtual so it can be used cleanly for layout creation. Also made it return this instead of void and made the ignore param true by default. About time.
1 parent c2b933e commit 493629a

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

loader/include/Geode/ui/Layout.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ class GEODE_DLL Layout : public cocos2d::CCObject {
3838
*/
3939
virtual cocos2d::CCSize getSizeHint(cocos2d::CCNode* on) const = 0;
4040

41-
void ignoreInvisibleChildren(bool ignore);
41+
/**
42+
* If true, the layout will not take into account invisible children when creating gaps or
43+
* calculating content sizes
44+
*/
45+
Layout* ignoreInvisibleChildren(bool ignore = true);
4246
bool isIgnoreInvisibleChildren() const;
4347

4448
virtual ~Layout() = default;
@@ -307,6 +311,11 @@ class GEODE_DLL AxisLayout : public Layout {
307311
* Set the default minimum/maximum scales for nodes in the layout
308312
*/
309313
AxisLayout* setDefaultScaleLimits(float min, float max);
314+
/**
315+
* If true, the layout will not take into account invisible children when creating gaps or
316+
* calculating content sizes
317+
*/
318+
AxisLayout* ignoreInvisibleChildren(bool ignore = true);
310319
};
311320

312321
/**

loader/include/Geode/ui/SimpleAxisLayout.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ class GEODE_DLL SimpleAxisLayout : public Layout {
183183
* The default is set to 2.0f
184184
*/
185185
SimpleAxisLayout* setMaxRelativeScale(std::optional<float> scale);
186+
/**
187+
* If true, the layout will not take into account invisible children when creating gaps or
188+
* calculating content sizes
189+
*/
190+
SimpleAxisLayout* ignoreInvisibleChildren(bool ignore = true);
186191

187192
Axis getAxis() const;
188193
AxisScaling getMainAxisScaling() const;

loader/src/cocos2d-ext/AxisLayout.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,12 @@ AxisLayout* AxisLayout::setDefaultScaleLimits(float min, float max) {
930930
return this;
931931
}
932932

933+
AxisLayout* AxisLayout::ignoreInvisibleChildren(bool ignore) {
934+
Layout::ignoreInvisibleChildren(ignore);
935+
936+
return this;
937+
}
938+
933939
AxisLayout::AxisLayout(Axis axis) : m_impl(std::make_unique<Impl>()) {
934940
m_impl->m_axis = axis;
935941
}

loader/src/cocos2d-ext/Layout.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ CCArray* Layout::getNodesToPosition(CCNode* on) const {
9090
return arr;
9191
}
9292

93-
void Layout::ignoreInvisibleChildren(bool ignore) {
93+
Layout* Layout::ignoreInvisibleChildren(bool ignore) {
9494
m_ignoreInvisibleChildren = ignore;
95+
return this;
9596
}
9697

9798
bool Layout::isIgnoreInvisibleChildren() const {

loader/src/cocos2d-ext/SimpleAxisLayout.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,11 @@ SimpleAxisLayout* SimpleAxisLayout::setMaxRelativeScale(std::optional<float> sca
846846
return this;
847847
}
848848

849+
SimpleAxisLayout* SimpleAxisLayout::ignoreInvisibleChildren(bool ignore) {
850+
Layout::ignoreInvisibleChildren(ignore);
851+
return this;
852+
}
853+
849854
Axis SimpleAxisLayout::getAxis() const {
850855
return m_impl->m_axis;
851856
}

0 commit comments

Comments
 (0)