#include <dali-toolkit/devel-api/image-loader/texture-manager.h>
#include <dali-toolkit/devel-api/visual-factory/visual-base.h>
#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <test-native-image.h>
#include <sstream>
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 ) );
+ 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( 15, 5, 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
+ DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliImageViewPaddingProperty02(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 "/Kid1.svg" ;
+ imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
+ imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
+ imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
+ 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 ) );
+ Stage::GetCurrent().Add( imageView );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), 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
+ DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), 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();
- // Don't transform if fitting mode is FILL
- if(Toolkit::GetImplementation(mVisual).GetFittingMode() == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO)
+ Extents 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 )
{
- Extents padding;
- padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
+ std::swap( padding.start, padding.end );
+ }
- Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(
- Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
+ auto finalOffset = Vector2( padding.start, padding.top );
- if (Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
- {
- std::swap(padding.start, padding.end);
- }
+ // remove padding from the size to know how much is left for the visual
+ auto finalSize = size - Vector2( padding.start + padding.end, padding.top + padding.bottom );
- // 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);
+ // Should provide a transform that handles aspect ratio according to image size
+ if( Toolkit::GetImplementation(mVisual).GetFittingMode() == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO )
+ {
+ auto availableVisualSize = finalSize;
Vector2 naturalSize;
- mVisual.GetNaturalSize(naturalSize);
+ mVisual.GetNaturalSize( naturalSize );
// 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 ) );
+ finalSize = naturalSize * std::min( ( naturalSize.width ? ( availableVisualSize.width / naturalSize.width ) : 0 ),
+ ( naturalSize.height ? ( availableVisualSize.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));
-
+ finalOffset += ( availableVisualSize - finalSize ) * .5f;
}
- // Should provide a transform that handles aspect ratio according to image size
+
+ // 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 ) );
+
mVisual.SetTransformAndSize( transformMap, size );
}
}
}
}
-/**
- * @brief Sets Control::Property::BACKGROUND visual
- * @param[in] controlImpl The control implementation
- * @param[in] visual The control background visual
- * @param[in] size The current size
- */
-void SetBackgroundVisual( Control::Impl& controlImpl, Toolkit::Visual::Base& visual, const Vector2& size )
-{
- Property::Map transformMap = Property::Map();
-
- 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, 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, newSize ); // Send an empty map as we do not want to modify the visual's set transform
-}
-
} // unnamed namespace
if( visual )
{
Vector2 size( targetSize );
- SetBackgroundVisual( *mImpl, visual, size );
-
+ visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
}
}
Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND );
if( visual )
{
- SetBackgroundVisual( *mImpl, visual, size );
+ visual.SetTransformAndSize( Property::Map(), size ); // Send an empty map as we do not want to modify the visual's set transform
}
}