rename AutoSizeLayout to CopySizeLayout

This commit is contained in:
HJfod 2024-01-31 23:36:00 +02:00
parent 563a44c874
commit ed588eb9b1
3 changed files with 6 additions and 52 deletions

View file

@ -433,23 +433,23 @@ public:
* Basically main use case is for FLAlertLayers (setting the size of the
* background and `m_buttonMenu` based on `m_mainLayer`)
*/
class AutoSizeLayout : public cocos2d::AnchorLayout {
class CopySizeLayout : public cocos2d::AnchorLayout {
protected:
cocos2d::CCArray* m_targets;
public:
static AutoSizeLayout* create();
virtual ~AutoSizeLayout();
static CopySizeLayout* create();
virtual ~CopySizeLayout();
/**
* Add a target to be automatically resized. Any targets' layouts will
* also be updated when this layout is updated
*/
AutoSizeLayout* add(cocos2d::CCNode* target);
CopySizeLayout* add(cocos2d::CCNode* target);
/**
* Remove a target from being automatically resized
*/
AutoSizeLayout* remove(cocos2d::CCNode* target);
CopySizeLayout* remove(cocos2d::CCNode* target);
void apply(cocos2d::CCNode* in) override;
cocos2d::CCSize getSizeHint(cocos2d::CCNode* in) const override;

View file

@ -53,7 +53,7 @@ namespace geode {
m_mainLayer->setPosition(winSize / 2);
m_mainLayer->setContentSize(m_size);
m_mainLayer->setLayout(
cocos2d::AutoSizeLayout::create()
cocos2d::CopySizeLayout::create()
->add(m_buttonMenu)
->add(m_bgSprite)
);

View file

@ -1,46 +0,0 @@
#include <cocos2d.h>
#include <Geode/utils/cocos.hpp>
#include <Geode/utils/ranges.hpp>
#include <Geode/loader/Log.hpp>
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
#include <Geode/binding/CCMenuItemToggler.hpp>
using namespace geode::prelude;
AutoSizeLayout* AutoSizeLayout::create() {
auto ret = new AutoSizeLayout();
ret->m_targets = CCArray::create();
ret->m_targets->retain();
ret->autorelease();
return ret;
}
AutoSizeLayout::~AutoSizeLayout() {
m_targets->release();
}
AutoSizeLayout* AutoSizeLayout::add(CCNode* target) {
m_targets->addObject(target);
return this;
}
AutoSizeLayout* AutoSizeLayout::remove(CCNode* target) {
m_targets->removeObject(target);
return this;
}
void AutoSizeLayout::apply(CCNode* in) {
AnchorLayout::apply(in);
for (auto& node : CCArrayExt<CCNode*>(m_targets)) {
// Prevent accidental infinite loop
if (node == in) continue;
node->ignoreAnchorPointForPosition(false);
node->setContentSize(in->getContentSize());
node->setPosition(in->getContentSize() / 2);
node->updateLayout();
}
}
CCSize AutoSizeLayout::getSizeHint(CCNode* in) const {
return in->getContentSize();
}