2022-10-10 13:58:47 -04:00
|
|
|
#pragma once
|
|
|
|
|
2022-10-22 15:10:36 -04:00
|
|
|
#include "../include/ccMacros.h"
|
|
|
|
#include "../cocoa/CCAffineTransform.h"
|
|
|
|
#include "../cocoa/CCArray.h"
|
2022-10-10 13:58:47 -04:00
|
|
|
#include <Geode/platform/platform.hpp>
|
|
|
|
#include <optional>
|
2024-05-10 06:15:18 -04:00
|
|
|
#include <memory>
|
2022-10-10 13:58:47 -04:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
class CCNode;
|
|
|
|
|
2023-03-19 09:02:49 -04:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable: 4275)
|
|
|
|
|
2022-10-10 13:58:47 -04:00
|
|
|
/**
|
|
|
|
* Layouts automatically handle the positioning of nodes. Use CCNode::setLayout
|
|
|
|
* to apply a layout to a node, and then use CCNode::updateLayout to apply
|
|
|
|
* the layout's positioning. Geode comes with a few default layouts like
|
|
|
|
* RowLayout, ColumnLayout, and GridLayout, but if you need a different kind
|
|
|
|
* of layout you can inherit from the Layout class.
|
|
|
|
*/
|
2023-03-19 09:02:49 -04:00
|
|
|
class GEODE_DLL Layout : public CCObject {
|
2023-02-02 10:08:13 -05:00
|
|
|
protected:
|
2023-04-04 10:44:49 -04:00
|
|
|
CCArray* getNodesToPosition(CCNode* forNode) const;
|
2023-04-02 07:43:39 -04:00
|
|
|
|
|
|
|
bool m_ignoreInvisibleChildren = false;
|
2023-02-02 10:08:13 -05:00
|
|
|
|
2022-10-10 13:58:47 -04:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Automatically apply the layout's positioning on a set of nodes
|
2023-02-02 10:08:13 -05:00
|
|
|
* @param on Node to apply the layout on. Position's the node's children
|
|
|
|
* according to the layout. The content size of the node should be
|
|
|
|
* respected as a boundary the layout shouldn't overflow. The node may be
|
2023-02-15 09:02:56 -05:00
|
|
|
* rescaled to better fit its contents
|
2022-10-10 13:58:47 -04:00
|
|
|
*/
|
2023-02-02 10:08:13 -05:00
|
|
|
virtual void apply(CCNode* on) = 0;
|
2023-02-06 14:36:08 -05:00
|
|
|
|
2023-04-04 10:44:49 -04:00
|
|
|
/**
|
|
|
|
* Get how much space this layout would like to take up for a given target
|
|
|
|
*/
|
|
|
|
virtual CCSize getSizeHint(CCNode* on) const = 0;
|
|
|
|
|
2023-04-02 07:43:39 -04:00
|
|
|
void ignoreInvisibleChildren(bool ignore);
|
|
|
|
bool isIgnoreInvisibleChildren() const;
|
|
|
|
|
2023-02-06 14:36:08 -05:00
|
|
|
virtual ~Layout() = default;
|
|
|
|
};
|
|
|
|
|
2024-02-10 06:09:11 -05:00
|
|
|
class GEODE_DLL LayoutOptions : public CCObject {
|
2023-02-06 14:36:08 -05:00
|
|
|
public:
|
|
|
|
virtual ~LayoutOptions() = default;
|
2022-10-10 13:58:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2023-02-15 09:02:56 -05:00
|
|
|
* The direction of an AxisLayout
|
2022-10-10 13:58:47 -04:00
|
|
|
*/
|
2023-02-06 14:36:08 -05:00
|
|
|
enum class Axis {
|
|
|
|
Row,
|
|
|
|
Column,
|
|
|
|
};
|
|
|
|
|
2022-10-10 13:58:47 -04:00
|
|
|
/**
|
2023-02-15 09:02:56 -05:00
|
|
|
* Specifies the alignment of something in an AxisLayout
|
2022-10-10 13:58:47 -04:00
|
|
|
*/
|
2023-02-06 14:36:08 -05:00
|
|
|
enum class AxisAlignment {
|
|
|
|
// Align items to the start
|
|
|
|
// |ooo......|
|
|
|
|
Start,
|
|
|
|
// All items are centered
|
|
|
|
// |...ooo...|
|
2022-10-10 13:58:47 -04:00
|
|
|
Center,
|
2023-02-06 14:36:08 -05:00
|
|
|
// Align items to the end
|
|
|
|
// |......ooo|
|
2022-10-10 13:58:47 -04:00
|
|
|
End,
|
2023-02-06 14:36:08 -05:00
|
|
|
// Each item gets the same portion from the layout (disregards gap)
|
|
|
|
// |.o..o..o.|
|
|
|
|
Even,
|
2022-10-10 13:58:47 -04:00
|
|
|
};
|
|
|
|
|
2023-02-15 09:02:56 -05:00
|
|
|
constexpr float AXISLAYOUT_DEFAULT_MIN_SCALE = 0.65f;
|
|
|
|
constexpr int AXISLAYOUT_DEFAULT_PRIORITY = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Options for controlling the behaviour of individual nodes in an AxisLayout
|
|
|
|
* @example
|
|
|
|
* auto node = CCNode::create();
|
|
|
|
* // this node will have 10 units of spacing between it and the next one
|
|
|
|
* node->setLayoutOptions(
|
|
|
|
* AxisLayoutOptions::create()
|
|
|
|
* ->setNextGap(10.f)
|
|
|
|
* );
|
|
|
|
* someNodeWithALayout->addChild(node);
|
|
|
|
*/
|
2023-02-13 15:09:16 -05:00
|
|
|
class GEODE_DLL AxisLayoutOptions : public LayoutOptions {
|
|
|
|
protected:
|
2024-05-09 08:18:18 -04:00
|
|
|
class Impl;
|
|
|
|
|
|
|
|
std::unique_ptr<Impl> m_impl;
|
|
|
|
|
|
|
|
AxisLayoutOptions();
|
2023-02-13 15:09:16 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
static AxisLayoutOptions* create();
|
|
|
|
|
2024-05-09 08:18:18 -04:00
|
|
|
virtual ~AxisLayoutOptions();
|
|
|
|
|
2023-02-15 09:02:56 -05:00
|
|
|
std::optional<bool> getAutoScale() const;
|
2024-05-09 08:18:18 -04:00
|
|
|
// @note Use hasExplicitMaxScale to know if the default scale has been overwritten
|
2023-02-15 09:02:56 -05:00
|
|
|
float getMaxScale() const;
|
2024-05-09 08:18:18 -04:00
|
|
|
// @note Use hasExplicitMinScale to know if the default scale has been overwritten
|
2023-02-15 09:02:56 -05:00
|
|
|
float getMinScale() const;
|
2024-05-09 08:18:18 -04:00
|
|
|
bool hasExplicitMaxScale() const;
|
|
|
|
bool hasExplicitMinScale() const;
|
2023-02-15 09:02:56 -05:00
|
|
|
float getRelativeScale() const;
|
2023-02-14 14:54:45 -05:00
|
|
|
std::optional<float> getLength() const;
|
2023-02-15 09:02:56 -05:00
|
|
|
std::optional<float> getPrevGap() const;
|
|
|
|
std::optional<float> getNextGap() const;
|
2023-02-14 14:54:45 -05:00
|
|
|
bool getBreakLine() const;
|
2023-02-15 09:02:56 -05:00
|
|
|
bool getSameLine() const;
|
|
|
|
int getScalePriority() const;
|
2024-05-09 08:18:18 -04:00
|
|
|
std::optional<AxisAlignment> getCrossAxisAlignment() const;
|
2023-02-13 15:09:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the maximum scale this node can be if it's contained in an
|
|
|
|
* auto-scaled layout. Default is 1
|
|
|
|
*/
|
2024-05-09 08:18:18 -04:00
|
|
|
[[deprecated("Use AxisLayoutOptions::setScaleLimits")]]
|
2023-02-13 15:09:16 -05:00
|
|
|
AxisLayoutOptions* setMaxScale(float scale);
|
|
|
|
|
|
|
|
/**
|
2023-02-15 09:02:56 -05:00
|
|
|
* Set the minimum scale this node can be if it's contained in an
|
|
|
|
* auto-scaled layout. Default is AXISLAYOUT_DEFAULT_MIN_SCALE
|
|
|
|
*/
|
2024-05-09 08:18:18 -04:00
|
|
|
[[deprecated("Use AxisLayoutOptions::setScaleLimits")]]
|
2023-02-15 09:02:56 -05:00
|
|
|
AxisLayoutOptions* setMinScale(float scale);
|
|
|
|
|
2024-05-09 08:18:18 -04:00
|
|
|
/**
|
|
|
|
* Set the limits to what the node can be scaled to. Passing `std::nullopt`
|
|
|
|
* uses the parent layout's default min / max scales
|
|
|
|
*/
|
|
|
|
AxisLayoutOptions* setScaleLimits(std::optional<float> min, std::optional<float> max);
|
|
|
|
|
2023-02-15 09:02:56 -05:00
|
|
|
/**
|
|
|
|
* Set the relative scale of this node compared to other nodes if it's
|
|
|
|
* contained in an auto-scaled layout. Default is 1
|
|
|
|
*/
|
|
|
|
AxisLayoutOptions* setRelativeScale(float scale);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set auto-scaling for this node, overriding the layout's auto-scale
|
|
|
|
* setting. If nullopt, the layout's auto-scale options will be used
|
2023-02-13 15:09:16 -05:00
|
|
|
*/
|
2023-02-15 09:02:56 -05:00
|
|
|
AxisLayoutOptions* setAutoScale(std::optional<bool> enabled);
|
2023-02-13 15:09:16 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an absolute length for this node. If nullopt, the length will be
|
|
|
|
* dynamically calculated based on content size
|
|
|
|
*/
|
|
|
|
AxisLayoutOptions* setLength(std::optional<float> length);
|
2023-02-14 14:54:45 -05:00
|
|
|
|
2023-02-15 09:02:56 -05:00
|
|
|
/**
|
|
|
|
* Override the default gap in the layout between this node and the
|
|
|
|
* previous one. If nullopt, the default gap of the layout will be used
|
|
|
|
*/
|
|
|
|
AxisLayoutOptions* setPrevGap(std::optional<float> gap);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the default gap in the layout between this node and the next
|
|
|
|
* one. If nullopt, the default gap of the layout will be used
|
|
|
|
*/
|
|
|
|
AxisLayoutOptions* setNextGap(std::optional<float> gap);
|
|
|
|
|
2023-02-14 14:54:45 -05:00
|
|
|
/**
|
|
|
|
* If enabled, the node will always cause a growable axis layout to break
|
|
|
|
* into a new line even if the current line could've fit the next node
|
|
|
|
*/
|
|
|
|
AxisLayoutOptions* setBreakLine(bool enable);
|
2023-02-15 09:02:56 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If enabled, the node will be forced to be on the same line as the
|
|
|
|
* previous node even if doing this would overflow
|
|
|
|
*/
|
|
|
|
AxisLayoutOptions* setSameLine(bool enable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the scale priority of this node. Nodes with higher priority will be
|
|
|
|
* scaled down first before nodes with lower priority when an auto-scaled
|
|
|
|
* layout attempts to fit its contents. Default is
|
|
|
|
* AXISLAYOUT_DEFAULT_PRIORITY
|
|
|
|
* @note For optimal performance, the priorities should all be close to
|
|
|
|
* each other with no gaps
|
|
|
|
*/
|
|
|
|
AxisLayoutOptions* setScalePriority(int priority);
|
2024-05-09 08:18:18 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the cross axis alignment for this node in the layout
|
|
|
|
*/
|
|
|
|
AxisLayoutOptions* setCrossAxisAlignment(std::optional<AxisAlignment> alignment);
|
2023-02-13 15:09:16 -05:00
|
|
|
};
|
|
|
|
|
2023-02-06 14:36:08 -05:00
|
|
|
/**
|
2023-02-15 09:02:56 -05:00
|
|
|
* A multi-purpose dynamic layout for arranging nodes along an axis. Can be
|
|
|
|
* used to arrange nodes in a single line, a grid, or a flex layout. The
|
|
|
|
* RowLayout and ColumnLayout classes function as simple thin wrappers over
|
|
|
|
* AxisLayout. The positioning of individual nodes in the layout can be
|
|
|
|
* further controlled using AxisLayoutOptions
|
|
|
|
* @warning Calculating layouts can get increasingly expensive for large
|
|
|
|
* amounts of child nodes being fit into a small space - while this should
|
|
|
|
* never prove a real performance concern as most layouts only have a few
|
|
|
|
* hundred children at the very most, be aware that you probably shouldn't
|
|
|
|
* call CCNode::updateLayout every frame for a menu with thousands of children
|
|
|
|
* @example
|
|
|
|
* auto menu = CCMenu::create();
|
|
|
|
* // The menu's children will be arranged horizontally, unless they overflow
|
|
|
|
* // the content size width in which case a new line will be inserted and
|
|
|
|
* // aligned to the left. The menu automatically will automatically grow in
|
|
|
|
* // height to fit all the rows
|
|
|
|
* menu->setLayout(
|
|
|
|
* RowLayout::create()
|
|
|
|
* ->setGap(10.f)
|
|
|
|
* ->setGrowCrossAxis(true)
|
|
|
|
* ->setAxisAlignment(AxisAlignment::Start)
|
|
|
|
* );
|
|
|
|
* menu->setContentSize({ 200.f, 0.f });
|
|
|
|
* menu->addChild(...);
|
|
|
|
* menu->updateLayout();
|
2023-02-06 14:36:08 -05:00
|
|
|
*/
|
2023-02-04 08:58:10 -05:00
|
|
|
class GEODE_DLL AxisLayout : public Layout {
|
2022-10-10 13:58:47 -04:00
|
|
|
protected:
|
2024-05-09 08:18:18 -04:00
|
|
|
class Impl;
|
|
|
|
|
|
|
|
std::unique_ptr<Impl> m_impl;
|
2022-10-10 13:58:47 -04:00
|
|
|
|
2023-02-04 08:58:10 -05:00
|
|
|
AxisLayout(Axis);
|
|
|
|
|
2022-10-10 13:58:47 -04:00
|
|
|
public:
|
2023-02-11 10:50:14 -05:00
|
|
|
/**
|
|
|
|
* Create a new AxisLayout. Note that this class is not automatically
|
|
|
|
* managed by default, so you must assign it to a CCNode or manually
|
|
|
|
* manage the memory yourself. See the chainable setters on AxisLayout for
|
|
|
|
* what options you can customize for the layout
|
|
|
|
* @param axis The direction of the layout
|
|
|
|
* @note For convenience, you can use the RowLayout and ColumnLayout
|
|
|
|
* classes, which are just thin wrappers over AxisLayout
|
|
|
|
* @returns Created AxisLayout
|
|
|
|
*/
|
|
|
|
static AxisLayout* create(Axis axis = Axis::Row);
|
|
|
|
|
2024-05-09 08:18:18 -04:00
|
|
|
virtual ~AxisLayout();
|
|
|
|
|
2023-02-02 10:08:13 -05:00
|
|
|
void apply(CCNode* on) override;
|
2023-04-04 10:44:49 -04:00
|
|
|
CCSize getSizeHint(CCNode* on) const override;
|
2022-10-10 13:58:47 -04:00
|
|
|
|
2023-02-11 05:06:01 -05:00
|
|
|
Axis getAxis() const;
|
|
|
|
AxisAlignment getAxisAlignment() const;
|
|
|
|
AxisAlignment getCrossAxisAlignment() const;
|
2023-02-23 14:18:43 -05:00
|
|
|
AxisAlignment getCrossAxisLineAlignment() const;
|
2023-02-11 05:06:01 -05:00
|
|
|
float getGap() const;
|
|
|
|
bool getAxisReverse() const;
|
|
|
|
bool getCrossAxisReverse() const;
|
|
|
|
bool getAutoScale() const;
|
|
|
|
bool getGrowCrossAxis() const;
|
|
|
|
bool getCrossAxisOverflow() const;
|
2024-01-20 14:26:01 -05:00
|
|
|
std::optional<float> getAutoGrowAxis() const;
|
2024-05-09 08:18:18 -04:00
|
|
|
float getDefaultMinScale() const;
|
|
|
|
float getDefaultMaxScale() const;
|
2023-02-11 05:06:01 -05:00
|
|
|
|
2023-02-11 10:50:14 -05:00
|
|
|
AxisLayout* setAxis(Axis axis);
|
2023-02-06 14:36:08 -05:00
|
|
|
/**
|
2023-02-23 14:18:43 -05:00
|
|
|
* Sets where to align the target node's children on the main axis (X-axis
|
|
|
|
* for Row, Y-axis for Column)
|
2023-02-02 10:08:13 -05:00
|
|
|
*/
|
2023-02-06 14:36:08 -05:00
|
|
|
AxisLayout* setAxisAlignment(AxisAlignment align);
|
2023-02-11 05:06:01 -05:00
|
|
|
/**
|
2023-02-23 14:18:43 -05:00
|
|
|
* Sets where to align the target node's children on the cross-axis (Y-axis
|
|
|
|
* for Row, X-axis for Column)
|
2023-02-11 05:06:01 -05:00
|
|
|
*/
|
|
|
|
AxisLayout* setCrossAxisAlignment(AxisAlignment align);
|
2023-02-23 14:18:43 -05:00
|
|
|
/**
|
|
|
|
* Sets where to align the target node's children on the cross-axis for
|
|
|
|
* each row (Y-axis for Row, X-axis for Column)
|
|
|
|
*/
|
|
|
|
AxisLayout* setCrossAxisLineAlignment(AxisAlignment align);
|
2023-02-02 10:08:13 -05:00
|
|
|
/**
|
|
|
|
* The spacing between the children of the node this layout applies to.
|
2023-02-06 14:36:08 -05:00
|
|
|
* Measured as the space between their edges, not centres. Does not apply
|
|
|
|
* on the main / cross axis if their alignment is AxisAlignment::Even
|
2023-02-02 10:08:13 -05:00
|
|
|
*/
|
2023-02-04 08:58:10 -05:00
|
|
|
AxisLayout* setGap(float gap);
|
2023-02-02 10:08:13 -05:00
|
|
|
/**
|
|
|
|
* Whether to reverse the direction of the children in this layout or not
|
|
|
|
*/
|
2023-02-06 14:36:08 -05:00
|
|
|
AxisLayout* setAxisReverse(bool reverse);
|
|
|
|
/**
|
|
|
|
* Whether to reverse the direction of the rows on the cross-axis or not
|
|
|
|
*/
|
|
|
|
AxisLayout* setCrossAxisReverse(bool reverse);
|
2023-02-02 10:08:13 -05:00
|
|
|
/**
|
2023-02-06 14:36:08 -05:00
|
|
|
* If enabled, then the layout may scale the target's children if they are
|
|
|
|
* about to overflow. Assumes that all the childrens' intended scale is 1
|
2023-02-02 10:08:13 -05:00
|
|
|
*/
|
2023-02-04 08:58:10 -05:00
|
|
|
AxisLayout* setAutoScale(bool enable);
|
2023-02-02 10:08:13 -05:00
|
|
|
/**
|
2023-02-06 14:36:08 -05:00
|
|
|
* If true, if the main axis overflows extra nodes will be placed on new
|
|
|
|
* rows/columns on the cross-axis
|
|
|
|
*/
|
|
|
|
AxisLayout* setGrowCrossAxis(bool expand);
|
|
|
|
/**
|
|
|
|
* If true, the cross-axis content size of the target node will be
|
|
|
|
* automatically adjusted to fit the children
|
2023-02-02 10:08:13 -05:00
|
|
|
*/
|
2023-02-06 14:36:08 -05:00
|
|
|
AxisLayout* setCrossAxisOverflow(bool allow);
|
2024-01-20 14:26:01 -05:00
|
|
|
/**
|
|
|
|
* If not `std::nullopt`, then the axis will be automatically extended to
|
|
|
|
* fit all items in a single row whose minimum length is the specified.
|
|
|
|
* Useful for scrollable list layer contents
|
|
|
|
*/
|
|
|
|
AxisLayout* setAutoGrowAxis(std::optional<float> allowAndMinLength);
|
2024-05-09 08:18:18 -04:00
|
|
|
/**
|
|
|
|
* Set the default minimum/maximum scales for nodes in the layout
|
|
|
|
*/
|
|
|
|
AxisLayout* setDefaultScaleLimits(float min, float max);
|
2022-10-10 13:58:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2023-02-04 08:58:10 -05:00
|
|
|
* Simple layout for arranging nodes in a row (horizontal line)
|
2022-10-10 13:58:47 -04:00
|
|
|
*/
|
2023-02-04 08:58:10 -05:00
|
|
|
class GEODE_DLL RowLayout : public AxisLayout {
|
2022-10-10 13:58:47 -04:00
|
|
|
protected:
|
2023-02-04 08:58:10 -05:00
|
|
|
RowLayout();
|
2022-10-10 13:58:47 -04:00
|
|
|
|
|
|
|
public:
|
2023-02-04 08:58:10 -05:00
|
|
|
/**
|
2024-02-10 06:09:11 -05:00
|
|
|
* Create a new RowLayout. See the chainable setters on RowLayout for
|
2023-02-04 08:58:10 -05:00
|
|
|
* what options you can customize for the layout
|
|
|
|
* @returns Created RowLayout
|
|
|
|
*/
|
|
|
|
static RowLayout* create();
|
|
|
|
};
|
2022-10-10 13:58:47 -04:00
|
|
|
|
2023-02-04 08:58:10 -05:00
|
|
|
/**
|
|
|
|
* Simple layout for arranging nodes in a column (vertical line)
|
|
|
|
*/
|
|
|
|
class GEODE_DLL ColumnLayout : public AxisLayout {
|
|
|
|
protected:
|
|
|
|
ColumnLayout();
|
|
|
|
|
|
|
|
public:
|
2023-02-02 10:08:13 -05:00
|
|
|
/**
|
2024-02-10 06:09:11 -05:00
|
|
|
* Create a new ColumnLayout. See the chainable setters on RowLayout for
|
2023-02-02 10:08:13 -05:00
|
|
|
* what options you can customize for the layout
|
|
|
|
* @returns Created ColumnLayout
|
|
|
|
*/
|
|
|
|
static ColumnLayout* create();
|
2022-10-10 13:58:47 -04:00
|
|
|
};
|
|
|
|
|
2024-01-29 17:08:53 -05:00
|
|
|
/**
|
|
|
|
* The relative position of a node to its parent in an AnchorLayout
|
|
|
|
*/
|
|
|
|
enum class Anchor {
|
|
|
|
Center,
|
|
|
|
TopLeft,
|
|
|
|
Top,
|
|
|
|
TopRight,
|
|
|
|
Right,
|
|
|
|
BottomRight,
|
|
|
|
Bottom,
|
|
|
|
BottomLeft,
|
|
|
|
Left,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2024-01-31 16:30:52 -05:00
|
|
|
* Options for customizing a node's position in an AnchorLayout
|
2024-01-29 17:08:53 -05:00
|
|
|
*/
|
|
|
|
class GEODE_DLL AnchorLayoutOptions : public LayoutOptions {
|
|
|
|
protected:
|
|
|
|
Anchor m_anchor = Anchor::Center;
|
|
|
|
CCPoint m_offset = CCPointZero;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static AnchorLayoutOptions* create();
|
|
|
|
|
|
|
|
Anchor getAnchor() const;
|
|
|
|
CCPoint getOffset() const;
|
|
|
|
|
|
|
|
AnchorLayoutOptions* setAnchor(Anchor anchor);
|
|
|
|
AnchorLayoutOptions* setOffset(CCPoint const& offset);
|
|
|
|
};
|
|
|
|
|
2024-01-31 16:30:52 -05:00
|
|
|
/**
|
|
|
|
* A layout for positioning nodes at specific positions relative to their
|
|
|
|
* parent's content size. See `Anchor` for available anchoring options. Useful
|
|
|
|
* for example for popups, where a popup using `AnchorLayout` can be
|
|
|
|
* automatically resized without needing to manually shuffle nodes around
|
|
|
|
*/
|
2024-01-29 17:08:53 -05:00
|
|
|
class GEODE_DLL AnchorLayout : public Layout {
|
|
|
|
public:
|
|
|
|
static AnchorLayout* create();
|
|
|
|
|
|
|
|
void apply(CCNode* on) override;
|
|
|
|
CCSize getSizeHint(CCNode* on) const override;
|
2024-01-31 16:11:43 -05:00
|
|
|
|
2024-01-31 16:30:52 -05:00
|
|
|
/**
|
|
|
|
* Get a position according to anchoring rules, with the same algorithm as
|
|
|
|
* `AnchorLayout` uses to position its nodes
|
|
|
|
* @param in The node whose content size to use as a reference
|
|
|
|
* @param anchor The anchor position
|
|
|
|
* @param offset Offset from the anchor
|
|
|
|
* @returns A position in `in` for the anchored and offsetted location
|
|
|
|
*/
|
2024-01-31 16:11:43 -05:00
|
|
|
static CCPoint getAnchoredPosition(CCNode* in, Anchor anchor, CCPoint const& offset);
|
|
|
|
};
|
|
|
|
|
2024-01-31 16:30:52 -05:00
|
|
|
/**
|
|
|
|
* A layout for automatically copying the content size of a node to other nodes.
|
|
|
|
* Basically main use case is for FLAlertLayers (setting the size of the
|
|
|
|
* background and `m_buttonMenu` based on `m_mainLayer`)
|
|
|
|
*/
|
2024-02-01 09:08:17 -05:00
|
|
|
class GEODE_DLL CopySizeLayout : public cocos2d::AnchorLayout {
|
2024-01-31 16:11:43 -05:00
|
|
|
protected:
|
|
|
|
cocos2d::CCArray* m_targets;
|
|
|
|
|
|
|
|
public:
|
2024-01-31 16:36:00 -05:00
|
|
|
static CopySizeLayout* create();
|
|
|
|
virtual ~CopySizeLayout();
|
2024-01-31 16:11:43 -05:00
|
|
|
|
2024-01-31 16:30:52 -05:00
|
|
|
/**
|
|
|
|
* Add a target to be automatically resized. Any targets' layouts will
|
|
|
|
* also be updated when this layout is updated
|
|
|
|
*/
|
2024-01-31 16:36:00 -05:00
|
|
|
CopySizeLayout* add(cocos2d::CCNode* target);
|
2024-01-31 16:30:52 -05:00
|
|
|
/**
|
|
|
|
* Remove a target from being automatically resized
|
|
|
|
*/
|
2024-01-31 16:36:00 -05:00
|
|
|
CopySizeLayout* remove(cocos2d::CCNode* target);
|
2024-01-31 16:11:43 -05:00
|
|
|
|
|
|
|
void apply(cocos2d::CCNode* in) override;
|
|
|
|
cocos2d::CCSize getSizeHint(cocos2d::CCNode* in) const override;
|
2024-01-29 17:08:53 -05:00
|
|
|
};
|
|
|
|
|
2023-03-19 09:02:49 -04:00
|
|
|
#pragma warning(pop)
|
|
|
|
|
2022-10-10 13:58:47 -04:00
|
|
|
NS_CC_END
|