CUGL 2.1
Cornell University Game Library
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cugl::scene2::FloatLayout Class Reference

#include <CUFloatLayout.h>

Inheritance diagram for cugl::scene2::FloatLayout:
cugl::scene2::Layout

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< FloatLayoutalloc ()
 
static std::shared_ptr< FloatLayoutallocWithData (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
 

Detailed Description

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.

Member Enumeration Documentation

◆ Alignment

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.

Constructor & Destructor Documentation

◆ FloatLayout()

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.

◆ ~FloatLayout()

cugl::scene2::FloatLayout::~FloatLayout ( )
inline

Deletes this layout manager, disposing of all resources.

Member Function Documentation

◆ add()

virtual bool cugl::scene2::FloatLayout::add ( const std::string  key,
const std::shared_ptr< JsonValue > &  data 
)
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.

Parameters
keyThe key identifying the layout information
dataA JSON object with the layout information
Returns
true if the layout information was assigned to that key

Reimplemented from cugl::scene2::Layout.

◆ alloc()

static std::shared_ptr<FloatLayout> cugl::scene2::FloatLayout::alloc ( )
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.

Returns
a newly allocated layout manager.

◆ allocWithData()

static std::shared_ptr<FloatLayout> cugl::scene2::FloatLayout::allocWithData ( const std::shared_ptr< JsonValue > &  data)
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.

Parameters
dataThe JSON object specifying the node
Returns
a newly allocated layout manager with the given JSON specificaton.

◆ dispose()

virtual void cugl::scene2::FloatLayout::dispose ( )
overridevirtual

Deletes the layout resources and resets all attributes.

A disposed layout manager can be safely reinitialized.

Reimplemented from cugl::scene2::Layout.

◆ getAlignment()

Alignment cugl::scene2::FloatLayout::getAlignment ( ) const
inline

Returns the alignment of this layout.

All children must share the same alignment.

Returns
the alignment of this layout.

◆ initWithData()

virtual bool cugl::scene2::FloatLayout::initWithData ( const std::shared_ptr< JsonValue > &  data)
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.

Parameters
dataThe JSON object specifying the node
Returns
true if initialization was successful.

Reimplemented from cugl::scene2::Layout.

◆ isHorizontal()

bool cugl::scene2::FloatLayout::isHorizontal ( ) const
inline

Returns true if the layout orientation is horizontal.

All children must be laid out by the same orientation.

Returns
true if the layout orientation is horizontal.

◆ layout()

virtual void cugl::scene2::FloatLayout::layout ( SceneNode node)
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.

Parameters
nodeThe scene graph node to rearrange

Reimplemented from cugl::scene2::Layout.

◆ layoutHorizontal()

void cugl::scene2::FloatLayout::layoutHorizontal ( SceneNode node)
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.

Parameters
nodeThe scene graph node to rearrange

◆ layoutVertical()

void cugl::scene2::FloatLayout::layoutVertical ( SceneNode node)
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.

Parameters
nodeThe scene graph node to rearrange

◆ prioritize()

void cugl::scene2::FloatLayout::prioritize ( )
protected

Computes the priority of the layout elements.

This method resorts the contents of the priority queue to match the current layout values.

◆ remove()

virtual bool cugl::scene2::FloatLayout::remove ( const std::string  key)
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.

Parameters
keyThe key identifying the layout information
Returns
true if the layout information was removed for that key

Reimplemented from cugl::scene2::Layout.

◆ setAlignment()

void cugl::scene2::FloatLayout::setAlignment ( Alignment  value)
inline

Sets whether the layout orientation is horizontal.

All children must be laid out by the same orientation.

Parameters
valueThe alignment of this layout.

◆ setHorizontal()

void cugl::scene2::FloatLayout::setHorizontal ( bool  value)
inline

Sets whether the layout orientation is horizontal.

All children must be laid out by the same orientation.

Parameters
valueWhether the layout orientation is horizontal.

Member Data Documentation

◆ _alignment

Alignment cugl::scene2::FloatLayout::_alignment
protected

The layout aligment

◆ _entries

std::unordered_map<std::string,Entry> cugl::scene2::FloatLayout::_entries
protected

The map of keys to layout information

◆ _horizontal

bool cugl::scene2::FloatLayout::_horizontal
protected

Whether the layout is horizontal or vertical

◆ _priority

std::vector<std::string> cugl::scene2::FloatLayout::_priority
protected

The priority ordering of this layout


The documentation for this class was generated from the following file: