From e06b9070d082ce18fcf0754c09ef87f295df6c5a Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Fri, 16 Feb 2024 16:30:31 +0200 Subject: [PATCH] add `CCNode::setContentWidth` etc. --- .../include/Geode/cocos/base_nodes/CCNode.h | 5 +++++ loader/src/cocos2d-ext/Layout.cpp | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/loader/include/Geode/cocos/base_nodes/CCNode.h b/loader/include/Geode/cocos/base_nodes/CCNode.h index 68b3559e..718060b1 100644 --- a/loader/include/Geode/cocos/base_nodes/CCNode.h +++ b/loader/include/Geode/cocos/base_nodes/CCNode.h @@ -1022,6 +1022,11 @@ public: */ GEODE_DLL void swapChildIndices(CCNode* first, CCNode* second); + GEODE_DLL void setContentWidth(float width); + GEODE_DLL void setContentHeight(float width); + GEODE_DLL float getContentWidth() const; + GEODE_DLL float getContentHeight() const; + template geode::EventListenerProtocol* addEventListener( std::string const& id, diff --git a/loader/src/cocos2d-ext/Layout.cpp b/loader/src/cocos2d-ext/Layout.cpp index b1a0a037..e46c66a2 100644 --- a/loader/src/cocos2d-ext/Layout.cpp +++ b/loader/src/cocos2d-ext/Layout.cpp @@ -47,6 +47,25 @@ bool CCNode::hasAncestor(CCNode* ancestor) { return false; } +// these use setContentSize and getContentSize because they're virtuals and +// some node may override those for wacky behaviour + +void CCNode::setContentWidth(float width) { + this->setContentSize({ width, m_obContentSize.height }); +} + +void CCNode::setContentHeight(float height) { + this->setContentSize({ m_obContentSize.width, height }); +} + +float CCNode::getContentWidth() const { + return this->getContentSize().width; +} + +float CCNode::getContentHeight() const { + return this->getContentSize().height; +} + CCArray* Layout::getNodesToPosition(CCNode* on) const { auto arr = CCArray::create(); for (auto child : CCArrayExt(on->getChildren())) {