-struct ScaleToFillConstraint
-{
- /**
- * @param padding to be added.
- */
- ScaleToFillConstraint( const Toolkit::Alignment::Padding& padding )
- : mPadding( padding )
- {}
-
- /**
- * Called by render thread
- */
- Vector3 operator()( const Vector3& currentSize,
- const PropertyInput& parentSizeProperty )
- {
- const Vector3& parentSize( parentSizeProperty.GetVector3() );
- return GetSize( currentSize, parentSize );
- }
-
- inline Vector3 GetSize( const Vector3& currentSize, const Vector3& parentSize )
- {
- const float parentSizeWidth = parentSize.width - ( mPadding.left + mPadding.right );
- const float parentSizeHeight = parentSize.height - ( mPadding.top + mPadding.bottom );
-
- // prevent ridiculous sizes if parent is really small or if we don't have a proper size for the actor
- if( ( parentSizeWidth < Math::MACHINE_EPSILON_1000 ) || ( parentSizeHeight < Math::MACHINE_EPSILON_1000 ) )
- {
- // no point trying to squeeze actors into this small size
- return Vector3::ZERO;
- }
- return Vector3( parentSizeWidth, parentSizeHeight, parentSize.depth );
- }
-
- const Toolkit::Alignment::Padding mPadding;
-};
-
-struct ScaleToFitKeepAspectConstraint
-{
- /**
- * @param padding to be added.
- */
- ScaleToFitKeepAspectConstraint( const Toolkit::Alignment::Padding& padding )
- : mPadding( padding ),
- mSizeStored( false ),
- mOriginalSize()
- {}
-
- /**
- * Called by render thread
- */
- Vector3 operator()( const Vector3& currentSize,
- const PropertyInput& parentSizeProperty )
- {
- const Vector3& parentSize( parentSizeProperty.GetVector3() );
- return GetSize( currentSize, parentSize );
- }
-
- inline Vector3 GetSize( const Vector3& currentSize, const Vector3& parentSize )
- {
- if( ( !mSizeStored ) && ( Vector3::ZERO != currentSize ) )
- {
- mOriginalSize = currentSize;
- mSizeStored = true;
- }
-
- const float parentSizeWidth = parentSize.width - ( mPadding.left + mPadding.right );
- const float parentSizeHeight = parentSize.height - ( mPadding.top + mPadding.bottom );
-
- // prevent ridiculous sizes if parent is really small or if we don't have a proper size for the actor
- if( ( parentSizeWidth < Math::MACHINE_EPSILON_1000 ) || ( parentSizeHeight < Math::MACHINE_EPSILON_1000 )||
- ( mOriginalSize.width < Math::MACHINE_EPSILON_1000 ) || ( mOriginalSize.height < Math::MACHINE_EPSILON_1000 ) )
- {
- // no point trying to squeeze actors into this small size
- return Vector3::ZERO;
- }
-
- return mOriginalSize * std::min( ( parentSizeWidth / mOriginalSize.width ), ( parentSizeHeight / mOriginalSize.height ) );
- }
-
- const Toolkit::Alignment::Padding mPadding;
- bool mSizeStored;
- Vector3 mOriginalSize;
-};
-
-struct ScaleToFillKeepAspectConstraint
-{
- /**
- * @param padding to be added.
- */
- ScaleToFillKeepAspectConstraint( const Toolkit::Alignment::Padding& padding )
- : mPadding( padding ),
- mSizeStored( false ),
- mOriginalSize()
- { }
-
- /**
- * Called by render thread
- */
- Vector3 operator()( const Vector3& currentSize,
- const PropertyInput& parentSizeProperty )
- {
- const Vector3& parentSize( parentSizeProperty.GetVector3() );
- return GetSize( currentSize, parentSize );
- }
-
- Vector3 GetSize( const Vector3& currentSize, const Vector3& parentSize )
- {
- if( ( !mSizeStored ) && ( Vector3::ZERO != currentSize ) )
- {
- mOriginalSize = currentSize;
- mSizeStored = true;
- }
-
- const float parentSizeWidth = parentSize.width - ( mPadding.left + mPadding.right );
- const float parentSizeHeight = parentSize.height - ( mPadding.top + mPadding.bottom );
-
- // prevent ridiculous sizes if parent is really small or if we don't have a proper size for the actor
- if( ( parentSizeWidth < Math::MACHINE_EPSILON_1000 ) || ( parentSizeHeight < Math::MACHINE_EPSILON_1000 )||
- ( mOriginalSize.width < Math::MACHINE_EPSILON_1000 ) || ( mOriginalSize.height < Math::MACHINE_EPSILON_1000 ) )
- {
- // no point trying to squeeze actors into this small size
- return Vector3::ZERO;
- }
-
- return mOriginalSize * std::max( ( parentSizeWidth / mOriginalSize.width ), ( parentSizeHeight / mOriginalSize.height ) );
- }
-
- const Toolkit::Alignment::Padding mPadding;
- bool mSizeStored;
- Vector3 mOriginalSize;
-};
-
-struct ShrinkToFitConstraint
-{
- /**
- * @param padding to be added.
- */
- ShrinkToFitConstraint( const Toolkit::Alignment::Padding& padding )
- : mPadding( padding ),
- mSizeStored( false ),
- mOriginalSize()
- {}
-
- /**
- * Called by render thread
- */
- Vector3 operator()( const Vector3& currentSize,
- const PropertyInput& parentSizeProperty )
- {
- const Vector3& parentSize( parentSizeProperty.GetVector3() );
- return GetSize( currentSize, parentSize );
- }
-
- Vector3 GetSize( const Vector3& currentSize, const Vector3& parentSize )
- {
- if( ( !mSizeStored ) && ( Vector3::ZERO != currentSize ) )
- {
- mOriginalSize = currentSize;
- mSizeStored = true;
- }
-
- const float parentSizeWidth = parentSize.width - ( mPadding.left + mPadding.right );
- const float parentSizeHeight = parentSize.height - ( mPadding.top + mPadding.bottom );
-
- // prevent ridiculous sizes if parent is really small or if we don't have a proper size for the actor
- if( ( parentSizeWidth < Math::MACHINE_EPSILON_1000 ) || ( parentSizeHeight < Math::MACHINE_EPSILON_1000 )||
- ( mOriginalSize.width < Math::MACHINE_EPSILON_1000 ) || ( mOriginalSize.height < Math::MACHINE_EPSILON_1000 ) )
- {
- // no point trying to squeeze actors into this small size
- return Vector3::ZERO;
- }
-
- return Vector3( std::min( parentSizeWidth, mOriginalSize.width ), std::min( parentSizeHeight, mOriginalSize.height ), std::min( parentSize.depth, mOriginalSize.depth ) );
- }
-
- const Toolkit::Alignment::Padding mPadding;
- bool mSizeStored;
- Vector3 mOriginalSize;
-};
-
-/**
- * Constraint that uses naturalSize if it fits inside parent and parent size if not. It also adds some padding pixels
- */
-struct ShrinkToFitKeepAspectConstraint
-{
- /**
- * @param padding to be added.
- */
- ShrinkToFitKeepAspectConstraint( const Toolkit::Alignment::Padding& padding )
- : mPadding( padding ),
- mSizeStored( false ),
- mOriginalSize()
- {}
-
- /**
- * Called by render thread
- */
- Vector3 operator()( const Vector3& currentSize,
- const PropertyInput& parentSizeProperty )
- {
- const Vector3& parentSize( parentSizeProperty.GetVector3() );
- return GetSize( currentSize, parentSize );
- }
-
- inline Vector3 GetSize( const Vector3& currentSize, const Vector3& parentSize )
- {
- if( ( !mSizeStored ) && ( Vector3::ZERO != currentSize ) )
- {
- mOriginalSize = currentSize;
- mSizeStored = true;
- }
-
- const float parentSizeWidth = parentSize.width - ( mPadding.left + mPadding.right );
- const float parentSizeHeight = parentSize.height - ( mPadding.top + mPadding.bottom );
-
- // prevent ridiculous sizes if parent is really small or if we don't have a proper size for the actor
- if( ( parentSizeWidth < Math::MACHINE_EPSILON_1000 ) || ( parentSizeHeight < Math::MACHINE_EPSILON_1000 )||
- ( mOriginalSize.width < Math::MACHINE_EPSILON_1000 ) || ( mOriginalSize.height < Math::MACHINE_EPSILON_1000 ) )
- {
- // no point trying to squeeze actors into this small size
- return Vector3::ZERO;
- }
-
- return Vector3( ShrinkInside( Vector2( parentSizeWidth, parentSizeHeight ), Vector2( mOriginalSize ) ) );
- }
-
- const Toolkit::Alignment::Padding mPadding;
- bool mSizeStored;
- Vector3 mOriginalSize;
-};
-