CUGL 1.3
Cornell University Game Library
|
#include <CUFloatLayout.h>
Public Types | |
enum | Alignment : int { Alignment::BOTTOM_LEFT = 0, Alignment::MIDDLE_LEFT = 1, Alignment::TOP_LEFT = 2, Alignment::BOTTOM_CENTER = 3, Alignment::CENTER = 4, Alignment::TOP_CENTER = 5, Alignment::BOTTOM_RIGHT = 6, Alignment::MIDDLE_RIGHT = 7, Alignment::TOP_RIGHT = 8 } |
Public Types inherited from cugl::Layout | |
enum | Anchor : int { Anchor::BOTTOM_LEFT = 0, Anchor::MIDDLE_LEFT = 1, Anchor::TOP_LEFT = 2, Anchor::BOTTOM_CENTER = 3, Anchor::CENTER = 4, Anchor::TOP_CENTER = 5, Anchor::BOTTOM_RIGHT = 6, Anchor::MIDDLE_RIGHT = 7, Anchor::TOP_RIGHT = 8, Anchor::BOTTOM_FILL = 9, Anchor::MIDDLE_FILL = 10, Anchor::TOP_FILL = 11, Anchor::LEFT_FILL = 12, Anchor::CENTER_FILL = 13, Anchor::RIGHT_FILL = 14, Anchor::TOTAL_FILL = 15, Anchor::NONE = 16 } |
Public Member Functions | |
FloatLayout () | |
~FloatLayout () | |
virtual bool | initWithData (const std::shared_ptr< JsonValue > &data) override |
virtual void | dispose () override |
bool | isHorizontal () const |
void | setHorizontal (bool value) |
Alignment | getAlignment () const |
void | setAlignment (Alignment value) |
virtual bool | add (const std::string key, const std::shared_ptr< JsonValue > &data) override |
bool | addPriority (const std::string key, size_t priority) |
virtual bool | remove (const std::string key) override |
virtual void | layout (Node *node) override |
Public Member Functions inherited from cugl::Layout | |
Layout () | |
~Layout () | |
virtual bool | init () |
Static Public Member Functions | |
static std::shared_ptr< FloatLayout > | alloc () |
static std::shared_ptr< FloatLayout > | allocWithData (const std::shared_ptr< JsonValue > &data) |
Static Public Member Functions inherited from cugl::Layout | |
static Anchor | getAnchor (const std::string &x_anchor, const std::string &y_anchor) |
static void | placeNode (Node *node, Anchor anchor, const Rect &bounds, const Vec2 &offset) |
static void | reanchor (Node *node, Anchor anchor) |
Protected Member Functions | |
void | layoutHorizontal (Node *node) |
void | layoutVertical (Node *node) |
Protected Attributes | |
std::vector< std::string > | _priority |
std::unordered_map< std::string, size_t > | _keyset |
bool | _horizontal |
Alignment | _alignment |
This class provides a float layout manager.
Children in a float layout are arranged in order, according to the layout orientation (horizontal or vertical). If there is not enough space in the Node for the children to all be in the same row or column (depending on orientation), then the later children wrap around to a new row or column. New rows are added downwards and new columns are added to the right. This is the same way that float layouts work in Java.
Any children that cannot fit (non-overlapping) into the Node are dropped. Once a child is dropped, no further children will be placed. So an exceptional large child can block the rest of the layout.
Layout information is indexed by key. To look up the layout information of a scene graph node, we use the name of the node. This requires all nodes to have unique names. The SceneLoader prefixes all child names by the parent name, so this is the case in any well-defined JSON file.
|
strong |
This enum represents the possible layout alignments.
Alignment is independent of an orientation. It specifies how to align each line or column with respect to each other, as well as how to anchor all of them in the larger Node space.
While alignment looks superficially similar to anchors, we do not currently allow fill alignments for a float layout. In addition, the semantics of alignment are very different than anchors. So we express them as different layouts.
Enumerator | |
---|---|
BOTTOM_LEFT | In horizontal orientation, this left justifies all of the individual lines. In addition, all Nodes in a single line will be aligned by their bottom, and the bottom line will be flush with the bottom of the Node. In vertical orientation, this bottom justifies all of the individual columns. In addition, all Nodes in a single column will be aligned by their left, and the left column will be flush with the left of the Node. |
MIDDLE_LEFT | In horizontal orientation, this left justifies all of the individual lines. In addition, all Nodes in a single line will be aligned by their middle, and the layout will be centered in the Node. In vertical orientation, this centers each of individual columns. In addition, all Nodes in a single column will be aligned by their left, and the left column will be flush with the left of the Node. |
TOP_LEFT | In horizontal orientation, this left justifies all of the individual lines. In addition, all Nodes in a single line will be aligned by their top, and the top line will be flush with the bottom of the Node. In vertical orientation, this top justifies all of the individual columns. In addition, all Nodes in a single column will be aligned by their left, and the left column will be flush with the left of the Node. |
BOTTOM_CENTER | In horizontal orientation, this centers each of the individual lines. In addition, all Nodes in a single line will be aligned by their bottom, and the bottom line will be flush with the bottom of the Node. In vertical orientation, this bottom justifies all of the individual columns. In addition, all Nodes in a single column will be aligned by their center, and the layout will be centered in the Node. |
CENTER | In horizontal orientation, this centers each of the individual lines. In addition, all Nodes in a single line will be aligned by their center, and the layout will be centered in the Node. In vertical orientation, this centers each of the individual columns. In addition, all Nodes in a single column will be aligned by their center, and the layout will be centered in the Node. |
TOP_CENTER | In horizontal orientation, this centers each of the individual lines. In addition, all Nodes in a single line will be aligned by their top, and the top line will be flush with the bottom of the Node. In vertical orientation, this top justifies all of the individual columns. In addition, all Nodes in a single column will be aligned by their center, and the layout will be centered in the Node. |
BOTTOM_RIGHT | In horizontal orientation, this right justifies all of the individual lines. In addition, all Nodes in a single line will be aligned by their bottom, and the bottom line will be flush with the bottom of the Node. In vertical orientation, this bottom justifies all of the individual columns. In addition, all Nodes in a single column will be aligned by their right, and the right column will be flush with the right of the Node. |
MIDDLE_RIGHT | In horizontal orientation, this right justifies all of the individual lines. In addition, all Nodes in a single line will be aligned by their middle, and the layout will be centered in the Node. In vertical orientation, this centers each of individual columns. In addition, all Nodes in a single column will be aligned by their right, and the right column will be flush with the right of the Node. |
TOP_RIGHT | In horizontal orientation, this right justifies all of the individual lines. In addition, all Nodes in a single line will be aligned by their top, and the top line will be flush with the bottom of the Node. In vertical orientation, this top justifies all of the individual columns. In addition, all Nodes in a single column will be aligned by their right, and the right column will be flush with the right of the Node. |
cugl::FloatLayout::FloatLayout | ( | ) |
Creates a degenerate layout manager with no data.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.
|
inline |
Deletes this layout manager, disposing of all resources.
|
overridevirtual |
Assigns layout information for a given key.
The JSON object may contain any of the following attribute value:
"priority": An int indicating placement priority. Children with lower priority go first.
A child with no priority is put at the end. If there is already a child with the given priority, then this method will fail.
To look up the layout information of a scene graph node, we use the name of the node. This requires all nodes to have unique names. The SceneLoader prefixes all child names by the parent name, so this is the case in any well-defined JSON file. If the key is already in use, this method will fail.
key | The key identifying the layout information |
data | A JSON object with the layout information |
Reimplemented from cugl::Layout.
bool cugl::FloatLayout::addPriority | ( | const std::string | key, |
size_t | priority | ||
) |
Assigns the layout priority for a given key.
In a float layout, children with lower priority go first. If there is already a child with the given priority, then this method will fail.
To look up the layout information of a scene graph node, we use the name of the node. This requires all nodes to have unique names. The SceneLoader prefixes all child names by the parent name, so this is the case in any well-defined JSON file. If the key is already in use, this method will fail.
key | The key identifying the layout information |
priority | The priority (lower is better) for this key |
|
inlinestatic |
Returns a newly allocated layout manager.
The layout manager is initially empty. Before using it to perform a layout, layout information must be registered throught the add method interface.
|
inlinestatic |
Returns a newly allocated layout manager with the given JSON specificaton.
In addition to the 'type' attribute (which must be "float"), the JSON specification supports the following attribute values:
"orientation": One of 'horizontal' or 'vertical' "x_alignment": One of 'left', 'center', or 'right' "y_alignment": One of 'bottom', 'middle', or 'top'
All attributes other than 'type' are optional.
data | The JSON object specifying the node |
|
inlineoverridevirtual |
Deletes the layout resources and resets all attributes.
A disposed layout manager can be safely reinitialized.
Reimplemented from cugl::Layout.
|
inline |
Returns the alignment of this layout.
All children must share the same alignment.
|
overridevirtual |
Initializes a new layout manager with the given JSON specificaton.
In addition to the 'type' attribute (which must be "float"), the JSON specification supports the following attribute values:
"orientation": One of 'horizontal' or 'vertical' "x_alignment": One of 'left', 'center', or 'right' "y_alignment": One of 'bottom', 'middle', or 'top'
All attributes other than 'type' are optional.
data | The JSON object specifying the node |
Reimplemented from cugl::Layout.
|
inline |
Returns true if the layout orientation is horizontal.
All children must be laid out by the same orientation.
|
overridevirtual |
Performs a layout on the given node.
This layout manager will searches for those children that are registered with it. For those children, it repositions and/or resizes them according to the layout information.
Children in a float layout are arranged in order, according to the layout orientation (horizontal or vertical). If there is not enough space in the Node for the children to all be in the same row or column (depending on orientation), then the later children wrap around to a new row or column. New rows are added downwards and new columns are added to the right. This is the same way that float layouts work in Java.
Any children that cannot fit (non-overlapping) into the Node are dropped. Once a child is dropped, no further children will be placed. So an exceptional large child can block the rest of the layout.
Layout information is indexed by key. To look up the layout information of a scene graph node, we use the name of the node. This requires all nodes to have unique names. The SceneLoader prefixes all child names by the parent name, so this is the case in any well-defined JSON file.
Children not registered with this layout manager are not affected.
node | The scene graph node to rearrange |
Reimplemented from cugl::Layout.
|
protected |
Performs a horizontal layout on the given node.
This method is identical to layout(Node*) except that it overrides the orientation settings of the layout manager; it always lays out the children horizontally.
node | The scene graph node to rearrange |
|
protected |
Performs a vertical layout on the given node.
This method is identical to layout(Node*) except that it overrides the orientation settings of the layout manager; it always lays out the children vertically.
node | The scene graph node to rearrange |
|
overridevirtual |
Removes the layout information for a given key.
To look up the layout information of a scene graph node, we use the name of the node. This requires all nodes to have unique names. The SceneLoader prefixes all child names by the parent name, so this is the case in any well-defined JSON file.
If the key is not in use, this method will fail.
key | The key identifying the layout information |
Reimplemented from cugl::Layout.
|
inline |
Sets whether the layout orientation is horizontal.
All children must be laid out by the same orientation.
value | The alignment of this layout. |
|
inline |
Sets whether the layout orientation is horizontal.
All children must be laid out by the same orientation.
value | Whether the layout orientation is horizontal. |
|
protected |
The layout aligment
|
protected |
Whether the layout is horizontal or vertical
|
protected |
To ensure key uniqueness
|
protected |
The child priority