cocos2d-x  3.5
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LayoutComponent Class Reference

A component class used for layout. More...

#include <UILayoutComponent.h>

Inheritance diagram for LayoutComponent:

Public Types

enum  HorizontalEdge { None, Left, Right, Center }
 Horizontal dock position type. More...
 
enum  VerticalEdge { None, Bottom, Top, Center }
 Vertical dock position type. More...
 

Public Member Functions

 LayoutComponent ()
 Default constructor. More...
 
 ~LayoutComponent ()
 Default destructor. More...
 
virtual bool init () override
 CREATE_FUNC (LayoutComponent)
 Create a LayoutComponent instance with default settings. More...
 
void setUsingPercentContentSize (bool isUsed)
 Percent content size is used to adapt node's content size based on parent's content size. More...
 
bool getUsingPercentContentSize () const
 Query whether use percent content size or not. More...
 
void setPercentContentSize (const Vec2 &percent)
 Set percent content size. More...
 
Vec2 getPercentContentSize () const
 Query the percent content size value. More...
 
const PointgetAnchorPosition () const
 Query the anchor position. More...
 
void setAnchorPosition (const Point &point)
 Change the anchor position to it's parent. More...
 
const PointgetPosition () const
 Query the owner's position. More...
 
void setPosition (const Point &position)
 Change the position of component owner. More...
 
bool isPositionPercentXEnabled () const
 Whether position percentX is enabled or not. More...
 
void setPositionPercentXEnabled (bool isUsed)
 Toggle position percentX enabled. More...
 
float getPositionPercentX () const
 Query the position percent X value. More...
 
void setPositionPercentX (float percentMargin)
 Change position percent X value. More...
 
bool isPositionPercentYEnabled () const
 Whether position percentY is enabled or not. More...
 
void setPositionPercentYEnabled (bool isUsed)
 Toggle position percentY enabled. More...
 
float getPositionPercentY () const
 Query the position percentY Y value. More...
 
void setPositionPercentY (float percentMargin)
 Change position percentY value. More...
 
HorizontalEdge getHorizontalEdge () const
 Query element horizontal dock type. More...
 
void setHorizontalEdge (HorizontalEdge hEage)
 Change element's horizontal dock type. More...
 
VerticalEdge getVerticalEdge () const
 Query element vertical dock type. More...
 
void setVerticalEdge (VerticalEdge vEage)
 Change element's vertical dock type. More...
 
float getLeftMargin () const
 Query left margin of owner relative to its parent. More...
 
void setLeftMargin (float margin)
 Change left margin of owner relative to its parent. More...
 
float getRightMargin () const
 Query the right margin of owner relative to its parent. More...
 
void setRightMargin (float margin)
 Change right margin of owner relative to its parent. More...
 
float getTopMargin () const
 Query the top margin of owner relative to its parent. More...
 
void setTopMargin (float margin)
 Change the top margin of owner relative to its parent. More...
 
float getBottomMargin () const
 Query the bottom margin of owner relative to its parent. More...
 
void setBottomMargin (float margin)
 Change the bottom margin of owner relative to its parent. More...
 
const SizegetSize () const
 Query owner's content size. More...
 
void setSize (const Size &size)
 Change the content size of owner. More...
 
bool isPercentWidthEnabled () const
 Query whether percent width is enabled or not. More...
 
void setPercentWidthEnabled (bool isUsed)
 Toggle enable percent width. More...
 
float getSizeWidth () const
 Query content size width of owner. More...
 
void setSizeWidth (float width)
 Change content size width of owner. More...
 
float getPercentWidth () const
 Query percent width of owner. More...
 
void setPercentWidth (float percentWidth)
 Change percent width of owner. More...
 
bool isPercentHeightEnabled () const
 Query whehter percent height is enabled or not. More...
 
void setPercentHeightEnabled (bool isUsed)
 Toggle enable percent height. More...
 
float getSizeHeight () const
 Query size height of owner. More...
 
void setSizeHeight (float height)
 Change size height of owner. More...
 
float getPercentHeight () const
 Query percent hieght of owner. More...
 
void setPercentHeight (float percentHeight)
 Change percent height value of owner. More...
 
bool isStretchWidthEnabled () const
 Query whether stretch width is enabled or not. More...
 
void setStretchWidthEnabled (bool isUsed)
 Toggle enable stretch width. More...
 
bool isStretchHeightEnabled () const
 Query whether stretch height is enabled or not. More...
 
void setStretchHeightEnabled (bool isUsed)
 Toggle enable stretch height. More...
 
void setPercentOnlyEnabled (bool enable)
 Toggle enable percent only. More...
 
void setActiveEnabled (bool enable)
 Toggle active enabled of LayoutComponent's owner. More...
 
void refreshLayout ()
 Refresh layout of the owner. More...
 

Static Public Member Functions

static LayoutComponentbindLayoutComponent (Node *node)
 Bind a LayoutComponent to a specified node. More...
 

Protected Member Functions

NodegetOwnerParent ()
void refreshHorizontalMargin ()
void refreshVerticalMargin ()

Protected Attributes

HorizontalEdge _horizontalEdge
VerticalEdge _verticalEdge
float _leftMargin
float _rightMargin
float _bottomMargin
float _topMargin
bool _usingPositionPercentX
float _positionPercentX
bool _usingPositionPercentY
float _positionPercentY
bool _usingStretchWidth
bool _usingStretchHeight
float _percentWidth
bool _usingPercentWidth
float _percentHeight
bool _usingPercentHeight
bool _actived
bool _isPercentOnly

Detailed Description

A component class used for layout.

The LayoutComponent holds all the data for layouting.

Constructor & Destructor Documentation

Default constructor.

Default destructor.

Member Function Documentation

static LayoutComponent*
bindLayoutComponent
( Node node)
static

Bind a LayoutComponent to a specified node.

If the node has already binded a LayoutComponent named __LAYOUT_COMPONENT_NAME, just return the LayoutComponent. Otherwise, create a new LayoutComponent and bind the LayoutComponent to the node.

Parameters
nodeA Node* instance pointer.
Returns
The binded LayoutComponent instance pointer.
CREATE_FUNC ( LayoutComponent  )

Create a LayoutComponent instance with default settings.

const Point& getAnchorPosition ( ) const

Query the anchor position.

Returns
Anchor position to it's parent
float getBottomMargin ( ) const

Query the bottom margin of owner relative to its parent.

Returns
Bottom margin in float.
HorizontalEdge getHorizontalEdge ( ) const

Query element horizontal dock type.

Returns
Horizontal dock type.
float getLeftMargin ( ) const

Query left margin of owner relative to its parent.

Returns
Left margin in float.
Node* getOwnerParent ( )
protected
Vec2 getPercentContentSize ( ) const

Query the percent content size value.

Returns
Percet (x,y) in Vec2.
float getPercentHeight ( ) const

Query percent hieght of owner.

Returns
Percent height in float.
float getPercentWidth ( ) const

Query percent width of owner.

Returns
percent width in float.
const Point& getPosition ( ) const

Query the owner's position.

Returns
The owner's position.
float getPositionPercentX ( ) const

Query the position percent X value.

Returns
Position percent X value in float.
float getPositionPercentY ( ) const

Query the position percentY Y value.

Returns
Position percent Y value in float.
float getRightMargin ( ) const

Query the right margin of owner relative to its parent.

Returns
Right margin in float.
const Size& getSize ( ) const

Query owner's content size.

Returns
Owner's content size.
float getSizeHeight ( ) const

Query size height of owner.

Returns
Size height in float.
float getSizeWidth ( ) const

Query content size width of owner.

Returns
Content size width in float.
float getTopMargin ( ) const

Query the top margin of owner relative to its parent.

Returns
Top margin in float.
bool getUsingPercentContentSize ( ) const

Query whether use percent content size or not.

Returns
True if using percent content size, false otherwise.
VerticalEdge getVerticalEdge ( ) const

Query element vertical dock type.

Returns
Vertical dock type.
virtual bool init ( )
overridevirtual
bool isPercentHeightEnabled ( ) const

Query whehter percent height is enabled or not.

Returns
True if percent height is enabled, false otherwise.
bool isPercentWidthEnabled ( ) const

Query whether percent width is enabled or not.

Returns
True if percent width is enabled, false, otherwise.
bool isPositionPercentXEnabled ( ) const

Whether position percentX is enabled or not.

Returns
True if position percertX is enable, false otherwise.
bool isPositionPercentYEnabled ( ) const

Whether position percentY is enabled or not.

See also
setPositionPercentYEnabled
Returns
True if position percentY is enabled, false otherwise.
bool isStretchHeightEnabled ( ) const

Query whether stretch height is enabled or not.

Returns
True if stretch height is enabled, false otherwise.
bool isStretchWidthEnabled ( ) const

Query whether stretch width is enabled or not.

Returns
True if stretch width is enabled, false otherwise.
void refreshHorizontalMargin ( )
protected
void refreshLayout ( )

Refresh layout of the owner.

void refreshVerticalMargin ( )
protected
void setActiveEnabled ( bool  enable)

Toggle active enabled of LayoutComponent's owner.

Parameters
enableTrue if active layout component, false otherwise.
void setAnchorPosition ( const Point point)

Change the anchor position to it's parent.

Parameters
pointA value in (x,y) format.
void setBottomMargin ( float  margin)

Change the bottom margin of owner relative to its parent.

Parameters
Marginin float.
void setHorizontalEdge ( HorizontalEdge  hEage)

Change element's horizontal dock type.

Parameters
hEageHorizontal dock type
See also
HorizontalEdge
void setLeftMargin ( float  margin)

Change left margin of owner relative to its parent.

Parameters
marginMargin in float.
void setPercentContentSize ( const Vec2 percent)

Set percent content size.

The value should be [0-1], 0 means the child's content size will be 0 and 1 means the child's content size is the same as its parents.

Parameters
percentThe percent (x,y) of the node in [0-1] scope.
void setPercentHeight ( float  percentHeight)

Change percent height value of owner.

Parameters
percentHeightPercent height in float.
void setPercentHeightEnabled ( bool  isUsed)

Toggle enable percent height.

Parameters
isUsedTrue if percent height is enabled, false otherwise.
void setPercentOnlyEnabled ( bool  enable)

Toggle enable percent only.

Parameters
enableTrue if percent only is enabled, false otherwise.
void setPercentWidth ( float  percentWidth)

Change percent width of owner.

Parameters
percentWidthPercent Width in float.
void setPercentWidthEnabled ( bool  isUsed)

Toggle enable percent width.

Parameters
isUsedTrue if percent width is enabled, false otherwise.
void setPosition ( const Point position)

Change the position of component owner.

Parameters
positionA position in (x,y)
void setPositionPercentX ( float  percentMargin)

Change position percent X value.

Parameters
percentMarginMargin in float.
void setPositionPercentXEnabled ( bool  isUsed)

Toggle position percentX enabled.

Parameters
isUsedTrue if enable position percentX, false otherwise.
void setPositionPercentY ( float  percentMargin)

Change position percentY value.

Parameters
percentMarginMargin in float.
void setPositionPercentYEnabled ( bool  isUsed)

Toggle position percentY enabled.

Parameters
isUsedTrue if position percentY is enabled, false otherwise.
void setRightMargin ( float  margin)

Change right margin of owner relative to its parent.

Parameters
marginMargin in float.
void setSize ( const Size size)

Change the content size of owner.

Parameters
sizeContent size in
See also
Size.
void setSizeHeight ( float  height)

Change size height of owner.

Parameters
heightSize height in float.
void setSizeWidth ( float  width)

Change content size width of owner.

Parameters
widthContent size width in float.
void setStretchHeightEnabled ( bool  isUsed)

Toggle enable stretch height.

Parameters
isUsedTrue if stretch height is enabled, false otherwise.
void setStretchWidthEnabled ( bool  isUsed)

Toggle enable stretch width.

Parameters
isUsedTrue if enable stretch width, false otherwise.
void setTopMargin ( float  margin)

Change the top margin of owner relative to its parent.

Parameters
marginMargin in float.
void setUsingPercentContentSize ( bool  isUsed)

Percent content size is used to adapt node's content size based on parent's content size.

If set to true then node's content size will be changed based on the value setted by

Parameters
isUsedTrue to enable percent content size, false otherwise.
void setVerticalEdge ( VerticalEdge  vEage)

Change element's vertical dock type.

Parameters
vEageVertical dock type
See also
VerticalEdge.

Member Data Documentation

bool _actived
protected
float _bottomMargin
protected
HorizontalEdge _horizontalEdge
protected
bool _isPercentOnly
protected
float _leftMargin
protected
float _percentHeight
protected
float _percentWidth
protected
float _positionPercentX
protected
float _positionPercentY
protected
float _rightMargin
protected
float _topMargin
protected
bool _usingPercentHeight
protected
bool _usingPercentWidth
protected
bool _usingPositionPercentX
protected
bool _usingPositionPercentY
protected
bool _usingStretchHeight
protected
bool _usingStretchWidth
protected
VerticalEdge _verticalEdge
protected

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