add option to ignore invisible children to Layout

This commit is contained in:
HJfod 2023-04-02 14:43:39 +03:00
parent 21173311c1
commit 152f90cf67
2 changed files with 20 additions and 4 deletions
loader
include/Geode/cocos/base_nodes
src/cocos2d-ext

View file

@ -23,7 +23,9 @@ class CCNode;
*/
class GEODE_DLL Layout : public CCObject {
protected:
static CCArray* getNodesToPosition(CCNode* forNode);
CCArray* getNodesToPosition(CCNode* forNode);
bool m_ignoreInvisibleChildren = false;
public:
/**
@ -35,6 +37,9 @@ public:
*/
virtual void apply(CCNode* on) = 0;
void ignoreInvisibleChildren(bool ignore);
bool isIgnoreInvisibleChildren() const;
virtual ~Layout() = default;
};

View file

@ -51,10 +51,21 @@ bool CCNode::hasAncestor(CCNode* ancestor) {
}
CCArray* Layout::getNodesToPosition(CCNode* on) {
if (!on->getChildren()) {
return CCArray::create();
auto arr = CCArray::create();
for (auto child : CCArrayExt<CCNode>(on->getChildren())) {
if (!m_ignoreInvisibleChildren || child->isVisible()) {
arr->addObject(child);
}
}
return on->getChildren()->shallowCopy();
return arr;
}
void Layout::ignoreInvisibleChildren(bool ignore) {
m_ignoreInvisibleChildren = ignore;
}
bool Layout::isIgnoreInvisibleChildren() const {
return m_ignoreInvisibleChildren;
}
static AxisLayoutOptions const* axisOpts(CCNode* node) {