END_TEST;
}
-
-int UtcDaliImageViewPaddingProperty(void)
-{
- ToolkitTestApplication application;
-
- ImageView imageView = ImageView::New();
- Property::Map imagePropertyMap;
- imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
- imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
- imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
- imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
- imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
- imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
- imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
- imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
- imageView.SetProperty( Control::Property::MARGIN, Extents( 10, 10, 10, 10 ) );
- Stage::GetCurrent().Add( imageView );
-
- application.SendNotification();
- application.Render();
-
- DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
-
- ImageView childImage = ImageView::New();
- childImage.SetBackgroundColor( Color::BLACK );
- childImage.SetSize( 10.f, 10.f );
- imageView.Add( childImage );
-
- application.SendNotification();
- application.Render();
-
- // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
- DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 25, 15, 0 ), TEST_LOCATION );
-
- // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
- Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
- Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
- Property::Map resultMap;
- imageVisual.CreatePropertyMap( resultMap );
-
- Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
- DALI_TEST_CHECK( transformValue );
- Property::Map* retMap = transformValue->GetMap();
- DALI_TEST_CHECK( retMap );
-
- // Image Visual should be positioned depending on ImageView's padding and margin
- DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 25, 15 ), TEST_LOCATION );
-
- END_TEST;
-}
void Control::Impl::SetMargin( Extents margin )
{
mControlImpl.mImpl->mMargin = margin;
-
- // Trigger a size negotiation request that may be needed when setting a margin.
- mControlImpl.RelayoutRequest();
}
Extents Control::Impl::GetMargin() const
void Control::Impl::SetPadding( Extents padding )
{
mControlImpl.mImpl->mPadding = padding;
-
- // Trigger a size negotiation request that may be needed when setting a padding.
- mControlImpl.RelayoutRequest();
}
Extents Control::Impl::GetPadding() const
{
Property::Map transformMap = Property::Map();
- Extents padding;
- padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
-
- Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
- Self().GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get<int>() );
-
- if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection )
+ // Don't transform if fitting mode is FILL
+ if(Toolkit::GetImplementation(mVisual).GetFittingMode() == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO)
{
- std::swap( padding.start, padding.end );
- }
+ Extents padding;
+ padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
- // remove padding from the size to know how much is left for the visual
- auto paddedSize = size - Vector2( padding.start + padding.end, padding.top + padding.bottom );
+ Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
+ Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
- Vector2 naturalSize;
- mVisual.GetNaturalSize( naturalSize );
+ if (Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
+ {
+ std::swap(padding.start, padding.end);
+ }
- // scale to fit the padded area
- auto finalSize =
- naturalSize * std::min( ( naturalSize.width ? ( paddedSize.width / naturalSize.width ) : 0 ),
- ( naturalSize.height ? ( paddedSize.height / naturalSize.height ) : 0 ) );
+ // remove padding from the size to know how much is left for the visual
+ auto paddedSize = size - Vector2(padding.start + padding.end, padding.top + padding.bottom);
- // calculate final offset within the padded area
- auto finalOffset = Vector2( padding.start, padding.top ) + ( paddedSize - finalSize ) * .5f;
+ Vector2 naturalSize;
+ mVisual.GetNaturalSize(naturalSize);
- // When set the margin on ImageView, the visual should be repositioned.
- Extents margin = Self().GetProperty<Extents>( Toolkit::Control::Property::MARGIN );
- if( ( margin.start != 0 ) || ( margin.end != 0 ) || ( margin.top != 0 ) || ( margin.bottom != 0 ) )
- {
- if( Self().GetCurrentAnchorPoint() != AnchorPoint::CENTER )
- {
- finalOffset.x += margin.start;
- finalOffset.y += margin.top;
- }
- }
+ // scale to fit the padded area
+ auto finalSize =
+ naturalSize * std::min( ( naturalSize.width ? ( paddedSize.width / naturalSize.width ) : 0 ),
+ ( naturalSize.height ? ( paddedSize.height / naturalSize.height ) : 0 ) );
+
+ // calculate final offset within the padded area
+ auto finalOffset = Vector2(padding.start, padding.top) + (paddedSize - finalSize) * .5f;
- // populate the transform map
- transformMap.Add( Toolkit::Visual::Transform::Property::OFFSET, finalOffset )
- .Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY,
- Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
- .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
- .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN )
- .Add( Toolkit::Visual::Transform::Property::SIZE, finalSize )
- .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY,
- Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) );
+ // populate the transform map
+ transformMap.Add(Toolkit::Visual::Transform::Property::OFFSET, finalOffset)
+ .Add(Toolkit::Visual::Transform::Property::OFFSET_POLICY,
+ Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE))
+ .Add(Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN)
+ .Add(Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN)
+ .Add(Toolkit::Visual::Transform::Property::SIZE, finalSize)
+ .Add(Toolkit::Visual::Transform::Property::SIZE_POLICY,
+ Vector2(Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE));
+ }
// Should provide a transform that handles aspect ratio according to image size
mVisual.SetTransformAndSize( transformMap, size );
}
{
Property::Map transformMap = Property::Map();
- if( ( ( controlImpl.mMargin.start != 0 ) ||
- ( controlImpl.mMargin.end != 0 ) ||
- ( controlImpl.mMargin.top != 0 ) ||
- ( controlImpl.mMargin.bottom != 0 ) ) &&
- ( controlImpl.mControlImpl.Self().GetCurrentAnchorPoint() != AnchorPoint::CENTER ) )
+ Vector2 newSize( 0.f, 0.f );
+ newSize.width = size.width + ( controlImpl.mPadding.start + controlImpl.mPadding.end );
+ newSize.height = size.height + ( controlImpl.mPadding.top + controlImpl.mPadding.bottom );
+
+ if( ( controlImpl.mMargin.start != 0 ) ||
+ ( controlImpl.mMargin.end != 0 ) ||
+ ( controlImpl.mMargin.top != 0 ) ||
+ ( controlImpl.mMargin.bottom != 0 ) )
{
- transformMap.Add( Toolkit::Visual::Transform::Property::SIZE, size )
+ transformMap.Add( Toolkit::Visual::Transform::Property::SIZE, newSize )
.Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
.Add( Toolkit::Visual::Transform::Property::OFFSET, Vector2( controlImpl.mMargin.start, controlImpl.mMargin.top ) )
.Add( Toolkit::Visual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
.Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
.Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
}
+ else if( ( controlImpl.mPadding.start != 0 ) ||
+ ( controlImpl.mPadding.end != 0 ) ||
+ ( controlImpl.mPadding.top != 0 ) ||
+ ( controlImpl.mPadding.bottom != 0 ) )
+ {
+ transformMap.Add( Toolkit::Visual::Transform::Property::SIZE, newSize )
+ .Add( Toolkit::Visual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::Visual::Transform::Policy::ABSOLUTE, Toolkit::Visual::Transform::Policy::ABSOLUTE ) )
+ .Add( Toolkit::Visual::Transform::Property::ORIGIN, Toolkit::Align::TOP_BEGIN )
+ .Add( Toolkit::Visual::Transform::Property::ANCHOR_POINT, Toolkit::Align::TOP_BEGIN );
+ }
- visual.SetTransformAndSize( transformMap, size ); // Send an empty map as we do not want to modify the visual's set transform
+ visual.SetTransformAndSize( transformMap, newSize ); // Send an empty map as we do not want to modify the visual's set transform
}
} // unnamed namespace