void Impl::DummyControl::OnRelayout( const Vector2& size, RelayoutContainer& container )
{
+ if ( mRelayoutCallback )
+ {
+ mRelayoutCallback( size ); // Execute callback if set
+ }
+
Property::Map emptyMap;
for( VisualIndices::iterator iter = mRegisteredVisualIndices.begin(); iter != mRegisteredVisualIndices.end() ; ++iter )
}
}
+void Impl::DummyControl::SetRelayoutCallback( RelayoutCallbackFunc callback )
+{
+ mRelayoutCallback = callback;
+}
+
+
DummyControl DummyControl::New( bool override )
{
DummyControl control;
// INTERNAL INCLUDES
#include <dali-toolkit/dali-toolkit.h>
+// EXTERNAL INCLUDES
+#include <functional>
+
namespace Dali
{
{
public:
+ typedef std::function<void( Size )> RelayoutCallbackFunc;
+
static Toolkit::DummyControl New();
void SetLayout( Property::Index visualIndex, Property::Map& map );
+ void SetRelayoutCallback( RelayoutCallbackFunc callback );
+
private:
DummyControl();
bool keyInputFocusLost;
Property::Map mLayouts;
+ RelayoutCallbackFunc mRelayoutCallback;
+
};
} // namespace Impl
#include <sstream>
#include <unistd.h>
+#include "dummy-control.h"
+
using namespace Dali;
using namespace Toolkit;
}
bool gResourceReadySignalFired = false;
+Vector3 gNaturalSize;
void ResourceReadySignal( Control control )
{
END_TEST;
}
+
+void OnRelayoutOverride( Size size )
+{
+ gNaturalSize = size; // Size Relayout is using
+}
+
+int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
+{
+ ToolkitTestApplication application;
+
+ // Check ImageView with background and main image, to ensure both visuals are marked as loaded
+ ImageView imageView = ImageView::New( TEST_IMAGE_1 );
+ imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+
+ DummyControl dummyControl = DummyControl::New( true );
+ Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+ dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
+
+ dummyControl.Add( imageView );
+ dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
+ Stage::GetCurrent().Add( dummyControl );
+
+ application.SendNotification();
+ application.Render();
+
+ // loading started, this waits for the loader thread for max 30 seconds
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
+ DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
+
+ gNaturalSize = Vector3::ZERO;
+
+ imageView.SetImage(gImage_600_RGB);
+
+ // Waiting for resourceReady so SendNotifcation not called here.
+
+ // loading started, this waits for the loader thread for max 30 seconds
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ // Trigger a potential relayout
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
+ DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
+
+ END_TEST;
+}
* by a control are loaded and ready.
* Most resources are only loaded when the control is placed on stage.
*
+ * @note A RelayoutRequest is queued by Control before this signal is emitted
+ *
* A callback of the following type may be connected:
* @code
* void YourCallbackName( Control control );
using namespace Dali;
ImageView::ImageView()
-: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ),
- mRelayoutRequired(true)
+: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) )
{
}
mPropertyMap = map;
mUrl.clear();
mImage.Reset();
- mRelayoutRequired = true;
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.
mUrl = url;
mImage.Reset();
mPropertyMap.Clear();
- mRelayoutRequired = true;
// 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 );
{
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
{
// Visual ready so update visual attached to this ImageView, following call to RelayoutRequest will use this visual.
mVisual = DevelControl::GetVisual( *this, Toolkit::ImageView::Property::IMAGE );
-
- if( mRelayoutRequired)
- {
- mRelayoutRequired = false;
- RelayoutRequest();
- }
}
///////////////////////////////////////////////////////////
std::string mUrl; ///< the url for the image if the image came from a URL, empty otherwise
Image mImage; ///< the Image if the image came from a Image, null otherwise
Property::Map mPropertyMap; ///< the Property::Map if the image came from a Property::Map, empty otherwise
- bool mRelayoutRequired; ///< True if relayout is required, e.g. due to unreadiness
};
} // namespace Internal