You.i Engine
CYIAutoLayout Class Reference

Detailed Description

A layout that assigns margins to children based on their initial position and size.

This layout calculates and assigns margin values for its children based on those children's initial position and size. Because the margins are calculated from the initial position and size, this layout appears to have no effect until the associated scene view is resized. At that point, the margins are applied to maintain the relative position and size of items.

For example, a child placed in the bottom right corner of the screen will remain in the bottom right corner even if the associated scene view is resized, and a child that covers most of the width of the associated scene view will become wider if the associated scene view is made wider.

Container View Template Comments Specification

These values are applied to the comment field of the container composition. All properties are optional.

Label Default value Accepted values Description
detect-fill-parent true true, false Indicates whether the layout will automatically assign 'fill-parent:true' properties to children that are large enough (at initialization time). See 'Fill Parent' farther down for details.

The parent layout class may define more properties that can be used.

See also
CYIStackLayout

Children View Template Comments Specification

This class has no configurable per-child properties, except for those of the parent class.

See also
CYIStackLayout

Margins

Margins for children are calculated automatically based on the position and size of those children at layout initialization. Those margins are then used, when the associated scene view is resized, to properly position and size the children. Note that the gravity and 'fill parent' properties of the child affect which margins are taken into consideration during layout. See the 'gravity' and 'fill parent' sections farther down for details.

Custom (non-0) margins can be specified for children. If this layout detects a non-0 margin on one of the children, the layout will avoid automatically calculating and assigning margin values for that child. Automatic assignment of gravity and 'fill parent' properties will also be skipped when custom margins are assigned.

Gravity

The gravity value specified in this layout is ignored. Instead, the layout calculates a gravity value for each child based on its initial position. This is done by dividing the associated scene view into 3 rows and 3 columns. One of 9 possible gravity values are assigned depending on where the center of the child is within those rows and columns. For example, if the child's center is in the top-right cell then the child will be assigned a top-right gravity.

Note
If a child has an 'item gravity' value assigned to it, then the layout does not automatically assign a gravity value for the child. This can be used to force a given child to align to a specific side of the scene view.
When a detected (or user-assigned gravity) other than 'center' is used, some of the configured margin values may be ignored. For example, a 'top right' gravity would result in the left and bottom margins being ignored.

Fill Parent

By default, this layout automatically detects which children should be marked as 'fill parent.' This is done by dividing the associated scene view into 3 rows and 3 columns, and seeing where the top-left and bottom-right corners of the child are initially. If a child's top side is within the first row and its bottom side is within the last row, then that child is marked as having a height that fills its parent. If a child's left side is within the first column and its right side is within the last column, then that child is marked as having a width that fills its parent. Note that the width and height 'fill parent' properties are separate: it is possible for a child to fill width and not fill height.

Note
If a child is already marked as 'fill parent' or 'fit content', then the layout does not override that setting.
There is no way to specify that a given child should not be set as 'fill parent.' To do this, the automatic assignment of 'fill parent' properties must be turned off using the 'detect-fill-parent' property. When 'detect-fill-parent' is turned off, all children must manually be marked as 'fill parent' if necessary.
In most cases, when a child is marked as 'fill parent' then its configured or automatically-assigned gravity value has no effect.

Text

In order for the text nodes to keep their initial position, this layout ignores the actual size of text nodes (as reported by the CYISceneNode::GetSize() function). Instead, this layout calculates margins relative to the text nodes' position. For 'box text' text nodes, the box size is used in addition to the text nodes' position. A side effect of this is that if a user specifies custom margins for a test node when using this layout, those custom margins may not behave like they do with other layout types. Consequently, it recommended to avoid specifying custom margins on text nodes.

#include <layout/YiAutoLayout.h>

Inheritance diagram for CYIAutoLayout:

Public Member Functions

 CYIAutoLayout ()
 
virtual ~CYIAutoLayout ()
 
void SetDetectFillParent (bool detectFillParent)
 
bool IsDetectingFillParent () const
 
- Public Member Functions inherited from CYIStackLayout
 CYIStackLayout ()
 
virtual ~CYIStackLayout ()
 
- Public Member Functions inherited from CYIAnimatingLayout
 CYIAnimatingLayout ()
 
virtual ~CYIAnimatingLayout ()
 
void DisableAnimationsOnNextLayout (bool disable=true)
 
void DisableAnimationsOnNextLayoutFor (CYISceneNode *pChild, bool disable=true)
 
virtual void ChildRemoved (CYISceneNode *pChild) override
 
virtual void ChildVisibilityChanged (CYISceneNode *pChild) override
 
void SetMovingTime (uint32_t movingTimeMs)
 
uint32_t GetMovingTimeMs () const
 
void SetSizingTime (uint32_t sizingTimeMs)
 
uint32_t GetSizingTimeMs () const
 
void SetTimeInterpolator (std::unique_ptr< CYITimeInterpolator > pInterpolator)
 
CYITimeInterpolatorGetTimeInterpolator ()
 
const CYITimeInterpolatorGetTimeInterpolator () const
 
- Public Member Functions inherited from CYILayout
 CYILayout ()
 
virtual ~CYILayout ()
 
void AttachTo (CYISceneView *pView)
 
void ConfigureFromAttachedNode ()
 
void DetachFromNode ()
 
CYISceneNodeGetAssociatedSceneNode () const
 
void Measure (const CYISceneNode::MeasureSpec &widthSpec, const CYISceneNode::MeasureSpec &heightSpec, const CYISceneNode::MeasureSpec &depthSpec)
 
void ApplyMeasurements ()
 
void SetPositioningMode (PositioningMode positioningMode)
 
PositioningMode GetPositioningMode () const
 
void SetPadding (const Padding &padding)
 
const PaddingGetPadding () const
 
void SetUseReverseChildrenOrder (bool useReverseChildrenOrder)
 
bool IsUsingReverseChildrenOrder () const
 
void SetGravity (const glm::vec3 &layoutGravity)
 
void SetGravity (CYILayoutConfig::Gravity gravity)
 
const glm::vec3 & GetGravity () const
 

Protected Member Functions

virtual void Configure () override
 
virtual void ChildAdded (CYISceneNode *pChild) override
 
virtual void ApplyPosition (CYISceneNode *pNode, const glm::vec3 &position) override
 
- Protected Member Functions inherited from CYIStackLayout
virtual void OnMeasure (const CYISceneNode::MeasureSpec &widthSpec, const CYISceneNode::MeasureSpec &heightSpec, const CYISceneNode::MeasureSpec &depthSpec) override
 
virtual void OnApplyMeasurements () override
 
- Protected Member Functions inherited from CYIAnimatingLayout
virtual void OnMeasurementsApplied () override
 
virtual const CYIRuntimeTypeInfoGetLayoutConfigType () const override
 
virtual void ApplySize (CYISceneNode *pChild, const glm::vec3 &size) override
 
- Protected Member Functions inherited from CYILayout
virtual void OnSceneViewAttached ()
 
virtual void OnMeasurementsCalculated (const CYISceneNode::MeasureSpec &widthSpec, const CYISceneNode::MeasureSpec &heightSpec, const CYISceneNode::MeasureSpec &depthSpec)
 
virtual std::unique_ptr< CYILayoutStateCreateLayoutStateInstance () const
 
void CreateLayoutObjectsFor (CYISceneNode *pNode) const
 
CYISceneNodeGetChild (size_t index) const
 
void ApplyMeasurementsToBackgroundChildren ()
 
const PaddingGetPaddingForChild (const CYISceneNode *pChild) const
 

Additional Inherited Members

- Public Types inherited from CYILayout
enum  PositioningMode {
  PositioningMode::SetPositionDirectly,
  PositioningMode::DoNotSetPositionDirectly
}
 
typedef CYILayoutConfig::CubeOffset Padding
 
- Static Public Member Functions inherited from CYILayout
static void RegisterAllLayouts ()
 
static bool IsLayoutable (const CYISceneNode *pNode)
 
static glm::vec3 GetDefaultSize (const CYISceneNode *pNode, const CYISceneNode::MeasureSpec &widthSpec, const CYISceneNode::MeasureSpec &heightSpec, const CYISceneNode::MeasureSpec &depthSpec)
 
static void UpdateMeasuredSizeForFitContent (const CYISceneNode *pNode, glm::vec3 *pMeasuredSize, const glm::vec3 &contentSize, const Padding &padding, const CYISceneNode::MeasureSpec &widthSpec, const CYISceneNode::MeasureSpec &heightSpec, const CYISceneNode::MeasureSpec &depthSpec)
 
static void UnscaleMeasureSpecs (const glm::vec3 &scale, CYISceneNode::MeasureSpec *pWidthSpec, CYISceneNode::MeasureSpec *pHeightSpec, CYISceneNode::MeasureSpec *pDepthSpec)
 
static float CalculateDimension (const CYISceneNode::MeasureSpec &spec, const CYILayoutConfig::SizeConstraint &constraint, float currentValue)
 
- Protected Types inherited from CYILayout
enum  Dimensions {
  Dimensions::None = 0x0,
  Dimensions::X = 0x1,
  Dimensions::Y = 0x2,
  Dimensions::Z = 0x4,
  Dimensions::AllButX = Y | Z,
  Dimensions::AllButY = X | Z,
  Dimensions::AllButZ = X | Y,
  Dimensions::All = X | Y | Z
}
 
- Static Protected Member Functions inherited from CYILayout
static void MeasureChildWithMargins (CYISceneNode *pChild, const CYISceneNode::MeasureSpec &parentWidthSpec, const CYISceneNode::MeasureSpec &parentHeightSpec, const CYISceneNode::MeasureSpec &parentDepthSpec, const Padding &padding)
 
static void MeasureChildWithMargins (CYISceneNode *pChild, const CYISceneNode::MeasureSpec &parentWidthSpec, const CYISceneNode::MeasureSpec &parentHeightSpec, const CYISceneNode::MeasureSpec &parentDepthSpec, const Padding &padding, const glm::vec3 &childScale)
 
static CYISceneNode::MeasureSpec CalculateChildMeasureSpec (const CYISceneNode::MeasureSpec &parentMeasureSpec, float padding, const CYILayoutConfig::SizeConstraint &childConstraint, float childScale)
 
static bool UpdateMeasureSpecsForFitContent (const CYISceneNode *pNode, CYISceneNode::MeasureSpec *widthSpec, CYISceneNode::MeasureSpec *heightSpec, CYISceneNode::MeasureSpec *depthSpec)
 
static void RemeasureChildrenForFillParent (const CYISceneNode *pNode, const glm::vec3 &parentMeasuredSize, const Padding &padding, Dimensions dimensionsToRemeasure)
 
static glm::vec3 GetAdjustedPosition (const glm::vec3 &desiredTopLeftPosition, const CYISceneNode *pChild)
 
static glm::vec3 GetUnadjustedPosition (const glm::vec3 &currentTopLeftPosition, const CYISceneNode *pChild)
 
static glm::vec3 GetAdjustedMeasuredSize (const CYISceneNode *pChild)
 
static glm::vec3 GetTopLeftPositionWithGravity (const glm::vec3 &layoutGravity, const glm::vec3 &childGravity, const glm::vec3 &containerTopLeft, const glm::vec3 &containerSize, const CYILayout::Padding &padding, const glm::vec3 &childSize, const CYILayoutConfig::Margin &margin, const glm::vec3 &currentChildPosition)
 
static void MeasureBackgroundChildren (CYISceneNode *pNode, const glm::vec3 &size)
 
- Protected Attributes inherited from CYILayout
CYISceneViewm_pNode
 In most cases, this variable is used as a node (thus the name m_pNode ) More...
 
Padding m_padding
 
bool m_reverseChildrenOrder
 
glm::vec3 m_gravity
 
PositioningMode m_positioningMode
 

Constructor & Destructor Documentation

◆ CYIAutoLayout()

CYIAutoLayout::CYIAutoLayout ( )

◆ ~CYIAutoLayout()

virtual CYIAutoLayout::~CYIAutoLayout ( )
virtual

Member Function Documentation

◆ ApplyPosition()

virtual void CYIAutoLayout::ApplyPosition ( CYISceneNode pChild,
const glm::vec3 &  position 
)
overrideprotectedvirtual

Applies the position position to the scene node pChild. This function, by default, simply calls CYISceneNode::SetPosition. It can be overridden in subclasses to support animating position changes for child scene nodes.

Reimplemented from CYIAnimatingLayout.

◆ ChildAdded()

virtual void CYIAutoLayout::ChildAdded ( CYISceneNode pChild)
overrideprotectedvirtual

Called when a child (pChild) is added to the scene node associated with this layout instance.

Note
Subclasses that override this method must call the parent class' ChildAdded method.

Reimplemented from CYIAnimatingLayout.

◆ Configure()

virtual void CYIAutoLayout::Configure ( )
overrideprotectedvirtual

Extracts relevant properties the associated scene node and configures this layout with said properties.

Note
Subclasses should override this method if they have custom configuration values. Remember to call the parent Configure function.

Reimplemented from CYIAnimatingLayout.

◆ IsDetectingFillParent()

bool CYIAutoLayout::IsDetectingFillParent ( ) const

◆ SetDetectFillParent()

void CYIAutoLayout::SetDetectFillParent ( bool  detectFillParent)

Sets the 'detect fill parent' property to detectFillParent. When set to true, this layout will automatically set 'fill parent' on children whose dimensions are large enough.

Note
This property should be set prior to assigning the layout to a view, as the 'detect fill parent' property takes effect as soon as the layout is assigned.
See also
CYIAutoLayout

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