CUGL 2.1
Cornell University Game Library
|
#include <CUFloatLayout.h>
Classes | |
class | Entry |
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::scene2::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 |
virtual bool | remove (const std::string key) override |
virtual void | layout (SceneNode *node) override |
Public Member Functions inherited from cugl::scene2::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::scene2::Layout | |
static Anchor | getAnchor (const std::string &x_anchor, const std::string &y_anchor) |
static void | placeNode (SceneNode *node, Anchor anchor, const Rect bounds, const Vec2 offset) |
static void | reanchor (SceneNode *node, Anchor anchor) |
Protected Member Functions | |
void | layoutHorizontal (SceneNode *node) |
void | layoutVertical (SceneNode *node) |
void | prioritize () |
Protected Attributes | |
std::vector< std::string > | _priority |
std::unordered_map< std::string, Entry > | _entries |
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 Scene2Loader 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.
cugl::scene2::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 values:
"priority": An int indicating placement priority. Children with lower priority go first. "padding" : A four-element float array. It defines the padding on all sides between elements
A child with no priority is put at the end. If there is already a child with the given priority, the ordering of the two elements is undefined
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 Scene2Loader 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::scene2::Layout.
|
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 |
|
overridevirtual |
Deletes the layout resources and resets all attributes.
A disposed layout manager can be safely reinitialized.
Reimplemented from cugl::scene2::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::scene2::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 Scene2Loader 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::scene2::Layout.
|
protected |
Performs a horizontal layout on the given node.
This method is identical to layout(SceneNode*) 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(SceneNode*) 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 |
|
protected |
Computes the priority of the layout elements.
This method resorts the contents of the priority queue to match the current layout values.
|
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 Scene2Loader 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::scene2::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 |
The map of keys to layout information
|
protected |
Whether the layout is horizontal or vertical
|
protected |
The priority ordering of this layout