From c40cf93a02e67215d4853278deb88f13d5c65003 Mon Sep 17 00:00:00 2001 From: Francisco Santos Date: Wed, 17 Jan 2018 18:11:07 +0000 Subject: [PATCH] Don't set position or offset on image visuals with fitting mode FILL Change-Id: Id23268884f5a3587d5fb27132f03e2d19f70cb6d --- .../controls/image-view/image-view-impl.cpp | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/dali-toolkit/internal/controls/image-view/image-view-impl.cpp b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp index 7e1b7056f0..9af610b60e 100755 --- a/dali-toolkit/internal/controls/image-view/image-view-impl.cpp +++ b/dali-toolkit/internal/controls/image-view/image-view-impl.cpp @@ -262,44 +262,46 @@ void ImageView::OnRelayout( const Vector2& size, RelayoutContainer& container ) if( mVisual ) { - Extents padding; - padding = Self().GetProperty( Toolkit::Control::Property::PADDING ); - - Dali::LayoutDirection::Type layoutDirection = static_cast( - Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); + Property::Map transformMap = Property::Map(); - 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( 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( + Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); - 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 = - Toolkit::GetImplementation(mVisual).GetFittingMode() == Visual::FittingMode::FILL - ? paddedSize - : naturalSize * std::min((paddedSize.width / naturalSize.width), (paddedSize.height / naturalSize.height)); + // 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); - // populate the transform map - Property::Map transformMap = Property::Map(); + // scale to fit the padded area + auto finalSize = + naturalSize * std::min((paddedSize.width / naturalSize.width), (paddedSize.height / naturalSize.height)); - 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 + 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)); + + } // Should provide a transform that handles aspect ratio according to image size mVisual.SetTransformAndSize( transformMap, size ); } -- 2.34.1