-// Copyright (c) 2016 Samsung Electronics Co., Ltd.
+/*
+ * Copyright (c) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
// CLASS HEADER
#include "image-view-impl.h"
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/internal/visuals/visual-string-constants.h>
using namespace Dali;
ImageView::ImageView()
-: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) )
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
+ mRelayoutRequired(true)
{
}
/////////////////////////////////////////////////////////////
+void ImageView::OnInitialize()
+{
+ // ImageView can relayout in the OnImageReady, alternative to a signal would be to have a upcall from the Control to ImageView
+ Dali::Toolkit::Control handle( GetOwner() );
+ Toolkit::DevelControl::ResourceReadySignal( handle ).Connect( this, &ImageView::OnResourceReady );
+}
+
void ImageView::SetImage( Image image )
{
// Don't bother comparing if we had a visual previously, just drop old visual and create new one
mUrl.clear();
mPropertyMap.Clear();
- mVisual = Toolkit::VisualFactory::Get().CreateVisual( image );
- RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual );
+ Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( image );
+ if (!mVisual)
+ {
+ mVisual = visual;
+ }
- RelayoutRequest();
+ DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual );
}
void ImageView::SetImage( const Property::Map& map )
mPropertyMap = map;
mUrl.clear();
mImage.Reset();
+ Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap );
+ // Don't set mVisual until it is ready and shown. Getters will still use current visual.
+ if (!mVisual)
+ {
+ mVisual = visual;
+ }
- mVisual = Toolkit::VisualFactory::Get().CreateVisual( mPropertyMap );
- RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual );
-
- RelayoutRequest();
+ DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual );
}
void ImageView::SetImage( const std::string& url, ImageDimensions size )
mImage.Reset();
mPropertyMap.Clear();
- mVisual = Toolkit::VisualFactory::Get().CreateVisual( url, size );
- RegisterVisual( Toolkit::ImageView::Property::IMAGE, mVisual );
+ // Don't set mVisual until it is ready and shown. Getters will still use current visual.
+ Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( url, size );
+ if (!mVisual)
+ {
+ mVisual = visual;
+ }
- RelayoutRequest();
+ DevelControl::RegisterVisual( *this, Toolkit::ImageView::Property::IMAGE, visual );
}
Image ImageView::GetImage() const
{
Control::OnRelayout( size, container );
+ // If visual is being replaced then mVisual will be the replacement visual even if not ready.
+ mVisual = DevelControl::GetVisual( *this, Toolkit::ImageView::Property::IMAGE );
+
if( mVisual )
{
// Pass in an empty map which uses default transform values meaning our visual fills the control
}
}
+void ImageView::OnResourceReady( Toolkit::Control control )
+{
+ if( mRelayoutRequired)
+ {
+ mRelayoutRequired = false;
+ RelayoutRequest();
+ }
+}
+
///////////////////////////////////////////////////////////
//
// Properties