/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
END_TEST;
}
+int UtcDaliImageViewFillMode(void)
+{
+ ToolkitTestApplication application;
+
+ tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
+ tet_infoline( " There should be no need to change the transform, our size-policy should be relative and size shoudl be [1,1]");
+
+ ImageView imageView = ImageView::New();
+ Property::Map imageMap;
+ imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
+ imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB );
+ imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL );
+
+ imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
+
+ Stage::GetCurrent().Add( imageView );
+
+ // Trigger a potential relayout
+ application.SendNotification();
+ application.Render();
+
+ Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
+ Property::Map returnedMap;
+ visual.CreatePropertyMap( returnedMap );
+
+ Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
+ DALI_TEST_CHECK( value );
+ Property::Map* map = value->GetMap();
+ DALI_TEST_CHECK( map );
+
+ // If there's
+ value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Relative size so will take up 100%
+
+ value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
+ DALI_TEST_CHECK( value );
+ DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
+
+ END_TEST;
+}
Property::Map transformMap = Property::Map();
Extents padding = Self().GetProperty<Extents>( Toolkit::Control::Property::PADDING );
+ const Visual::FittingMode fittingMode = Toolkit::GetImplementation(mVisual).GetFittingMode();
- 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 )
+ if( ( padding != Extents() ) || // If padding is not zero
+ ( fittingMode == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO ) )
{
- 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 );
+ auto finalOffset = Vector2( padding.start, padding.top );
- // 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;
+ // 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 );
- Vector2 naturalSize;
- mVisual.GetNaturalSize( naturalSize );
+ // Should provide a transform that handles aspect ratio according to image size
+ if( fittingMode == Visual::FittingMode::FIT_KEEP_ASPECT_RATIO )
+ {
+ auto availableVisualSize = finalSize;
- // scale to fit the padded area
- finalSize = naturalSize * std::min( ( naturalSize.width ? ( availableVisualSize.width / naturalSize.width ) : 0 ),
- ( naturalSize.height ? ( availableVisualSize.height / naturalSize.height ) : 0 ) );
+ Vector2 naturalSize;
+ mVisual.GetNaturalSize( naturalSize );
- // calculate final offset within the padded area
- finalOffset += ( availableVisualSize - finalSize ) * .5f;
- }
+ // scale to fit the padded area
+ finalSize = naturalSize * std::min( ( naturalSize.width ? ( availableVisualSize.width / naturalSize.width ) : 0 ),
+ ( naturalSize.height ? ( availableVisualSize.height / naturalSize.height ) : 0 ) );
- // 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 ) );
+ // calculate final offset within the padded area
+ finalOffset += ( availableVisualSize - 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 ) );
+ }
mVisual.SetTransformAndSize( transformMap, size );
}