mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -05:00
make Layout inherit from CCObject
This commit is contained in:
parent
7a05c4984f
commit
81472c9ab5
3 changed files with 19 additions and 8 deletions
|
@ -11,6 +11,9 @@ NS_CC_BEGIN
|
|||
|
||||
class CCNode;
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4275)
|
||||
|
||||
/**
|
||||
* Layouts automatically handle the positioning of nodes. Use CCNode::setLayout
|
||||
* to apply a layout to a node, and then use CCNode::updateLayout to apply
|
||||
|
@ -18,7 +21,7 @@ class CCNode;
|
|||
* RowLayout, ColumnLayout, and GridLayout, but if you need a different kind
|
||||
* of layout you can inherit from the Layout class.
|
||||
*/
|
||||
class GEODE_DLL Layout {
|
||||
class GEODE_DLL Layout : public CCObject {
|
||||
protected:
|
||||
static CCArray* getNodesToPosition(CCNode* forNode);
|
||||
|
||||
|
@ -349,4 +352,6 @@ public:
|
|||
static ColumnLayout* create();
|
||||
};
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -825,7 +825,9 @@ AxisLayout* AxisLayout::setGrowCrossAxis(bool shrink) {
|
|||
}
|
||||
|
||||
AxisLayout* AxisLayout::create(Axis axis) {
|
||||
return new AxisLayout(axis);
|
||||
auto ret = new AxisLayout(axis);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// RowLayout
|
||||
|
@ -833,7 +835,9 @@ AxisLayout* AxisLayout::create(Axis axis) {
|
|||
RowLayout::RowLayout() : AxisLayout(Axis::Row) {}
|
||||
|
||||
RowLayout* RowLayout::create() {
|
||||
return new RowLayout();
|
||||
auto ret = new RowLayout();
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ColumnLayout
|
||||
|
@ -841,7 +845,9 @@ RowLayout* RowLayout::create() {
|
|||
ColumnLayout::ColumnLayout() : AxisLayout(Axis::Column) {}
|
||||
|
||||
ColumnLayout* ColumnLayout::create() {
|
||||
return new ColumnLayout();
|
||||
auto ret = new ColumnLayout();
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// AxisLayoutOptions
|
||||
|
|
|
@ -19,7 +19,7 @@ private:
|
|||
FieldContainer* m_fieldContainer;
|
||||
Ref<cocos2d::CCObject> m_userObject;
|
||||
std::string m_id = "";
|
||||
std::unique_ptr<Layout> m_layout = nullptr;
|
||||
Ref<Layout> m_layout = nullptr;
|
||||
std::unique_ptr<LayoutOptions> m_layoutOptions = nullptr;
|
||||
std::unordered_map<std::string, std::any> m_attributes;
|
||||
|
||||
|
@ -135,14 +135,14 @@ void CCNode::setLayout(Layout* layout, bool apply, bool respectAnchor) {
|
|||
}
|
||||
this->ignoreAnchorPointForPosition(false);
|
||||
}
|
||||
GeodeNodeMetadata::set(this)->m_layout.reset(layout);
|
||||
GeodeNodeMetadata::set(this)->m_layout = layout;
|
||||
if (apply) {
|
||||
this->updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
Layout* CCNode::getLayout() {
|
||||
return GeodeNodeMetadata::set(this)->m_layout.get();
|
||||
return GeodeNodeMetadata::set(this)->m_layout.data();
|
||||
}
|
||||
|
||||
void CCNode::setLayoutOptions(LayoutOptions* options, bool apply) {
|
||||
|
@ -160,7 +160,7 @@ void CCNode::updateLayout(bool updateChildOrder) {
|
|||
if (updateChildOrder) {
|
||||
this->sortAllChildren();
|
||||
}
|
||||
if (auto layout = GeodeNodeMetadata::set(this)->m_layout.get()) {
|
||||
if (auto layout = GeodeNodeMetadata::set(this)->m_layout.data()) {
|
||||
layout->apply(this);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue