mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -05:00
rename AutoSizeLayout to CopySizeLayout
This commit is contained in:
parent
563a44c874
commit
ed588eb9b1
3 changed files with 6 additions and 52 deletions
10
loader/include/Geode/cocos/base_nodes/Layout.hpp
vendored
10
loader/include/Geode/cocos/base_nodes/Layout.hpp
vendored
|
@ -433,23 +433,23 @@ public:
|
||||||
* Basically main use case is for FLAlertLayers (setting the size of the
|
* Basically main use case is for FLAlertLayers (setting the size of the
|
||||||
* background and `m_buttonMenu` based on `m_mainLayer`)
|
* background and `m_buttonMenu` based on `m_mainLayer`)
|
||||||
*/
|
*/
|
||||||
class AutoSizeLayout : public cocos2d::AnchorLayout {
|
class CopySizeLayout : public cocos2d::AnchorLayout {
|
||||||
protected:
|
protected:
|
||||||
cocos2d::CCArray* m_targets;
|
cocos2d::CCArray* m_targets;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static AutoSizeLayout* create();
|
static CopySizeLayout* create();
|
||||||
virtual ~AutoSizeLayout();
|
virtual ~CopySizeLayout();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a target to be automatically resized. Any targets' layouts will
|
* Add a target to be automatically resized. Any targets' layouts will
|
||||||
* also be updated when this layout is updated
|
* 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
|
* Remove a target from being automatically resized
|
||||||
*/
|
*/
|
||||||
AutoSizeLayout* remove(cocos2d::CCNode* target);
|
CopySizeLayout* remove(cocos2d::CCNode* target);
|
||||||
|
|
||||||
void apply(cocos2d::CCNode* in) override;
|
void apply(cocos2d::CCNode* in) override;
|
||||||
cocos2d::CCSize getSizeHint(cocos2d::CCNode* in) const override;
|
cocos2d::CCSize getSizeHint(cocos2d::CCNode* in) const override;
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace geode {
|
||||||
m_mainLayer->setPosition(winSize / 2);
|
m_mainLayer->setPosition(winSize / 2);
|
||||||
m_mainLayer->setContentSize(m_size);
|
m_mainLayer->setContentSize(m_size);
|
||||||
m_mainLayer->setLayout(
|
m_mainLayer->setLayout(
|
||||||
cocos2d::AutoSizeLayout::create()
|
cocos2d::CopySizeLayout::create()
|
||||||
->add(m_buttonMenu)
|
->add(m_buttonMenu)
|
||||||
->add(m_bgSprite)
|
->add(m_bgSprite)
|
||||||
);
|
);
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
Loading…
Reference in a new issue