You.i Engine
CYIScalingLayout Class Reference

Detailed Description

A layout that scales its children to fill their container.

This layout behaves like a CYIStackLayout, but with one major difference: after the children have been measured, this layout sets, on the children, a scaling factor that would cause the children to 'fill' their container. The 'scale mode' property can be used to specify how the children are scaled.

It is not necessary to set 'fill parent' on the children of this layout in order for the children to be scaled. However, setting 'fill parent' on the children modifies the behaviour of the scaling layout. If 'fill parent' is set on both the horizontal and vertical dimensions of a child, then no scaling is applied to that child. If 'fill parent' is applied to either of the horizontal or vertical dimensions of a child, then the child is resized to fill the parent in that dimension and the scaling layout will scale that calculated size. As a result, the 'fit' and 'fill' scaling modes have no effect when 'fill parent' is specified on a single dimension of a child.

The 'fit content' property can be specified on the layout. When 'fit content' is specified on both the horizontal and vertical dimensions, it results in a minimally-sized container. When used on a single dimension, the container is expanded to reduce the 'empty spaces' after scaling the children.

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
scale-mode stretch stretch, fit, fill, none The scaling mode for the children.
See also
CYIScalingLayout::ScaleMode

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

See also
CYIStackLayout

Children View Template Comments Specification

Note
Margins specified on children are in composition units, and thus do not get scaled along with the children.
Children marked as 'background' get measured normally and do not get scaled.

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

See also
CYIStackLayout

#include <layout/YiScalingLayout.h>

Inheritance diagram for CYIScalingLayout:

Public Types

enum  ScaleMode {
  ScaleMode::None,
  ScaleMode::Stretch,
  ScaleMode::Fit,
  ScaleMode::Fill
}
 
- Public Types inherited from CYILayout
enum  PositioningMode {
  PositioningMode::SetPositionDirectly,
  PositioningMode::DoNotSetPositionDirectly
}
 
typedef CYILayoutConfig::CubeOffset Padding
 

Public Member Functions

 CYIScalingLayout ()
 
virtual ~CYIScalingLayout ()
 
void SetScalingMode (ScaleMode mode)
 
ScaleMode GetScalingMode () 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 ChildAdded (CYISceneNode *pChild) override
 
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 OnMeasure (const CYISceneNode::MeasureSpec &widthSpec, const CYISceneNode::MeasureSpec &heightSpec, const CYISceneNode::MeasureSpec &depthSpec) override
 
virtual void OnApplyMeasurements () override
 
virtual void ApplyScale (CYISceneNode *pChild, const glm::vec3 &scale)
 
- Protected Member Functions inherited from CYIAnimatingLayout
virtual void OnMeasurementsApplied () override
 
virtual const CYIRuntimeTypeInfoGetLayoutConfigType () const override
 
virtual void ApplyPosition (CYISceneNode *pChild, const glm::vec3 &position) 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

- 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
 

Member Enumeration Documentation

◆ ScaleMode

The various possible scaling modes for this layout.

Enumerator
None 

Causes the children to be given a scale of 1.0.

Stretch 

Causes the children to stretch to fill the container.

Fit 

Causes the children to proportionally scale to fit the container. The aspect ratio of the children is preserved. Empty space may be left on the edges of the container.

Fill 

Causes the children to proportionally scale to fill the container. The children may overflow out of the container in order to preserve their aspect ratio.

Constructor & Destructor Documentation

◆ CYIScalingLayout()

CYIScalingLayout::CYIScalingLayout ( )

◆ ~CYIScalingLayout()

virtual CYIScalingLayout::~CYIScalingLayout ( )
virtual

Member Function Documentation

◆ ApplyScale()

virtual void CYIScalingLayout::ApplyScale ( CYISceneNode pChild,
const glm::vec3 &  scale 
)
protectedvirtual

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

◆ Configure()

virtual void CYIScalingLayout::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.

◆ GetScalingMode()

ScaleMode CYIScalingLayout::GetScalingMode ( ) const

◆ OnApplyMeasurements()

virtual void CYIScalingLayout::OnApplyMeasurements ( )
overrideprotectedvirtual

Applies the measured sizes of the associate scene node's children.

Warning
Implementations of this function are required to ensure that the ApplyMeasurements function of each child node is called at least once, even if those children are hidden or are non-laid-out.
Note
Typically, if OnApplyMeasurements is overridden then OnMeasure must also be overridden.
See also
CYILayout::ApplyMeasurements

Reimplemented from CYIStackLayout.

◆ OnMeasure()

virtual void CYIScalingLayout::OnMeasure ( const CYISceneNode::MeasureSpec widthSpec,
const CYISceneNode::MeasureSpec heightSpec,
const CYISceneNode::MeasureSpec depthSpec 
)
overrideprotectedvirtual

Measures the associated scene node, considering its layout configuration constraints (if available) and the provided measure specifications.

Warning
Implementations of this function are required to ensure that the Measure function of each child scene node is called at least once, even if those children are hidden or are non-laid-out.
Note
Typically, if OnMeasure is overridden then OnApplyMeasurements must also be overridden.
See also
CYILayout::Measure

Reimplemented from CYIStackLayout.

◆ SetScalingMode()

void CYIScalingLayout::SetScalingMode ( ScaleMode  mode)

Sets the scaling mode to mode.


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