From 9fbfb29c51bb28cd57b4b89fd5ac837ca10bafe8 Mon Sep 17 00:00:00 2001 From: Kingsley Stephens Date: Wed, 25 Feb 2015 10:34:11 +0000 Subject: [PATCH] Size negotiation example Change-Id: Iffcdd6753c39fa83e7f68ef927339374bc0061a2 --- com.samsung.dali-demo.xml | 5 +- demo/dali-demo.cpp | 6 +- demo/dali-table-view.cpp | 265 ++-- demo/dali-table-view.h | 24 +- .../animated-shapes/animated-shapes-example.cpp | 1 + examples/blocks/blocks-example.cpp | 5 +- examples/builder/examples.cpp | 4 + examples/buttons/buttons-example.cpp | 41 +- examples/cluster/cluster-example.cpp | 13 +- .../cube-transition-effect-example.cpp | 2 + .../image-scaling-irregular-grid-example.cpp | 3 +- examples/item-view/item-view-example.cpp | 35 +- examples/logging/logging-example.cpp | 8 +- examples/magnifier/magnifier-example.cpp | 3 + examples/page-turn-view/page-turn-view-example.cpp | 17 +- examples/path-animation/path-animation.cpp | 5 + examples/scroll-view/scroll-view-example.cpp | 8 +- .../shadow-bone-lighting-example.cpp | 3 +- .../size-negotiation/size-negotiation-example.cpp | 1346 ++++++++++++++++++++ examples/text-view/text-view-example.cpp | 14 +- resources/scripts/animated-buttons.json | 33 +- resources/scripts/animated-colors.json | 23 + resources/scripts/animation.json | 1 + resources/scripts/background-color.json | 3 + shared/view.h | 19 +- 25 files changed, 1696 insertions(+), 191 deletions(-) create mode 100644 examples/size-negotiation/size-negotiation-example.cpp diff --git a/com.samsung.dali-demo.xml b/com.samsung.dali-demo.xml index 028ee55..3b1aa48 100644 --- a/com.samsung.dali-demo.xml +++ b/com.samsung.dali-demo.xml @@ -68,7 +68,7 @@ - + @@ -85,4 +85,7 @@ + + + diff --git a/demo/dali-demo.cpp b/demo/dali-demo.cpp index a2741e8..31ddbd0 100644 --- a/demo/dali-demo.cpp +++ b/demo/dali-demo.cpp @@ -39,11 +39,15 @@ int main(int argc, char **argv) demo.AddExample(Example("refraction-effect.example", "Refraction")); demo.AddExample(Example("scroll-view.example", "Scroll View")); demo.AddExample(Example("shadow-bone-lighting.example", "Lights and shadows")); - demo.AddExample(Example("builder.example", "Script Based UI")); +// demo.AddExample(Example("builder.example", "Script Based UI")); demo.AddExample(Example("image-scaling-irregular-grid.example", "Image Scaling Modes")); demo.AddExample(Example("text-view.example", "Text View")); demo.AddExample(Example("animated-shapes.example", "Animated Shapes")); demo.AddExample(Example("path-animation.example", "Path Animation")); + demo.AddExample(Example("size-negotiation.example", "Size Negotiation")); + + demo.SortAlphabetically( true ); + app.MainLoop(); return 0; diff --git a/demo/dali-table-view.cpp b/demo/dali-table-view.cpp index bb7bc7c..c825afe 100644 --- a/demo/dali-table-view.cpp +++ b/demo/dali-table-view.cpp @@ -55,10 +55,10 @@ const int MAX_PAGES = 256; ///< Maximum pag const int EXAMPLES_PER_ROW = 3; const int ROWS_PER_PAGE = 3; const int EXAMPLES_PER_PAGE = EXAMPLES_PER_ROW * ROWS_PER_PAGE; -const float LOGO_MARGIN_RATIO = 0.5f / 0.9f; +const float LOGO_MARGIN_RATIO = 0.1f / 0.3f; const float BOTTOM_PADDING_RATIO = 0.4f / 0.9f; const Vector3 SCROLLVIEW_RELATIVE_SIZE(0.9f, 1.0f, 0.8f ); ///< ScrollView's relative size to its parent -const Vector3 TABLE_RELATIVE_SIZE(0.9f, 0.9f, 0.8f ); ///< TableView's relative size to the entire stage. The Y value means sum of the logo and table relative heights. +const Vector3 TABLE_RELATIVE_SIZE(0.95f, 0.9f, 0.8f ); ///< TableView's relative size to the entire stage. The Y value means sum of the logo and table relative heights. const float STENCIL_RELATIVE_SIZE = 1.0f; const float EFFECT_SNAP_DURATION = 0.66f; ///< Scroll Snap Duration for Effects @@ -75,7 +75,6 @@ const float SCALE_SPEED_SIN = 0.1f; const unsigned int BACKGROUND_ANIMATION_DURATION = 15000; // 15 secs const float BACKGROUND_Z = -1.0f; -const float BACKGROUND_SIZE_SCALE = 1.0f; const Vector4 BACKGROUND_COLOR( 1.0f, 1.0f, 1.0f, 1.0f ); const float BUBBLE_MIN_Z = -1.0; @@ -124,10 +123,11 @@ ImageActor CreateBackground( std::string imagePath ) { Image image = ResourceImage::New( imagePath ); ImageActor background = ImageActor::New( image ); - + background.SetName( "BACKGROUND" ); background.SetAnchorPoint( AnchorPoint::CENTER ); background.SetParentOrigin( ParentOrigin::CENTER ); background.SetZ( -1.0f ); + background.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); return background; } @@ -139,7 +139,7 @@ const float IMAGE_BORDER_TOP = IMAGE_BORDER_LEFT; const float IMAGE_BORDER_BOTTOM = IMAGE_BORDER_LEFT; /** - * Constraint to return a position for a bubble based on the scroll value and vertical wrapping. + * Constraint to return a position for a bubble based on the scroll value and vertical wrapping */ struct AnimateBubbleConstraint { @@ -154,15 +154,15 @@ public: Vector3 operator()( const Vector3& current, const PropertyInput& scrollProperty, const PropertyInput& parentSize ) { Vector3 pos( current ); + const float parentHeight = parentSize.GetVector3().height; - // Wrap bubbles verically. - if( pos.y + mShapeSize * 0.5f < -parentSize.GetVector3().y * 0.5f ) + // Wrap bubbles vertically + if( pos.y + mShapeSize * 0.5f < -parentHeight * 0.5f ) { - pos.y += parentSize.GetVector3().y + mShapeSize; + pos.y = parentHeight * 0.5f + mShapeSize * 0.5f; } - // Bubbles X position moves parallax to horizontal - // panning by a scale factor unique to each bubble. + // Bubbles X position moves parallax to horizontal panning by a scale factor unique to each bubble pos.x = mInitialX + ( scrollProperty.GetVector3().x * mScale ); return pos; } @@ -186,7 +186,6 @@ DaliTableView::DaliTableView( Application& application ) mRootActor(), mRotateAnimation(), mBackground(), - mLogo(), mPressedAnimation(), mScrollViewLayer(), mScrollView(), @@ -242,15 +241,14 @@ void DaliTableView::Initialize( Application& application ) const Vector2 stageSize = Stage::GetCurrent().GetSize(); // Background - mBackground = CreateBackground( mBackgroundImagePath ); - // set same size as parent actor - mBackground.SetSize( stageSize ); - Stage::GetCurrent().Add( mBackground ); + Actor background = CreateBackground( mBackgroundImagePath ); + Stage::GetCurrent().Add( background ); // Render entire content as overlays, as is all on same 2D plane. mRootActor = TableView::New( 4, 1 ); mRootActor.SetAnchorPoint( AnchorPoint::CENTER ); mRootActor.SetParentOrigin( ParentOrigin::CENTER ); + mRootActor.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); Stage::GetCurrent().Add( mRootActor ); // Toolbar at top @@ -262,37 +260,42 @@ void DaliTableView::Initialize( Application& application ) DemoHelper::GetDefaultTextStyle()); mRootActor.AddChild( toolBarLayer, TableView::CellPosition( 0, 0 ) ); - const float toolbarHeight = DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight; - mRootActor.SetFixedHeight( 0, toolbarHeight ); + mRootActor.SetFitHeight( 0 ); // Add logo - mLogo = CreateLogo( LOGO_PATH ); + Dali::ImageActor logo = CreateLogo( LOGO_PATH ); + logo.SetName( "LOGO_IMAGE" ); + logo.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS ); const float paddingHeight = ( ( 1.f-TABLE_RELATIVE_SIZE.y ) * stageSize.y ); const float logoMargin = paddingHeight * LOGO_MARGIN_RATIO; - const float logoHeight = mLogo.GetImage().GetHeight() + logoMargin; - mRootActor.SetFixedHeight( 1, logoHeight ); // Show version in a popup when log is tapped mLogoTapDetector = TapGestureDetector::New(); - mLogoTapDetector.Attach( mLogo ); + mLogoTapDetector.Attach( logo ); mLogoTapDetector.DetectedSignal().Connect( this, &DaliTableView::OnLogoTapped ); const float bottomMargin = paddingHeight * BOTTOM_PADDING_RATIO; - mButtonsPageRelativeSize = Vector3( TABLE_RELATIVE_SIZE.x, 1.f - ( toolbarHeight + logoHeight + bottomMargin) / stageSize.height, TABLE_RELATIVE_SIZE.z ); - mRootActor.SetFixedHeight( 2, mButtonsPageRelativeSize.y * stageSize.height ); Alignment alignment = Alignment::New(); - alignment.Add(mLogo); + alignment.SetName( "LOGO_ALIGNMENT" ); + alignment.Add( logo ); + alignment.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + alignment.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT ); + Actor alignmentActor = alignment; + alignmentActor.SetPadding( Padding( 0.0f, 0.0f, logoMargin, logoMargin )); mRootActor.AddChild( alignment, TableView::CellPosition( 1, 0 ) ); + mRootActor.SetFitHeight( 1 ); // scrollview occupying the majority of the screen mScrollView = ScrollView::New(); + mScrollView.SetRelayoutEnabled( true ); mScrollView.SetAnchorPoint( AnchorPoint::CENTER ); mScrollView.SetParentOrigin( ParentOrigin::CENTER ); - // Note: Currently, changing mScrollView to use SizeMode RELATIVE_TO_PARENT - // will cause scroll ends to appear in the wrong position. - mScrollView.ApplyConstraint( Dali::Constraint::New( Dali::Actor::Property::SIZE, Dali::ParentSource( Dali::Actor::Property::SIZE ), Dali::RelativeToConstraint( SCROLLVIEW_RELATIVE_SIZE ) ) ); + mScrollView.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + const float buttonsPageMargin = ( 1.0f - TABLE_RELATIVE_SIZE.x ) * 0.5f * stageSize.width; + mScrollView.SetPadding( Padding( buttonsPageMargin, buttonsPageMargin, 0.0f, 0.0f ) ); + mScrollView.SetAxisAutoLock( true ); mScrollView.ScrollCompletedSignal().Connect( this, &DaliTableView::OnScrollComplete ); mScrollView.ScrollStartedSignal().Connect( this, &DaliTableView::OnScrollStart ); @@ -302,12 +305,37 @@ void DaliTableView::Initialize( Application& application ) mScrollViewLayer.SetAnchorPoint( AnchorPoint::CENTER ); mScrollViewLayer.SetParentOrigin( ParentOrigin::CENTER ); mScrollViewLayer.SetDrawMode( DrawMode::OVERLAY ); + mScrollViewLayer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + // Create solid background colour. + ImageActor backgroundColourActor = Dali::Toolkit::CreateSolidColorActor( BACKGROUND_COLOR ); + backgroundColourActor.SetAnchorPoint( AnchorPoint::CENTER ); + backgroundColourActor.SetParentOrigin( ParentOrigin::CENTER ); + backgroundColourActor.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + backgroundColourActor.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + backgroundColourActor.SetSizeModeFactor( Vector3( 1.0f, 1.5f, 1.0f ) ); + backgroundColourActor.SetZ( BACKGROUND_Z ); + mScrollViewLayer.Add( backgroundColourActor ); // Populate background and bubbles - needs to be scrollViewLayer so scroll ends show - SetupBackground( mScrollView, mScrollViewLayer, stageSize ); + Actor bubbleContainer = Actor::New(); + bubbleContainer.SetRelayoutEnabled( true ); + bubbleContainer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + bubbleContainer.SetAnchorPoint( AnchorPoint::CENTER ); + bubbleContainer.SetParentOrigin( ParentOrigin::CENTER ); + mScrollViewLayer.Add( bubbleContainer ); + + SetupBackground( bubbleContainer ); + + Alignment buttonsAlignment = Alignment::New(); + buttonsAlignment.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + buttonsAlignment.Add( mScrollViewLayer ); mScrollViewLayer.Add( mScrollView ); - mRootActor.AddChild( mScrollViewLayer, TableView::CellPosition( 2, 0 ) ); + + mRootActor.AddChild( buttonsAlignment, TableView::CellPosition( 2, 0 ) ); + + mRootActor.SetFixedHeight( 3, bottomMargin ); // Add scroll view effect and setup constraints on pages ApplyScrollViewEffect(); @@ -333,7 +361,7 @@ void DaliTableView::Initialize( Application& application ) winHandle.ShowIndicator( Dali::Window::INVISIBLE ); - // + // Background animation mAnimationTimer = Timer::New( BACKGROUND_ANIMATION_DURATION ); mAnimationTimer.TickSignal().Connect( this, &DaliTableView::PauseBackgroundAnimation ); mAnimationTimer.Start(); @@ -349,12 +377,10 @@ void DaliTableView::ApplyCubeEffectToActors() { Actor page = *pageIter; - unsigned int numChildren = page.GetChildCount(); - Actor pageActor = page; - for( unsigned int i=0; iSetDomain( RulerDomain( 0.0f, mTotalPages * stageSize.width * mButtonsPageRelativeSize.x, true ) ); + mScrollRulerX->SetDomain( RulerDomain( 0.0f, mTotalPages * stageSize.width * TABLE_RELATIVE_SIZE.x, true ) ); mScrollRulerY->Disable(); mScrollView.SetRulerX( mScrollRulerX ); mScrollView.SetRulerY( mScrollRulerY ); @@ -483,12 +507,16 @@ void DaliTableView::Rotate( unsigned int degrees ) mRotateAnimation.Play(); } -Actor DaliTableView::CreateTile( const std::string& name, const std::string& title, const Size& parentSize, bool addBackground ) +Actor DaliTableView::CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, bool addBackground ) { - Actor tile = Actor::New(); - tile.SetName( name ); - tile.SetAnchorPoint( AnchorPoint::CENTER ); - tile.SetParentOrigin( ParentOrigin::CENTER ); + Actor content = Actor::New(); + content.SetName( name ); + content.SetAnchorPoint( AnchorPoint::CENTER ); + content.SetParentOrigin( ParentOrigin::CENTER ); + content.SetRelayoutEnabled( true ); + content.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + content.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + content.SetSizeModeFactor( sizeMultiplier ); // create background image if( addBackground ) @@ -498,16 +526,17 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit image.SetAnchorPoint( AnchorPoint::CENTER ); image.SetParentOrigin( ParentOrigin::CENTER ); // make the image 100% of tile - image.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + // move image back to get text appear in front image.SetZ( -1 ); image.SetStyle( ImageActor::STYLE_NINE_PATCH ); image.SetNinePatchBorder( Vector4( IMAGE_BORDER_LEFT, IMAGE_BORDER_TOP, IMAGE_BORDER_RIGHT, IMAGE_BORDER_BOTTOM ) ); - tile.Add( image ); + content.Add( image ); // Add stencil ImageActor stencil = NewStencilImage(); - stencil.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + stencil.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); image.Add( stencil ); } @@ -518,22 +547,23 @@ Actor DaliTableView::CreateTile( const std::string& name, const std::string& tit text.SetMultilinePolicy( Toolkit::TextView::SplitByWord ); text.SetLineJustification( Toolkit::TextView::Center ); text.SetTextAlignment( Toolkit::Alignment::Type( Alignment::HorizontalCenter | Alignment::VerticalCenter ) ); - text.SetColor( Color::WHITE ); text.SetZ( 1 ); // make the text 90% of tile - text.SetSize( 0.9f * parentSize.width, 0.9f * parentSize.height ); + text.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + text.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + text.SetSizeModeFactor( Vector3( 0.9f, 0.9f, 0.0f ) ); text.SetStyleToCurrentText( GetTableTextStyle() ); text.SetSnapshotModeEnabled( false ); - tile.Add( text ); + content.Add( text ); // Set the tile to be keyboard focusable - tile.SetKeyboardFocusable(true); + content.SetKeyboardFocusable(true); // connect to the touch events - tile.TouchedSignal().Connect( this, &DaliTableView::OnTilePressed ); - tile.HoveredSignal().Connect( this, &DaliTableView::OnTileHovered ); + content.TouchedSignal().Connect( this, &DaliTableView::OnTilePressed ); + content.HoveredSignal().Connect( this, &DaliTableView::OnTileHovered ); - return tile; + return content; } ImageActor DaliTableView::NewStencilImage() @@ -654,8 +684,6 @@ void DaliTableView::OnScrollComplete( const Dali::Vector3& position ) // move focus to 1st item of new page FocusManager focusManager = FocusManager::Get(); focusManager.SetCurrentFocusActor(mPages[mScrollView.GetCurrentPage()].GetChildAt(0) ); - - ApplyCubeEffectToActors(); } bool DaliTableView::OnScrollTouched( Actor actor, const TouchEvent& event ) @@ -721,37 +749,65 @@ void DaliTableView::OnKeyEvent( const KeyEvent& event ) } } -void DaliTableView::SetupBackground( Actor bubbleContainer, Actor backgroundLayer, const Vector2& size ) +void DaliTableView::SetupBackground( Actor bubbleContainer ) { // Create distance field shape. BufferImage distanceField; Size imageSize( 512, 512 ); CreateShapeImage( CIRCLE, imageSize, distanceField ); - // Create solid background colour. - ImageActor backgroundColourActor = Dali::Toolkit::CreateSolidColorActor( BACKGROUND_COLOR ); - backgroundColourActor.SetAnchorPoint( AnchorPoint::CENTER ); - backgroundColourActor.SetParentOrigin( ParentOrigin::CENTER ); - backgroundColourActor.SetSize( size * BACKGROUND_SIZE_SCALE ); - backgroundColourActor.SetZ( BACKGROUND_Z ); - backgroundColourActor.SetPositionInheritanceMode( DONT_INHERIT_POSITION ); - backgroundLayer.Add( backgroundColourActor ); - // Add bubbles to the bubbleContainer. // Note: The bubbleContainer is parented externally to this function. - AddBackgroundActors( bubbleContainer, NUM_BACKGROUND_IMAGES, distanceField, size ); + AddBackgroundActors( bubbleContainer, NUM_BACKGROUND_IMAGES, distanceField ); +} + +void DaliTableView::InitialiseBackgroundActors( Actor actor ) +{ + // Delete current animations + mBackgroundAnimations.clear(); + + // Create new animations + const Vector3 size = actor.GetTargetSize(); + + for( unsigned int i = 0, childCount = actor.GetChildCount(); i < childCount; ++i ) + { + Actor child = actor.GetChildAt( i ); + + const Vector3 childSize = child.GetTargetSize(); + + // Calculate a random position + Vector3 childPos( Random::Range( -size.x * 0.5f * BACKGROUND_SPREAD_SCALE, size.x * 0.5f * BACKGROUND_SPREAD_SCALE ), + Random::Range( -size.y * 0.5f - childSize.height, size.y * 0.5f + childSize.height ), + Random::Range( BUBBLE_MIN_Z, BUBBLE_MAX_Z ) ); + + child.SetPosition( childPos ); + + // Define bubble horizontal parallax and vertical wrapping + Constraint animConstraint = Constraint::New < Vector3 > ( Actor::Property::POSITION, + Source( mScrollView, mScrollView.GetPropertyIndex( ScrollView::SCROLL_POSITION_PROPERTY_NAME ) ), + Dali::ParentSource( Dali::Actor::Property::SIZE ), + AnimateBubbleConstraint( childPos, Random::Range( -0.85f, 0.25f ), childSize.height ) ); + child.ApplyConstraint( animConstraint ); + + // Kickoff animation + Animation animation = Animation::New( Random::Range( 40.0f, 80.0f ) ); + animation.MoveBy( child, Vector3( 0.0f, -1.0f, 0.0f ), AlphaFunctions::Linear ); + animation.SetLooping( true ); + animation.Play(); + mBackgroundAnimations.push_back( animation ); + } } -void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage distanceField, const Dali::Vector2& size ) +void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage distanceField ) { for( int i = 0; i < count; ++i ) { float randSize = Random::Range( 10.0f, 400.0f ); float hue = Random::Range( 0.3f, 1.0f ); - Vector4 randColour( hue, hue*0.5, 0.0f, Random::Range( 0.3f, 0.6f )); + Vector4 randColour( hue, hue * 0.5, 0.0f, Random::Range( 0.3f, 0.6f )); ImageActor dfActor = ImageActor::New( distanceField ); - mBackgroundActors.push_back( dfActor ); + dfActor.SetRelayoutEnabled( false ); dfActor.SetSize( Vector2( randSize, randSize ) ); dfActor.SetParentOrigin( ParentOrigin::CENTER ); @@ -761,33 +817,10 @@ void DaliTableView::AddBackgroundActors( Actor layer, int count, BufferImage dis effect.SetOutlineParams( Vector2( 0.55f, 0.00f ) ); effect.SetSmoothingEdge( 0.5f ); layer.Add( dfActor ); - - // Setup animation - Vector3 actorPos( - Random::Range( -size.x * 0.5f * BACKGROUND_SPREAD_SCALE, size.x * 0.5f * BACKGROUND_SPREAD_SCALE ), - Random::Range( -size.y * 0.5f - randSize, size.y * 0.5f + randSize ), - Random::Range( BUBBLE_MIN_Z, BUBBLE_MAX_Z ) ); - dfActor.SetPosition( actorPos ); - - // Define bubble horizontal parallax and vertical wrapping - Constraint animConstraint = Constraint::New < Vector3 > ( Actor::Property::POSITION, - Source( mScrollView, mScrollView.GetPropertyIndex( ScrollView::SCROLL_POSITION_PROPERTY_NAME ) ), - Dali::ParentSource( Dali::Actor::Property::SIZE ), - AnimateBubbleConstraint( actorPos, Random::Range( -0.85f, 0.25f ), randSize ) ); - dfActor.ApplyConstraint( animConstraint ); - - // Kickoff animation - Animation animation = Animation::New( Random::Range( 40.0f, 200.0f ) ); - KeyFrames keyframes = KeyFrames::New(); - keyframes.Add( 0.0f, actorPos ); - Vector3 toPos( actorPos ); - toPos.y -= ( size.y + randSize ); - keyframes.Add( 1.0f, toPos ); - animation.AnimateBetween( Property( dfActor, Actor::Property::POSITION ), keyframes ); - animation.SetLooping( true ); - animation.Play(); - mBackgroundAnimations.push_back( animation ); } + + // Positioning will occur when the layer is relaid out + layer.OnRelayoutSignal().Connect( this, &DaliTableView::InitialiseBackgroundActors ); } void DaliTableView::CreateShapeImage( ShapeType shapeType, const Size& size, BufferImage& distanceFieldOut ) @@ -860,7 +893,7 @@ ImageActor DaliTableView::CreateLogo( std::string imagePath ) ImageActor logo = ImageActor::New( image ); logo.SetAnchorPoint( AnchorPoint::CENTER ); - logo.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); + logo.SetParentOrigin( ParentOrigin::CENTER ); return logo; } @@ -994,14 +1027,18 @@ void DaliTableView::OnLogoTapped( Dali::Actor actor, const Dali::TapGesture& tap stream << "DALi Toolkit: " << TOOLKIT_MAJOR_VERSION << "." << TOOLKIT_MINOR_VERSION << "." << TOOLKIT_MICRO_VERSION << std::endl << "(" << TOOLKIT_BUILD_DATE << ")"; mVersionPopup = Dali::Toolkit::Popup::New(); - mVersionPopup.SetTitle( stream.str() ); mVersionPopup.SetParentOrigin( ParentOrigin::CENTER ); mVersionPopup.SetAnchorPoint( AnchorPoint::CENTER ); + mVersionPopup.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + mVersionPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mVersionPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) ); + mVersionPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT ); + mVersionPopup.SetTitle( stream.str() ); mVersionPopup.HideTail(); mVersionPopup.OutsideTouchedSignal().Connect( this, &DaliTableView::HideVersionPopup ); mVersionPopup.HiddenSignal().Connect( this, &DaliTableView::PopupHidden ); - Dali::Stage::GetCurrent().Add( mVersionPopup ); + mVersionPopup.MarkDirtyForRelayout(); } mVersionPopup.Show(); diff --git a/demo/dali-table-view.h b/demo/dali-table-view.h index fbaa2ea..05640ef 100644 --- a/demo/dali-table-view.h +++ b/demo/dali-table-view.h @@ -165,7 +165,7 @@ private: // Application callbacks & implementation * * @return The Actor for the created tile. */ - Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Size& parentSize, bool addBackground ); + Dali::Actor CreateTile( const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, bool addBackground ); /** * Create a stencil image @@ -276,9 +276,8 @@ private: // Application callbacks & implementation * Create a depth field background * * @param[in] bubbleLayer Add the graphics to this layer - * @param[in] backgroundLayer Add the background to this layer */ - void SetupBackground( Dali::Actor bubbleLayer, Dali::Actor backgroundLayer, const Dali::Vector2& size ); + void SetupBackground( Dali::Actor bubbleLayer ); /** * Create background actors for the given layer @@ -286,9 +285,8 @@ private: // Application callbacks & implementation * @param[in] layer The layer to add the actors to * @param[in] count The number of actors to generate * @param[in] distanceField The distance field bitmap to use - * @param[in] size The size of the actor */ - void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage distanceField, const Dali::Vector2& size ); + void AddBackgroundActors( Dali::Actor layer, int count, Dali::BufferImage distanceField ); /** * Create a bitmap with the specified shape and also output a distance field @@ -378,6 +376,20 @@ private: // Application callbacks & implementation */ void PopupHidden(); + /* + * @brief Callback called when the buttons page actor is relaid out + * + * @param[in] actor The page actor + */ + void OnButtonsPageRelayout( const Dali::Actor& actor ); + + /** + * @brief Callback called to set up background actors + * + * @param[in] actor The actor raising the callback + */ + void InitialiseBackgroundActors( Dali::Actor actor ); + private: Dali::Application& mApplication; ///< Application instance. @@ -385,7 +397,6 @@ private: Dali::Toolkit::TableView mRootActor; ///< All content (excluding background is anchored to this Actor) Dali::Animation mRotateAnimation; ///< Animation to rotate and resize mRootActor. Dali::ImageActor mBackground; ///< Background's static image. - Dali::ImageActor mLogo; ///< Logo's static image. Dali::Animation mPressedAnimation; ///< Button press scaling animation. Dali::Layer mScrollViewLayer; ///< ScrollView resides on a separate layer. Dali::Toolkit::ScrollView mScrollView; ///< ScrollView container (for all Examples) @@ -413,6 +424,7 @@ private: bool mSortAlphabetically:1; ///< Sort examples alphabetically. bool mBackgroundAnimsPlaying:1; ///< Are background animations playing bool mVersionPopupShown:1; ///< Whehter the version popup is shown or not + }; #endif // __DALI_DEMO_H__ diff --git a/examples/animated-shapes/animated-shapes-example.cpp b/examples/animated-shapes/animated-shapes-example.cpp index b7a5a72..f73c796 100644 --- a/examples/animated-shapes/animated-shapes-example.cpp +++ b/examples/animated-shapes/animated-shapes-example.cpp @@ -52,6 +52,7 @@ public: //Create a view mView = Dali::Toolkit::View::New(); + mView.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); stage.Add( mView ); //Set background image for the view diff --git a/examples/blocks/blocks-example.cpp b/examples/blocks/blocks-example.cpp index cf1ceae..5412b0d 100644 --- a/examples/blocks/blocks-example.cpp +++ b/examples/blocks/blocks-example.cpp @@ -421,7 +421,8 @@ private: mLevelContainer = Actor::New(); mLevelContainer.SetAnchorPoint( AnchorPoint::CENTER ); mLevelContainer.SetParentOrigin( ParentOrigin::CENTER ); - mLevelContainer.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + mLevelContainer.SetRelayoutEnabled( true ); + mLevelContainer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); mContentLayer.Add( mLevelContainer ); mBrickCount = 0; @@ -593,6 +594,7 @@ private: ImageActor brick = ImageActor::New(img); brick.SetParentOrigin(ParentOrigin::TOP_LEFT); brick.SetAnchorPoint(AnchorPoint::CENTER); + brick.SetRelayoutEnabled( false ); brick.SetSize( brickSize ); brick.SetPosition( Vector3( position ) ); @@ -625,6 +627,7 @@ private: ImageActor actor = ImageActor::New(img); actor.SetParentOrigin(ParentOrigin::TOP_LEFT); actor.SetAnchorPoint(AnchorPoint::CENTER); + actor.SetRelayoutEnabled( false ); return actor; } diff --git a/examples/builder/examples.cpp b/examples/builder/examples.cpp index bac5840..41d2162 100644 --- a/examples/builder/examples.cpp +++ b/examples/builder/examples.cpp @@ -290,6 +290,7 @@ public: mFiles.clear(); mItemView = ItemView::New(*this); + mItemView.SetRelayoutEnabled( false ); stage.Add( mItemView ); mItemView.SetParentOrigin(ParentOrigin::CENTER); mItemView.SetAnchorPoint(AnchorPoint::CENTER); @@ -396,6 +397,7 @@ public: Actor MenuItem(const std::string& text) { TextView t = TextView::New(); + t.SetResizePolicy( FILL_TO_PARENT, WIDTH ); t.SetMarkupProcessingEnabled(true); int size = static_cast(DemoHelper::ScalePointSize(6)); @@ -480,6 +482,8 @@ public: builder.AddActors( layer ); + // Force relayout on layer + layer.RelayoutRequestTree(); } diff --git a/examples/buttons/buttons-example.cpp b/examples/buttons/buttons-example.cpp index 37ede2b..b6b82ff 100644 --- a/examples/buttons/buttons-example.cpp +++ b/examples/buttons/buttons-example.cpp @@ -127,14 +127,16 @@ class ButtonsController: public ConnectionTracker radioGroup2Background.SetAnchorPoint( AnchorPoint::TOP_LEFT ); radioGroup2Background.SetParentOrigin( ParentOrigin::TOP_LEFT ); radioGroup2Background.SetPosition( DP(MARGIN_SIZE), DP(yPos) ); - radioGroup2Background.SetSize( DP(348), DP(GROUP2_HEIGHT) ); + radioGroup2Background.SetRelayoutEnabled( true ); + radioGroup2Background.SetPreferredSize( Vector2( DP(348), DP(GROUP2_HEIGHT) ) ); mContentLayer.Add( radioGroup2Background ); Actor radioButtonsGroup2 = Actor::New(); radioButtonsGroup2.SetParentOrigin( ParentOrigin::TOP_LEFT ); radioButtonsGroup2.SetAnchorPoint( AnchorPoint::TOP_LEFT ); radioButtonsGroup2.SetPosition( DP(MARGIN_SIZE), DP(MARGIN_SIZE) ); - radioButtonsGroup2.SetSize( DP(100), DP(160) ); + radioButtonsGroup2.SetRelayoutEnabled( true ); + radioButtonsGroup2.SetPreferredSize( Vector2( DP(100), DP(160) ) ); radioGroup2Background.Add( radioButtonsGroup2 ); @@ -143,7 +145,7 @@ class ButtonsController: public ConnectionTracker // Radio 1 { ImageActor imageActor = ImageActor::New( ResourceImage::New( SMALL_IMAGE_1 ) ); - imageActor.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ); + imageActor.SetPreferredSize( Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) ); mRadioButtonImage1 = Dali::Toolkit::RadioButton::New( imageActor ); mRadioButtonImage1.SetParentOrigin( ParentOrigin::TOP_LEFT ); mRadioButtonImage1.SetAnchorPoint( AnchorPoint::TOP_LEFT ); @@ -158,7 +160,7 @@ class ButtonsController: public ConnectionTracker radioY += RADIO_LABEL_THUMBNAIL_SIZE + RADIO_IMAGE_SPACING; ImageActor imageActor = ImageActor::New( ResourceImage::New( SMALL_IMAGE_2 ) ); - imageActor.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ); + imageActor.SetPreferredSize( Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) ); mRadioButtonImage2 = Dali::Toolkit::RadioButton::New( imageActor ); mRadioButtonImage2.SetParentOrigin( ParentOrigin::TOP_LEFT ); @@ -173,7 +175,7 @@ class ButtonsController: public ConnectionTracker radioY += RADIO_LABEL_THUMBNAIL_SIZE + RADIO_IMAGE_SPACING; ImageActor imageActor = ImageActor::New( ResourceImage::New( SMALL_IMAGE_3 ) ); - imageActor.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ); + imageActor.SetPreferredSize( Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) ); mRadioButtonImage3 = Dali::Toolkit::RadioButton::New( imageActor ); mRadioButtonImage3.SetParentOrigin( ParentOrigin::TOP_LEFT ); @@ -188,8 +190,8 @@ class ButtonsController: public ConnectionTracker mUpdateButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); mUpdateButton.SetAnchorPoint( AnchorPoint::TOP_CENTER ); mUpdateButton.SetPosition( 0, DP(MARGIN_SIZE) ); - mUpdateButton.SetLabel("Select"); - mUpdateButton.SetSize( DP(100), DP(BUTTON_HEIGHT) ); + mUpdateButton.SetLabel( "Select" ); + mUpdateButton.SetPreferredSize( Vector2( DP(100), DP(BUTTON_HEIGHT) ) ); mUpdateButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); mUpdateButton.SetDisabledImage( Dali::ResourceImage::New( PUSHBUTTON_DISABLED_IMAGE ) ); @@ -208,7 +210,7 @@ class ButtonsController: public ConnectionTracker mImage.SetParentOrigin( ParentOrigin::TOP_RIGHT ); mImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); mImage.SetPosition( DP(MARGIN_SIZE), 0 ); - mImage.SetSize( DP(218), DP(218) ); + mImage.SetPreferredSize( Vector2( DP(218), DP(218) ) ); radioButtonsGroup2.Add( mImage ); // The enable/disable radio group @@ -218,7 +220,8 @@ class ButtonsController: public ConnectionTracker radioGroup1Background.SetAnchorPoint( AnchorPoint::TOP_LEFT ); radioGroup1Background.SetParentOrigin( ParentOrigin::TOP_LEFT ); radioGroup1Background.SetPosition( DP(MARGIN_SIZE), DP(yPos) ); - radioGroup1Background.SetSize( DP(348), DP(GROUP1_HEIGHT) ); + radioGroup1Background.SetRelayoutEnabled( true ); + radioGroup1Background.SetPreferredSize( Vector2( DP(348), DP(GROUP1_HEIGHT) ) ); mContentLayer.Add( radioGroup1Background ); // Radio group @@ -232,17 +235,17 @@ class ButtonsController: public ConnectionTracker // First radio button { Toolkit::TableView tableView = Toolkit::TableView::New( 1, 2 ); - tableView.SetSize( DP(260), DP(RADIO_LABEL_THUMBNAIL_SIZE) ); + tableView.SetPreferredSize( Vector2( DP(260), 0.0f ) ); + tableView.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT ); Toolkit::TextView textView = Toolkit::TextView::New( "Select enabled" ); - Toolkit::Alignment alignment = Toolkit::Alignment::New( Toolkit::Alignment::HorizontalLeft ); - alignment.Add( textView ); - tableView.AddChild( alignment, Toolkit::TableView::CellPosition( 0, 0 ) ); + tableView.AddChild( textView, Toolkit::TableView::CellPosition( 0, 0 ) ); ImageActor imageActor = ImageActor::New( ResourceImage::New( ENABLED_IMAGE ) ); - imageActor.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ); + imageActor.SetPreferredSize( Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) ); + imageActor.SetResizePolicy( FIXED, ALL_DIMENSIONS ); + imageActor.SetPadding( Padding( DP(20.0f), 0.0f, 0.0f, 0.0f ) ); tableView.AddChild( imageActor, Toolkit::TableView::CellPosition( 0, 1 ) ); - tableView.SetFixedWidth( 1, DP(RADIO_LABEL_THUMBNAIL_SIZE) ); Toolkit::RadioButton radioButton = Dali::Toolkit::RadioButton::New( tableView ); radioButton.SetName( "radio-select-enable" ); @@ -276,7 +279,8 @@ class ButtonsController: public ConnectionTracker checkBoxBackground.SetAnchorPoint( AnchorPoint::TOP_LEFT ); checkBoxBackground.SetParentOrigin( ParentOrigin::TOP_LEFT ); checkBoxBackground.SetPosition( DP(MARGIN_SIZE), DP(yPos) ); - checkBoxBackground.SetSize( DP(430), DP(GROUP3_HEIGHT) ); + checkBoxBackground.SetRelayoutEnabled( true ); + checkBoxBackground.SetPreferredSize( Vector2( DP(430), DP(GROUP3_HEIGHT) ) ); mContentLayer.Add( checkBoxBackground ); Dali::Image unselected = Dali::ResourceImage::New( CHECKBOX_UNSELECTED_IMAGE ); @@ -336,7 +340,8 @@ class ButtonsController: public ConnectionTracker toggleBackground.SetAnchorPoint( AnchorPoint::TOP_LEFT ); toggleBackground.SetParentOrigin( ParentOrigin::TOP_LEFT ); toggleBackground.SetPosition( DP(MARGIN_SIZE), DP(yPos) ); - toggleBackground.SetSize( DP(150 + MARGIN_SIZE * 2), DP(GROUP4_HEIGHT) ); + toggleBackground.SetRelayoutEnabled( true ); + toggleBackground.SetPreferredSize( Vector2( DP(150 + MARGIN_SIZE * 2), DP(GROUP4_HEIGHT) ) ); mContentLayer.Add( toggleBackground ); Toolkit::PushButton toggleButton = Toolkit::PushButton::New(); @@ -345,7 +350,7 @@ class ButtonsController: public ConnectionTracker toggleButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); toggleButton.SetPosition( DP(MARGIN_SIZE), DP(MARGIN_SIZE) ); toggleButton.SetLabel( "Unselected" ); - toggleButton.SetSize( DP(150), DP(BUTTON_HEIGHT) ); + toggleButton.SetPreferredSize( Vector2( DP(150), DP(BUTTON_HEIGHT) ) ); toggleButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); toggleButton.SetDisabledImage( Dali::ResourceImage::New( PUSHBUTTON_DISABLED_IMAGE ) ); diff --git a/examples/cluster/cluster-example.cpp b/examples/cluster/cluster-example.cpp index 50b6d4d..73e8490 100644 --- a/examples/cluster/cluster-example.cpp +++ b/examples/cluster/cluster-example.cpp @@ -477,6 +477,7 @@ public: // create and setup the scroll view... mScrollView = ScrollView::New(); + mScrollView.SetRelayoutEnabled( false ); mScrollView.SetSize(stageSize); // attach Wobble Effect to ScrollView @@ -488,7 +489,8 @@ public: mScrollView.SetParentOrigin(ParentOrigin::CENTER); // Scale ScrollView to fit parent (mContentLayer) - mScrollView.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + mScrollView.SetRelayoutEnabled( true ); + mScrollView.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); // Add the scroll view to the content layer mContentLayer.Add(mScrollView); @@ -515,6 +517,7 @@ public: Cluster clusterActor = Cluster::New(style); clusterActor.SetParentOrigin(ParentOrigin::CENTER); clusterActor.SetAnchorPoint(AnchorPoint::CENTER); + clusterActor.SetRelayoutEnabled( false ); Vector2 stageSize = Dali::Stage::GetCurrent().GetSize(); float minStageDimension = std::min(stageSize.x, stageSize.y); @@ -533,6 +536,7 @@ public: backgroundAttributes.SetScalingMode( Dali::ImageAttributes::ShrinkToFit ); Image bg = ResourceImage::New( CLUSTER_BACKGROUND_IMAGE_PATH ); ImageActor image = ImageActor::New(bg); + image.SetRelayoutEnabled( false ); clusterActor.SetBackgroundImage(image); // Add actors (pictures) as the children of the cluster @@ -576,6 +580,7 @@ public: shadowActor.SetPosition(Vector3(0.0f, 0.0f, -1.0f)); // Apply size-relative mode to auto-size the image shadow + shadowActor.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); shadowActor.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); shadowActor.SetSizeModeFactor( ShadowProperty::SIZE_SCALE ); actor.Add( shadowActor ); @@ -585,7 +590,7 @@ public: ImageActor imageActor = ImageActor::New( image ); imageActor.SetParentOrigin( ParentOrigin::CENTER ); imageActor.SetAnchorPoint( AnchorPoint::CENTER ); - imageActor.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + imageActor.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); actor.Add( imageActor ); // Add a border image child actor (with a fixed size offset from parent). @@ -595,6 +600,7 @@ public: borderActor.SetStyle( ImageActor::STYLE_NINE_PATCH ); borderActor.SetNinePatchBorder( CLUSTER_IMAGE_BORDER_ABSOLUTE ); borderActor.SetPosition( Vector3( 0.0f, 0.0f, 1.0f ) ); + borderActor.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); borderActor.SetSizeMode( SIZE_FIXED_OFFSET_FROM_PARENT ); borderActor.SetSizeModeFactor( Vector3( CLUSTER_IMAGE_BORDER_INDENT - 1.0f, CLUSTER_IMAGE_BORDER_INDENT - 1.0f, 0.0f ) * 2.0f ); actor.Add( borderActor ); @@ -625,7 +631,8 @@ public: mScrollView.Add(pageView); pageView.SetParentOrigin(ParentOrigin::CENTER); pageView.SetPosition(Vector3(stageSize.width * column, 0.0f, 0.0f)); - pageView.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + pageView.SetRelayoutEnabled( true ); + pageView.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); // Create cluster actors, add them to scroll view, and set the shear effect with the given center point. Cluster cluster = CreateClusterActor(clusterType, style); diff --git a/examples/cube-transition-effect/cube-transition-effect-example.cpp b/examples/cube-transition-effect/cube-transition-effect-example.cpp index 7fa1545..a5ea7b1 100644 --- a/examples/cube-transition-effect/cube-transition-effect-example.cpp +++ b/examples/cube-transition-effect/cube-transition-effect-example.cpp @@ -288,6 +288,7 @@ void CubeTransitionApp::OnInit( Application& application ) mCurrentImage = ImageActor::New( LoadStageFillingImage( IMAGES[mIndex] ) ); mCurrentImage.SetPositionInheritanceMode( USE_PARENT_POSITION ); mCurrentImage.ApplyConstraint( mImageConstraint ); + mCurrentImage.SetRelayoutEnabled( false ); mParent.Add( mCurrentImage ); mCurrentEffect = mCubeWaveEffect; @@ -332,6 +333,7 @@ void CubeTransitionApp::GoToNextImage() mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION); mNextImage.ApplyConstraint( mImageConstraint ); + mNextImage.SetRelayoutEnabled( false ); mCurrentEffect.SetTargetImage(mNextImage); if( image.GetLoadingState() == ResourceLoadingSucceeded ) { diff --git a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp index 09bfe9e..6b14053 100644 --- a/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp +++ b/examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp @@ -421,7 +421,8 @@ public: // coordinates in a frame defined by a parent actor: Actor gridActor = Actor::New(); - gridActor.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + gridActor.SetRelayoutEnabled( true ); + gridActor.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); gridActor.SetParentOrigin( ParentOrigin::CENTER ); gridActor.SetAnchorPoint( AnchorPoint::CENTER ); diff --git a/examples/item-view/item-view-example.cpp b/examples/item-view/item-view-example.cpp index d86306e..841f630 100644 --- a/examples/item-view/item-view-example.cpp +++ b/examples/item-view/item-view-example.cpp @@ -281,7 +281,8 @@ public: mDeleteButton.SetDrawMode( DrawMode::OVERLAY ); mDeleteButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) ); mDeleteButton.SetButtonImage( ResourceImage::New( DELETE_IMAGE ) ); - mDeleteButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f ); + mDeleteButton.SetResizePolicy( FIXED, ALL_DIMENSIONS ); + mDeleteButton.SetPreferredSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) ); mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked); mDeleteButton.SetLeaveRequired( true ); mDeleteButton.SetVisible( false ); @@ -295,7 +296,8 @@ public: mInsertButton.SetDrawMode( DrawMode::OVERLAY ); mInsertButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) ); mInsertButton.SetButtonImage( ResourceImage::New( INSERT_IMAGE ) ); - mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f ); + mInsertButton.SetResizePolicy( FIXED, ALL_DIMENSIONS ); + mInsertButton.SetPreferredSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) ); mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked); mInsertButton.SetLeaveRequired( true ); mInsertButton.SetVisible( false ); @@ -309,7 +311,8 @@ public: mReplaceButton.SetDrawMode( DrawMode::OVERLAY ); mReplaceButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) ); mReplaceButton.SetButtonImage( ResourceImage::New( REPLACE_IMAGE ) ); - mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f ); + mReplaceButton.SetResizePolicy( FIXED, ALL_DIMENSIONS ); + mReplaceButton.SetPreferredSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) ); mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked); mReplaceButton.SetLeaveRequired( true ); mReplaceButton.SetVisible( false ); @@ -318,6 +321,7 @@ public: // Create the item view actor mImageAtlas = CreateImageAtlas(); mItemView = ItemView::New(*this); + mItemView.SetRelayoutEnabled( false ); mItemView.SetParentOrigin(ParentOrigin::CENTER); mItemView.SetAnchorPoint(AnchorPoint::CENTER); @@ -897,6 +901,7 @@ public: // From ItemFactory borderActor.SetStyle( ImageActor::STYLE_NINE_PATCH ); borderActor.SetNinePatchBorder( Vector4( ITEM_IMAGE_BORDER_LEFT, ITEM_IMAGE_BORDER_TOP, ITEM_IMAGE_BORDER_RIGHT, ITEM_IMAGE_BORDER_BOTTOM ) ); borderActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); // darken with parent image-actor + borderActor.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); borderActor.SetSizeMode( SIZE_FIXED_OFFSET_FROM_PARENT ); borderActor.SetSizeModeFactor( ITEM_BORDER_MARGIN_SIZE ); actor.Add(borderActor); @@ -908,6 +913,7 @@ public: // From ItemFactory // Add a checkbox child actor; invisible until edit-mode is enabled ImageActor checkbox = ImageActor::New( mWhiteImage ); + checkbox.SetRelayoutEnabled( false ); checkbox.SetName( "CheckBox" ); checkbox.SetColor( Vector4(0.0f,0.0f,0.0f,0.6f) ); checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT ); @@ -924,6 +930,7 @@ public: // From ItemFactory actor.Add( checkbox ); ImageActor tick = ImageActor::New( ResourceImage::New(SELECTED_IMAGE) ); + tick.SetRelayoutEnabled( false ); tick.SetColorMode( USE_OWN_COLOR ); tick.SetName( "Tick" ); tick.SetParentOrigin( ParentOrigin::TOP_RIGHT ); @@ -988,12 +995,12 @@ private: mMenu = Toolkit::Popup::New(); mMenu.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); mMenu.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT ); + mMenu.SetResizePolicy( FIXED, ALL_DIMENSIONS ); + mMenu.SetPreferredSize( Vector2( popupWidth, MENU_OPTION_HEIGHT * 2 ) ); mMenu.OutsideTouchedSignal().Connect( this, &ItemViewExample::HideMenu ); - stage.Add( mMenu ); TableView tableView = TableView::New( 0, 0 ); - Vector2 tableSize = Vector2( popupWidth, MENU_OPTION_HEIGHT * 2 ); - tableView.SetSize( tableSize ); + tableView.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); mMenu.Add( tableView ); Slider slider = Slider::New(); @@ -1002,9 +1009,9 @@ private: slider.SetProperty( Slider::Property::VALUE, mDurationSeconds ); slider.SetProperty( Slider::Property::VALUE_PRECISION, 2 ); slider.SetProperty( Slider::Property::SHOW_POPUP, true ); + slider.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); slider.ValueChangedSignal().Connect( this, &ItemViewExample::SliderValueChange ); tableView.AddChild( slider, TableView::CellPosition( 0, 0 ) ); - tableView.SetRelativeHeight( 0, 0.5f ); TextStyle defaultTextStyle; defaultTextStyle.SetFontName(DEFAULT_TEXT_STYLE_FONT_FAMILY); @@ -1018,19 +1025,21 @@ private: text.SetParentOrigin( ParentOrigin::TOP_LEFT ); text.SetTextAlignment( Dali::Toolkit::Alignment::HorizontalLeft ); text.SetStyleToCurrentText( defaultTextStyle ); - text.SetSize( 0.0f, LABEL_TEXT_SIZE_Y ); - text.ApplyConstraint( Dali::Constraint::New( Dali::Actor::Property::SIZE_WIDTH, Dali::ParentSource( Dali::Actor::Property::SIZE_WIDTH ), Dali::EqualToConstraint() ) ); + text.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + text.SetResizePolicy( FIXED, HEIGHT ); + text.SetPreferredSize( Vector2( 0.0f, LABEL_TEXT_SIZE_Y ) ); text.SetZ( -0.9f ); slider.Add( text ); Actor textContainer = Actor::New(); + textContainer.SetRelayoutEnabled( true ); + textContainer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); mAlphaFunctionText = TextView::New( ALPHA_FUNCTIONS_TEXT[mAlphaFuncIndex] ); mAlphaFunctionText.SetAnchorPoint( ParentOrigin::CENTER ); mAlphaFunctionText.SetParentOrigin( ParentOrigin::CENTER ); mAlphaFunctionText.SetTextAlignment( Toolkit::Alignment::VerticalCenter ); textContainer.Add( mAlphaFunctionText ); tableView.AddChild( textContainer, TableView::CellPosition( 1, 0 ) ); - tableView.SetRelativeHeight( 0, 0.5f ); mTapDetector = TapGestureDetector::New(); mTapDetector.Attach(mAlphaFunctionText); @@ -1041,10 +1050,12 @@ private: text.SetParentOrigin( ParentOrigin::TOP_LEFT ); text.SetTextAlignment( Dali::Toolkit::Alignment::HorizontalLeft ); text.SetStyleToCurrentText( defaultTextStyle ); - text.SetSize( 0.0f, LABEL_TEXT_SIZE_Y ); - text.ApplyConstraint( Dali::Constraint::New( Dali::Actor::Property::SIZE_WIDTH, Dali::ParentSource( Dali::Actor::Property::SIZE_WIDTH ), Dali::EqualToConstraint() ) ); + text.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + text.SetResizePolicy( FIXED, HEIGHT ); + text.SetPreferredSize( Vector2( 0.0f, LABEL_TEXT_SIZE_Y ) ); textContainer.Add( text ); + mMenu.MarkDirtyForRelayout(); mMenu.Show(); mMenuShown = true; } diff --git a/examples/logging/logging-example.cpp b/examples/logging/logging-example.cpp index 94f7ac0..0c44ed1 100644 --- a/examples/logging/logging-example.cpp +++ b/examples/logging/logging-example.cpp @@ -275,7 +275,7 @@ class LoggingController: public ConnectionTracker mContentLayer.Add( createGroupBackground ); int buttonXDP = DP(MARGIN_SIZE); - int buttonWidthDP = (createGroupBackground.GetSize().width - DP(MARGIN_SIZE) * 3) / 2; + int buttonWidthDP = (createGroupBackground.GetTargetSize().width - DP(MARGIN_SIZE) * 3) / 2; { Toolkit::PushButton button = Toolkit::PushButton::New(); @@ -326,7 +326,7 @@ class LoggingController: public ConnectionTracker mContentLayer.Add( timingGroupBackground ); buttonXDP = DP(MARGIN_SIZE); - buttonWidthDP = (timingGroupBackground.GetSize().width - DP(MARGIN_SIZE) * 3) / 2; + buttonWidthDP = (timingGroupBackground.GetTargetSize().width - DP(MARGIN_SIZE) * 3) / 2; { Toolkit::PushButton button = Toolkit::PushButton::New(); @@ -377,7 +377,7 @@ class LoggingController: public ConnectionTracker mContentLayer.Add( enableGroupBackground ); buttonXDP = DP(MARGIN_SIZE); - buttonWidthDP = (enableGroupBackground.GetSize().width - DP(MARGIN_SIZE) * 3) / 2; + buttonWidthDP = (enableGroupBackground.GetTargetSize().width - DP(MARGIN_SIZE) * 3) / 2; { Toolkit::PushButton button = Toolkit::PushButton::New(); @@ -509,7 +509,7 @@ class LoggingController: public ConnectionTracker mContentLayer.Add( vsyncGroupBackground ); buttonXDP = DP(MARGIN_SIZE); - buttonWidthDP = vsyncGroupBackground.GetSize().width - DP(MARGIN_SIZE) * 2; + buttonWidthDP = vsyncGroupBackground.GetTargetSize().width - DP(MARGIN_SIZE) * 2; { Toolkit::PushButton button = Toolkit::PushButton::New(); diff --git a/examples/magnifier/magnifier-example.cpp b/examples/magnifier/magnifier-example.cpp index ebaa264..f28529b 100644 --- a/examples/magnifier/magnifier-example.cpp +++ b/examples/magnifier/magnifier-example.cpp @@ -227,12 +227,14 @@ public: // Create magnifier (controlled by human touch) Layer overlay = Layer::New(); + overlay.SetRelayoutEnabled( false ); overlay.SetSensitive(false); overlay.SetParentOrigin( ParentOrigin::CENTER ); overlay.SetSize(mStageSize); Stage::GetCurrent().Add(overlay); mMagnifier = Toolkit::Magnifier::New(); + mMagnifier.SetRelayoutEnabled( false ); mMagnifier.SetSourceActor( mView.GetBackgroundLayer() ); mMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width mMagnifier.SetMagnificationFactor( MAGNIFICATION_FACTOR ); @@ -251,6 +253,7 @@ public: // Create bouncing magnifier automatically bounces around screen. mBouncingMagnifier = Toolkit::Magnifier::New(); + mBouncingMagnifier.SetRelayoutEnabled( false ); mBouncingMagnifier.SetSourceActor( mView.GetBackgroundLayer() ); mBouncingMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width mBouncingMagnifier.SetMagnificationFactor( MAGNIFICATION_FACTOR ); diff --git a/examples/page-turn-view/page-turn-view-example.cpp b/examples/page-turn-view/page-turn-view-example.cpp index fa412ad..8f5d147 100644 --- a/examples/page-turn-view/page-turn-view-example.cpp +++ b/examples/page-turn-view/page-turn-view-example.cpp @@ -78,14 +78,20 @@ class PortraitPageFactory : public PageFactory */ virtual Actor NewPage( unsigned int pageId ) { + ImageActor page; + if( pageId == 0 ) { - return ImageActor::New( ResourceImage::New( BOOK_COVER_PORTRAIT ) ); + page = ImageActor::New( ResourceImage::New( BOOK_COVER_PORTRAIT ) ); } else { - return ImageActor::New( ResourceImage::New( PAGE_IMAGES_PORTRAIT[ (pageId-1) % NUMBER_OF_PORTRAIT_IMAGE ] ) ); + page = ImageActor::New( ResourceImage::New( PAGE_IMAGES_PORTRAIT[ (pageId-1) % NUMBER_OF_PORTRAIT_IMAGE ] ) ); } + + page.SetRelayoutEnabled( false ); + + return page; } }; @@ -120,6 +126,10 @@ class LandscapePageFactory : public PageFactory pageBack = ImageActor::New( ResourceImage::New( PAGE_IMAGES_LANDSCAPE[ (imageId+1) % NUMBER_OF_LANDSCAPE_IMAGE ] ) ); } pageFront.Add(pageBack); + + pageFront.SetRelayoutEnabled( false ); + pageBack.SetRelayoutEnabled( false ); + return pageFront; } }; @@ -223,6 +233,7 @@ void PageTurnController::OnInit( Application& app ) // Create default View. mView = View::New(); + mView.SetRelayoutEnabled( false ); stage.Add( mView ); Dali::Window winHandle = app.GetWindow(); @@ -236,6 +247,7 @@ void PageTurnController::OnInit( Application& app ) mView.OrientationAnimationStartedSignal().Connect( this, &PageTurnController::OnOrientationAnimationStarted ); mPageTurnPortraitView = PageTurnPortraitView::New( mPortraitPageFactory, stageSize ); + mPageTurnPortraitView.SetRelayoutEnabled( false ); mPageTurnPortraitView.SetSpineShadowParameter( Vector2(70.f, 30.f) ); mPageTurnPortraitView.PageTurnStartedSignal().Connect( this, &PageTurnController::OnPageStartedTurn ); mPageTurnPortraitView.PageTurnFinishedSignal().Connect( this, &PageTurnController::OnPageFinishedTurn ); @@ -244,6 +256,7 @@ void PageTurnController::OnInit( Application& app ) mPageTurnPortraitView.SetPositionInheritanceMode( USE_PARENT_POSITION ); mPageTurnLandscapeView = PageTurnLandscapeView::New( mLandscapePageFactory, Vector2(stageSize.y*0.5f, stageSize.x) ); + mPageTurnLandscapeView.SetRelayoutEnabled( false ); mPageTurnLandscapeView.PageTurnStartedSignal().Connect( this, &PageTurnController::OnPageStartedTurn ); mPageTurnLandscapeView.PageTurnFinishedSignal().Connect( this, &PageTurnController::OnPageFinishedTurn ); mPageTurnLandscapeView.PagePanStartedSignal().Connect( this, &PageTurnController::OnPageStartedPan ); diff --git a/examples/path-animation/path-animation.cpp b/examples/path-animation/path-animation.cpp index 2611be4..c602254 100644 --- a/examples/path-animation/path-animation.cpp +++ b/examples/path-animation/path-animation.cpp @@ -69,6 +69,7 @@ public: textActor.SetSize(size.y,size.y,0.0f); Slider slider = Slider::New(); + slider.SetRelayoutEnabled( false ); slider.SetAnchorPoint( AnchorPoint::CENTER_LEFT); slider.SetParentOrigin( ParentOrigin::CENTER_RIGHT); slider.SetProperty(Slider::Property::LOWER_BOUND, -1.0f ); @@ -100,6 +101,7 @@ public: //TextInput Dali::Layer controlsLayer = Dali::Layer::New(); + controlsLayer.SetRelayoutEnabled( false ); controlsLayer.SetSize( stage.GetSize().x, stage.GetSize().y*0.3f, 0.0 ); controlsLayer.SetPosition( 0.0f, stage.GetSize().y*0.8f, 0.0f ); controlsLayer.SetAnchorPoint( AnchorPoint::TOP_LEFT); @@ -199,6 +201,7 @@ public: if( !mControlPoint[index] ) { mControlPoint[index] = Toolkit::CreateSolidColorActor(Vector4(1.0f,1.0f,1.0f,1.0f)); + mControlPoint[index].SetRelayoutEnabled( false ); mControlPoint[index].SetParentOrigin( ParentOrigin::TOP_LEFT); mControlPoint[index].SetAnchorPoint( AnchorPoint::CENTER ); mControlPoint[index].SetSize( 20.0f, 20.0f ); @@ -220,6 +223,7 @@ public: if( !mControlPoint[index]) { mControlPoint[index] = Toolkit::CreateSolidColorActor(Vector4(1.0f,1.0f,1.0f,1.0f)); + mControlPoint[index].SetRelayoutEnabled( false ); mControlPoint[index].SetParentOrigin( ParentOrigin::TOP_LEFT); mControlPoint[index].SetAnchorPoint( AnchorPoint::CENTER ); mControlPoint[index].SetSize( 20.0f, 20.0f ); @@ -470,6 +474,7 @@ public: ImageAttributes attributes; Image img = ResourceImage::New(ACTOR_IMAGE, attributes ); mActor = ImageActor::New( img ); + mActor.SetRelayoutEnabled( false ); mActor.SetAnchorPoint( AnchorPoint::CENTER ); mActor.SetSize( 100, 50, 1 ); stage.Add( mActor ); diff --git a/examples/scroll-view/scroll-view-example.cpp b/examples/scroll-view/scroll-view-example.cpp index b69ea83..de3dfa4 100644 --- a/examples/scroll-view/scroll-view-example.cpp +++ b/examples/scroll-view/scroll-view-example.cpp @@ -226,6 +226,7 @@ private: Vector2 stageSize = stage.GetSize(); mScrollView = ScrollView::New(); + mScrollView.SetRelayoutEnabled( false ); mScrollView.SetAnchorPoint(AnchorPoint::CENTER); mScrollView.SetParentOrigin(ParentOrigin::CENTER); mContentLayer.Add( mScrollView ); @@ -298,7 +299,8 @@ private: Actor CreatePage() { Actor page = Actor::New(); - page.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + page.SetRelayoutEnabled( true ); + page.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); page.SetParentOrigin( ParentOrigin::CENTER ); page.SetAnchorPoint( AnchorPoint::CENTER ); @@ -450,7 +452,8 @@ private: void ApplyEffectToPage(Actor page) { page.RemoveConstraints(); - page.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + page.SetRelayoutEnabled( true ); + page.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); switch( mEffectMode ) { @@ -566,6 +569,7 @@ private: attributes.SetFilterMode( ImageAttributes::BoxThenLinear ); Image img = ResourceImage::New(filename, attributes); ImageActor actor = ImageActor::New(img); + actor.SetRelayoutEnabled( false ); actor.SetName( filename ); actor.SetParentOrigin(ParentOrigin::CENTER); actor.SetAnchorPoint(AnchorPoint::CENTER); diff --git a/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp b/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp index 6b8b917..09ee56c 100644 --- a/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp +++ b/examples/shadow-bone-lighting/shadow-bone-lighting-example.cpp @@ -213,7 +213,8 @@ public: mShadowView.SetName("Container"); mShadowView.SetParentOrigin(ParentOrigin::CENTER); mShadowView.SetAnchorPoint(AnchorPoint::CENTER); - mShadowView.SetSizeMode( SIZE_EQUAL_TO_PARENT ); + mShadowView.SetRelayoutEnabled( true ); + mShadowView.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); mShadowView.SetPointLightFieldOfView( Math::PI / 2.0f); mContents.Add(mShadowView); diff --git a/examples/size-negotiation/size-negotiation-example.cpp b/examples/size-negotiation/size-negotiation-example.cpp new file mode 100644 index 0000000..130f83b --- /dev/null +++ b/examples/size-negotiation/size-negotiation-example.cpp @@ -0,0 +1,1346 @@ +/* + * Copyright (c) 2014 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. + * + */ + +#include "shared/view.h" +#include +#include + +using namespace Dali; + +// Define this so that it is interchangeable +// "DP" stands for Device independent Pixels +#define DP(x) DemoHelper::ScalePointSize(x) + +struct ButtonItem +{ + const char* name; + const char* text; +}; + + +namespace +{ + +const char* const BACKGROUND_IMAGE = DALI_IMAGE_DIR "background-gradient.jpg"; +const char* const TOOLBAR_IMAGE = DALI_IMAGE_DIR "top-bar.png"; + +const char* const TOOLBAR_TITLE = "Size Negotiation"; +const int TOOLBAR_HEIGHT = 62; + +const char* MENU_ICON_IMAGE = DALI_IMAGE_DIR "icon-cluster-none.png"; + +const char* const PUSHBUTTON_BUTTON_IMAGE = DALI_IMAGE_DIR "button-up.9.png"; +const char* const PUSHBUTTON_PRESS_IMAGE = DALI_IMAGE_DIR "button-down.9.png"; + +const char* const POPUPS_MENU_ID = "POPUPS_MENU"; +const char* const TABLEVIEW_MENU_ID = "TABLEVIEW_MENU"; + +const char* const POPUP_BUTTON_EMPTY_ID = "POPUP_BUTTON_EMPTY"; +const char* const POPUP_BUTTON_TITLE_ID = "POPUP_BUTTON_TITLE"; +const char* const POPUP_BUTTON_BUTTONS_1_ID = "POPUP_BUTTON_BUTTONS_1"; +const char* const POPUP_BUTTON_BUTTONS_2_ID = "POPUP_BUTTON_BUTTONS_2"; +const char* const POPUP_BUTTON_TITLE_BUTTONS_ID = "POPUP_BUTTON_TITLE_BUTTONS"; +const char* const POPUP_BUTTON_CONTENT_TEXT_ID = "POPUP_BUTTON_CONTENT_TEXT"; +const char* const POPUP_BUTTON_CONTENT_IMAGE_ID = "POPUP_BUTTON_CONTENT_IMAGE"; +const char* const POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID = "POPUP_BUTTON_CONTENT_IMAGE_SCALE"; +const char* const POPUP_BUTTON_CONTENT_IMAGE_FIT_ID = "POPUP_BUTTON_CONTENT_IMAGE_FIT"; +const char* const POPUP_BUTTON_CONTENT_IMAGE_FILL_ID = "POPUP_BUTTON_CONTENT_IMAGE_FILL"; +const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_ID = "POPUP_BUTTON_TITLE_CONTENT_TEXT"; +const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_BUTTONS_ID = "POPUP_BUTTON_TITLE_CONTENT_TEXT_BUTTONS"; +const char* const POPUP_BUTTON_COMPLEX_ID = "POPUP_BUTTON_COMPLEX"; + +const char* const TABLEVIEW_BUTTON_EMPTY_ID = "TABLEVIEW_BUTTON_EMPTY"; +const char* const TABLEVIEW_BUTTON_1CELL_ID = "TABLEVIEW_BUTTON_1CELL"; +const char* const TABLEVIEW_BUTTON_3CELL_ID = "TABLEVIEW_BUTTON_3CELL"; +const char* const TABLEVIEW_BUTTON_3X3CELL_ID = "TABLEVIEW_BUTTON_3X3CELL"; +const char* const TABLEVIEW_BUTTON_FIXED1_ID = "TABLEVIEW_BUTTON_FIXED1"; +const char* const TABLEVIEW_BUTTON_FIXED2_ID = "TABLEVIEW_BUTTON_FIXED2"; +const char* const TABLEVIEW_BUTTON_FIT1_ID = "TABLEVIEW_BUTTON_FIT1"; +const char* const TABLEVIEW_BUTTON_FIT2_ID = "TABLEVIEW_BUTTON_FIT2"; +const char* const TABLEVIEW_BUTTON_NATURAL1_ID = "TABLEVIEW_BUTTON_NATURAL1"; +const char* const TABLEVIEW_BUTTON_NATURAL2_ID = "TABLEVIEW_BUTTON_NATURAL2"; +const char* const TABLEVIEW_BUTTON_NATURAL3_ID = "TABLEVIEW_BUTTON_NATURAL3"; + +const char* const OKAY_BUTTON_ID = "OKAY_BUTTON"; +const char* const CANCEL_BUTTON_ID = "CANCEL_BUTTON"; + +const char* const CONTENT_TEXT = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; +const char* const IMAGE1 = DALI_IMAGE_DIR "gallery-medium-5.jpg"; +const char* const IMAGE2 = DALI_IMAGE_DIR "background-magnifier.jpg"; +const char* const CHECKBOX_UNCHECKED_IMAGE = DALI_IMAGE_DIR "checkbox-unselected.png"; +const char* const CHECKBOX_CHECKED_IMAGE = DALI_IMAGE_DIR "checkbox-selected.png"; + +const ButtonItem MENU_ITEMS[] = { + { POPUPS_MENU_ID, "Popups" }, + { TABLEVIEW_MENU_ID, "TableView" } +}; + +const unsigned int MENU_ITEMS_COUNT = sizeof( MENU_ITEMS ) / sizeof( MENU_ITEMS[0] ); + +const ButtonItem POPUP_BUTTON_ITEMS[] = { + { POPUP_BUTTON_COMPLEX_ID, "Complex" }, + { POPUP_BUTTON_EMPTY_ID, "Empty" }, + { POPUP_BUTTON_TITLE_ID, "Title" }, + { POPUP_BUTTON_BUTTONS_1_ID, "1 Button" }, + { POPUP_BUTTON_BUTTONS_2_ID, "2 Buttons" }, + { POPUP_BUTTON_TITLE_BUTTONS_ID, "Title & Buttons" }, + { POPUP_BUTTON_CONTENT_TEXT_ID, "Text" }, + { POPUP_BUTTON_CONTENT_IMAGE_ID, "Image" }, + { POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID, "Image Scale" }, + { POPUP_BUTTON_CONTENT_IMAGE_FIT_ID, "Image Fit" }, + { POPUP_BUTTON_CONTENT_IMAGE_FILL_ID, "Image Fill" }, + { POPUP_BUTTON_TITLE_CONTENT_TEXT_ID, "Title Text" }, + { POPUP_BUTTON_TITLE_CONTENT_TEXT_BUTTONS_ID, "Title, text, buttons" } + +}; + +const int POPUP_BUTTON_ITEMS_COUNT = sizeof( POPUP_BUTTON_ITEMS ) / sizeof( POPUP_BUTTON_ITEMS[0] ); + +const ButtonItem TABLEVIEW_BUTTON_ITEMS[] = { + { TABLEVIEW_BUTTON_EMPTY_ID, "Empty" }, + { TABLEVIEW_BUTTON_1CELL_ID, "1 Cell" }, + { TABLEVIEW_BUTTON_3CELL_ID, "3 Cell" }, + { TABLEVIEW_BUTTON_3X3CELL_ID, "3x3 Cells" }, + { TABLEVIEW_BUTTON_FIXED1_ID, "Fixed 1" }, + { TABLEVIEW_BUTTON_FIXED2_ID, "Fixed 2" }, + { TABLEVIEW_BUTTON_FIT1_ID, "Fit Top Bottom" }, + { TABLEVIEW_BUTTON_FIT2_ID, "Fit Middle" }, + { TABLEVIEW_BUTTON_NATURAL1_ID, "Natural 1" }, + { TABLEVIEW_BUTTON_NATURAL2_ID, "Natural 2" }, + { TABLEVIEW_BUTTON_NATURAL3_ID, "Natural 3" }, +}; + +const unsigned int TABLEVIEW_BUTTON_ITEMS_COUNT = sizeof( TABLEVIEW_BUTTON_ITEMS ) / sizeof( TABLEVIEW_BUTTON_ITEMS[0] ); + +} // namespace + + + +/** + * This example shows the usage of size negotiation. + */ +class SizeNegotiationController: public ConnectionTracker, public Toolkit::ItemFactory +{ +public: + + SizeNegotiationController( Application& application ) + : mApplication( application ), + mMenuShown( false ), + mDemoState( POPUP ) + { + // Connect to the Application's Init signal + mApplication.InitSignal().Connect( this, &SizeNegotiationController::Create ); + } + + ~SizeNegotiationController() + { + // Nothing to do here + } + + void Create( Application& application ) + { + // The Init signal is received once (only) during the Application lifetime + + Stage stage = Stage::GetCurrent(); + + // Respond to key events + stage.KeyEventSignal().Connect(this, &SizeNegotiationController::OnKeyEvent); + + // Creates a default view with a default tool bar. + // The view is added to the stage. + mContentLayer = DemoHelper::CreateView( application, + mView, + mToolBar, + BACKGROUND_IMAGE, + TOOLBAR_IMAGE, + std::string("") ); + + mTitleActor = Dali::Toolkit::TextView::New(); + mTitleActor.SetName( "CUSTOM_TOOLBAR_TITLE" ); + + SetTitle(); + + // Create menu button + Toolkit::PushButton viewButton = Toolkit::PushButton::New(); + viewButton.SetBackgroundImage( ResourceImage::New( MENU_ICON_IMAGE ) ); + viewButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnMenu ); + mToolBar.AddControl( viewButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); + + // Add title to the tool bar. + const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding ); + mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) ); + + mItemView = Toolkit::ItemView::New( *this ); + mItemView.SetParentOrigin( ParentOrigin::CENTER ); + mItemView.SetAnchorPoint( AnchorPoint::CENTER ); + mItemView.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + // Use a grid layout for tests + Toolkit::GridLayoutPtr gridLayout = Toolkit::GridLayout::New(); + gridLayout->SetNumberOfColumns( 2 ); + gridLayout->SetTopMargin( DP(TOOLBAR_HEIGHT) + DP(20.0f) ); + gridLayout->SetBottomMargin( DP(100.0f) ); + gridLayout->SetRowSpacing( DP(20.0f) ); + mItemView.AddLayout( *gridLayout ); + + Vector2 stageSize = stage.GetSize(); + float layoutWidth = Toolkit::IsHorizontal( gridLayout->GetOrientation() ) ? stageSize.height : stageSize.width; + float gridItemSize = ( layoutWidth / gridLayout->GetNumberOfColumns() ) * 0.5f; + gridLayout->SetScrollSpeedFactor( gridLayout->GetNumberOfColumns() / gridItemSize * 0.5f ); + + mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f ); + + mContentLayer.Add( mItemView ); + } + + void SetTitle() + { + std::string subTitle = ""; + + switch( mDemoState ) + { + case POPUP: + { + subTitle = "Popups"; + break; + } + + case TABLEVIEW: + { + subTitle = "TableView"; + break; + } + + default: + { + break; + } + } + + mTitleActor.SetText( std::string( TOOLBAR_TITLE ) + ": " + subTitle ); + mTitleActor.SetStyleToCurrentText( DemoHelper::GetDefaultTextStyle() ); + } + + bool OnMenu( Toolkit::Button button ) + { + ShowMenu(); + return true; + } + + void ShowMenu() + { + Stage stage = Stage::GetCurrent(); + const float popupWidth = stage.GetSize().x * 0.5f; + + mMenu = Toolkit::Popup::New(); + mMenu.SetParentOrigin( ParentOrigin::TOP_LEFT ); + mMenu.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + mMenu.HideTail(); + mMenu.OutsideTouchedSignal().Connect( this, &SizeNegotiationController::HideMenu ); + mMenu.SetPreferredSize( Vector2( popupWidth, 0.0f ) ); + mMenu.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT ); + + Toolkit::TableView tableView = Toolkit::TableView::New( 0, 0 ); + tableView.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + tableView.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT ); + mMenu.Add( tableView ); + + for( unsigned int i = 0; i < MENU_ITEMS_COUNT; ++i ) + { + Toolkit::PushButton menuButton = Toolkit::PushButton::New(); + menuButton.SetName( MENU_ITEMS[ i ].name ); + menuButton.SetLabel( MENU_ITEMS[ i ].text ); + menuButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnMenuSelect ); + + tableView.Add( menuButton ); + tableView.SetFitHeight( i ); + } + + // Show the menu + mMenu.Show(); + mMenuShown = true; + } + + void HideMenu() + { + if( mMenu ) + { + mMenu.Hide(); + mMenu.Reset(); + } + + mMenuShown = false; + } + + bool OnMenuSelect( Toolkit::Button button ) + { + bool refresh = false; + + if( button.GetName() == POPUPS_MENU_ID ) + { + if( mDemoState != POPUP ) + { + refresh = true; + mDemoState = POPUP; + } + } + else if( button.GetName() == TABLEVIEW_MENU_ID ) + { + if( mDemoState != TABLEVIEW ) + { + refresh = true; + mDemoState = TABLEVIEW; + } + } + + if( refresh ) + { + SetTitle(); + + mItemView.Refresh(); + } + + HideMenu(); + return true; + } + + Toolkit::Popup CreatePopup() + { + Stage stage = Stage::GetCurrent(); + const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f; + + Toolkit::Popup popup = Toolkit::Popup::New(); + popup.SetName( "POPUP" ); + popup.SetParentOrigin( ParentOrigin::CENTER ); + popup.SetAnchorPoint( AnchorPoint::CENTER ); + popup.SetPreferredSize( Vector2( POPUP_WIDTH_DP, 0.0f ) ); + popup.HideTail(); + + popup.OutsideTouchedSignal().Connect( this, &SizeNegotiationController::OnPopupOutsideTouched ); + + return popup; + } + + bool OnButtonClicked( Toolkit::Button button ) + { + if( button.GetName() == POPUP_BUTTON_EMPTY_ID ) + { + mPopup = CreatePopup(); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_TITLE_ID ) + { + mPopup = CreatePopup(); + mPopup.SetTitle( "Popup!" ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_BUTTONS_1_ID ) + { + mPopup = CreatePopup(); + + Toolkit::PushButton okayButton = Toolkit::PushButton::New(); + okayButton.SetName( OKAY_BUTTON_ID ); + okayButton.SetLabel( "OK!" ); + okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + + okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + + mPopup.AddButton( okayButton ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_BUTTONS_2_ID ) + { + mPopup = CreatePopup(); + + Toolkit::PushButton cancelButton = Toolkit::PushButton::New(); + cancelButton.SetName( CANCEL_BUTTON_ID ); + cancelButton.SetLabel( "Cancel" ); + cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + + cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + + mPopup.AddButton( cancelButton ); + + Toolkit::PushButton okayButton = Toolkit::PushButton::New(); + okayButton.SetName( OKAY_BUTTON_ID ); + okayButton.SetLabel( "OK!" ); + okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + + okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + + mPopup.AddButton( okayButton ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_TITLE_BUTTONS_ID ) + { + mPopup = CreatePopup(); + mPopup.SetTitle( "Popup!" ); + + Toolkit::PushButton cancelButton = Toolkit::PushButton::New(); + cancelButton.SetName( CANCEL_BUTTON_ID ); + cancelButton.SetLabel( "Cancel" ); + cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + + cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + + mPopup.AddButton( cancelButton ); + + Toolkit::PushButton okayButton = Toolkit::PushButton::New(); + okayButton.SetName( OKAY_BUTTON_ID ); + okayButton.SetLabel( "OK!" ); + okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + + okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + + mPopup.AddButton( okayButton ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_CONTENT_TEXT_ID ) + { + mPopup = CreatePopup(); + + Toolkit::TextView text = Toolkit::TextView::New(); + text.SetName( "POPUP_CONTENT_TEXT" ); + text.SetText( CONTENT_TEXT ); + text.SetMultilinePolicy( Toolkit::TextView::SplitByWord ); + text.SetWidthExceedPolicy( Toolkit::TextView::Split ); + text.SetLineJustification( Toolkit::TextView::Center ); + text.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + text.SetDimensionDependency( HEIGHT, WIDTH ); + text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) ); + + mPopup.Add( text ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_ID ) + { + mPopup = CreatePopup(); + + ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) ); + image.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + image.SetDimensionDependency( HEIGHT, WIDTH ); + image.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) ); + + mPopup.Add( image ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID ) + { + mPopup = CreatePopup(); + + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) ); + image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + mPopup.Add( image ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FIT_ID ) + { + mPopup = CreatePopup(); + + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) ); + image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + image.SetSizeScalePolicy( FIT_WITH_ASPECT_RATIO ); + + mPopup.Add( image ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FILL_ID ) + { + mPopup = CreatePopup(); + + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) ); + image.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + image.SetSizeScalePolicy( FILL_WITH_ASPECT_RATIO ); + + mPopup.Add( image ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID ) + { + mPopup = CreatePopup(); + mPopup.SetTitle( "Popup!" ); + + Toolkit::TextView text = Toolkit::TextView::New(); + text.SetName( "POPUP_CONTENT_TEXT" ); + text.SetText( CONTENT_TEXT ); + text.SetMultilinePolicy( Toolkit::TextView::SplitByWord ); + text.SetWidthExceedPolicy( Toolkit::TextView::Split ); + text.SetLineJustification( Toolkit::TextView::Center ); + text.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + text.SetDimensionDependency( HEIGHT, WIDTH ); + text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) ); + + mPopup.Add( text ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_BUTTONS_ID ) + { + mPopup = CreatePopup(); + mPopup.SetTitle( "Popup!" ); + + Toolkit::TextView text = Toolkit::TextView::New(); + text.SetName( "POPUP_CONTENT_TEXT" ); + text.SetText( CONTENT_TEXT ); + text.SetMultilinePolicy( Toolkit::TextView::SplitByWord ); + text.SetWidthExceedPolicy( Toolkit::TextView::Split ); + text.SetLineJustification( Toolkit::TextView::Left ); + text.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + text.SetDimensionDependency( HEIGHT, WIDTH ); + text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) ); + + mPopup.Add( text ); + + Toolkit::PushButton cancelButton = Toolkit::PushButton::New(); + cancelButton.SetName( CANCEL_BUTTON_ID ); + cancelButton.SetLabel( "Cancel" ); + cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + + cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + + mPopup.AddButton( cancelButton ); + + Toolkit::PushButton okayButton = Toolkit::PushButton::New(); + okayButton.SetName( OKAY_BUTTON_ID ); + okayButton.SetLabel( "OK!" ); + okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + + okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + + mPopup.AddButton( okayButton ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == POPUP_BUTTON_COMPLEX_ID ) + { + mPopup = CreatePopup(); + mPopup.SetTitle( "Warning" ); + + // Content + Toolkit::TableView content = Toolkit::TableView::New( 2, 2 ); + content.SetName( "COMPLEX_TABLEVIEW" ); + content.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + content.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT ); + content.SetFitHeight( 0 ); + content.SetFitHeight( 1 ); + content.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 0.0f ) ); + + // Text + { + Toolkit::TextView text = Toolkit::TextView::New(); + text.SetText( "Do you really want to quit?" ); + text.SetMultilinePolicy( Toolkit::TextView::SplitByWord ); + text.SetWidthExceedPolicy( Toolkit::TextView::Split ); + text.SetLineJustification( Toolkit::TextView::Left ); + text.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + text.SetDimensionDependency( HEIGHT, WIDTH ); + + content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) ); + } + + // Image + { + ImageActor image = ImageActor::New( ResourceImage::New( IMAGE1 ) ); + image.SetName( "COMPLEX_IMAGE" ); + image.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + image.SetDimensionDependency( HEIGHT, WIDTH ); + image.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 0.0f ) ); + content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) ); + } + + // Text 2 + { + Toolkit::TableView root = Toolkit::TableView::New( 1, 2 ); + root.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + root.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT ); + root.SetFitHeight( 0 ); + root.SetFitWidth( 0 ); + root.SetPadding( Padding( 0.0f, 0.0f, 0.0f, 20.0f ) ); + + Dali::Image unchecked = Dali::ResourceImage::New( CHECKBOX_UNCHECKED_IMAGE ); + Dali::Image checked = Dali::ResourceImage::New( CHECKBOX_CHECKED_IMAGE ); + Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New(); + checkBox.SetBackgroundImage( unchecked ); + checkBox.SetSelectedImage( checked ); + checkBox.SetPreferredSize( Vector2( 48, 48 ) ); + checkBox.SetResizePolicy( FIXED, ALL_DIMENSIONS ); + + root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) ); + + Toolkit::TextView text = Toolkit::TextView::New(); + text.SetText( "Don't show again" ); + text.SetLineJustification( Toolkit::TextView::Left ); + Actor textActor = text; + textActor.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 10.0f ) ); + + root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) ); + + content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0, 0, 2 ) ); // Column span 2 + } + + mPopup.Add( content ); + + // Buttons + Toolkit::PushButton cancelButton = Toolkit::PushButton::New(); + cancelButton.SetName( CANCEL_BUTTON_ID ); + cancelButton.SetLabel( "Cancel" ); + cancelButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + cancelButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + + cancelButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + + mPopup.AddButton( cancelButton ); + + Toolkit::PushButton okayButton = Toolkit::PushButton::New(); + okayButton.SetName( OKAY_BUTTON_ID ); + okayButton.SetLabel( "OK!" ); + okayButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + okayButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + + okayButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + + mPopup.AddButton( okayButton ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_EMPTY_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + + Toolkit::TableView table = Toolkit::TableView::New( 0, 0 ); + table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_1CELL_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + + Toolkit::TableView table = Toolkit::TableView::New( 0, 0 ); + table.SetName( "TABLEVIEW_BUTTON_1CELL_ID" ); + table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.Add( backing ); + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_3CELL_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + + Toolkit::TableView table = Toolkit::TableView::New( 0, 0 ); + table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.Add( backing ); + } + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_3X3CELL_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + + Toolkit::TableView table = Toolkit::TableView::New( 3, 3 ); + table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + // Column 0 + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) ); + } + + // Column 1 + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 1 ) ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 1 ) ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 0.0f, 1.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 1 ) ); + } + + // Column 2 + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 2 ) ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.5f, 0.5f, 0.5f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 2 ) ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.5f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 2 ) ); + } + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_FIXED1_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + + Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); + table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.SetFixedHeight( 0, 50.0f ); + + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + TextActor text = TextActor::New( "Fixed" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + TextActor text = TextActor::New( "Fill" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + TextActor text = TextActor::New( "Fill" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + table.Add( backing ); + } + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_FIXED2_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + + Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); + table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.SetFixedHeight( 0, 50.0f ); + table.SetFixedHeight( 2, 50.0f ); + + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + TextActor text = TextActor::New( "Fixed" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + TextActor text = TextActor::New( "Fill" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + TextActor text = TextActor::New( "Fixed" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + table.Add( backing ); + } + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_FIT1_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + + Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); + table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.SetFitHeight( 0 ); + table.SetFitHeight( 2 ); + + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + backing.SetResizePolicy( FIXED, HEIGHT ); + backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) ); + + TextActor text = TextActor::New( "Fit" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + TextActor text = TextActor::New( "Fill" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + backing.SetResizePolicy( FIXED, HEIGHT ); + backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) ); + + TextActor text = TextActor::New( "Fit" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_FIT2_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) ); + + + Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); + table.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + table.SetFitHeight( 1 ); + + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + TextActor text = TextActor::New( "Fill" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + backing.SetResizePolicy( FIXED, HEIGHT ); + backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) ); + + TextActor text = TextActor::New( "Fit" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + TextActor text = TextActor::New( "Fill" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL1_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) ); + mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT ); + + Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); + table.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT ); + table.SetFitHeight( 0 ); + table.SetFitHeight( 1 ); + table.SetFitHeight( 2 ); + + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + backing.SetResizePolicy( FIXED, HEIGHT ); + backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) ); + + TextActor text = TextActor::New( "Fit" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + backing.SetResizePolicy( FIXED, HEIGHT ); + backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) ); + + TextActor text = TextActor::New( "Fit" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + backing.SetResizePolicy( FIXED, HEIGHT ); + backing.SetPreferredSize( Vector2( 0.0f, 300.0f ) ); + + TextActor text = TextActor::New( "Fit" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL2_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) ); + mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT ); + + Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); + table.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT ); + table.SetFitHeight( 0 ); + table.SetFitHeight( 1 ); + + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + backing.SetResizePolicy( FIXED, HEIGHT ); + backing.SetPreferredSize( Vector2( 0.0f, 100.0f ) ); + + TextActor text = TextActor::New( "Fit" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + backing.SetResizePolicy( FIXED, HEIGHT ); + backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) ); + + TextActor text = TextActor::New( "Fit" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL3_ID ) + { + mPopup = CreatePopup(); + mPopup.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + mPopup.SetSizeMode( SIZE_RELATIVE_TO_PARENT ); + mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) ); + mPopup.SetResizePolicy( FIT_TO_CHILDREN, HEIGHT ); + + Toolkit::TableView table = Toolkit::TableView::New( 3, 1 ); + table.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + table.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT ); + table.SetFixedHeight( 0, 20.0f ); + table.SetFitHeight( 1 ); + + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); + + TextActor text = TextActor::New( "Fixed" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + { + Actor backing = Toolkit::CreateSolidColorActor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) ); + backing.SetResizePolicy( FILL_TO_PARENT, WIDTH ); + backing.SetResizePolicy( FIXED, HEIGHT ); + backing.SetPreferredSize( Vector2( 0.0f, 200.0f ) ); + + TextActor text = TextActor::New( "Fit" ); + text.SetAnchorPoint( AnchorPoint::CENTER ); + text.SetParentOrigin( ParentOrigin::CENTER ); + backing.Add( text ); + + table.Add( backing ); + } + + mPopup.Add( table ); + + // The popup is not yet on the stage so needs to be flaged as dirty + mPopup.MarkDirtyForRelayout(); + + mPopup.Show(); + } + else if( button.GetName() == OKAY_BUTTON_ID || button.GetName() == CANCEL_BUTTON_ID ) + { + if( mPopup ) + { + mPopup.Hide(); + } + } + + return true; + } + + void OnPopupOutsideTouched() + { + if( mPopup ) + { + mPopup.Hide(); + } + } + + void OnKeyEvent( const KeyEvent& event ) + { + if( event.state == KeyEvent::Down ) + { + if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + { + // Exit application when click back or escape. + mApplication.Quit(); + } + } + } + +public: // From ItemFactory + + /** + * @brief Return the number of items to display in the item view + * + * @return Return the number of items to display + */ + virtual unsigned int GetNumberOfItems() + { + switch( mDemoState ) + { + case POPUP: + { + return POPUP_BUTTON_ITEMS_COUNT; + } + + case TABLEVIEW: + { + return TABLEVIEW_BUTTON_ITEMS_COUNT; + } + + default: + { + break; + } + } + + return 0; + } + + /** + * @brief Create a new item to populate the item view with + * + * @param[in] itemId The index of the item to create + * @return Return the created actor for the given ID + */ + virtual Actor NewItem(unsigned int itemId) + { + const ButtonItem* buttonDataArray = NULL; + switch( mDemoState ) + { + case POPUP: + { + buttonDataArray = POPUP_BUTTON_ITEMS; + break; + } + + case TABLEVIEW: + { + buttonDataArray = TABLEVIEW_BUTTON_ITEMS; + break; + } + + default: + { + break; + } + } + + if( buttonDataArray ) + { + Toolkit::PushButton popupButton = Toolkit::PushButton::New(); + popupButton.SetName( buttonDataArray[ itemId ].name ); + popupButton.SetLabel( buttonDataArray[ itemId ].text ); + popupButton.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS ); + + popupButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) ); + popupButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) ); + + popupButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked ); + + return popupButton; + } + + return Actor(); + } + +private: + + enum DemoState + { + POPUP, + TABLEVIEW + }; + + Application& mApplication; + Toolkit::View mView; ///< The View instance. + Toolkit::ToolBar mToolBar; ///< The View's Toolbar. + Layer mContentLayer; ///< Content layer + + Toolkit::TextView mTitleActor; ///< Title text + + Toolkit::Popup mMenu; ///< The navigation menu + bool mMenuShown; ///< If the navigation menu is currently being displayed or not + + Toolkit::Popup mPopup; + + Toolkit::ItemView mItemView; ///< ItemView to hold test images + + DemoState mDemoState; +}; + +void RunTest( Application& application ) +{ + SizeNegotiationController test( application ); + + application.MainLoop(); +} + +// Entry point for Linux & SLP applications +// +int main( int argc, char **argv ) +{ + Application application = Application::New( &argc, &argv ); + + RunTest( application ); + + return 0; +} diff --git a/examples/text-view/text-view-example.cpp b/examples/text-view/text-view-example.cpp index 155a8c4..aefda6d 100644 --- a/examples/text-view/text-view-example.cpp +++ b/examples/text-view/text-view-example.cpp @@ -75,14 +75,14 @@ const TableString TABLE_STRINGS[] = { { "HelveticaNue", "Regular", 8.0f, { "HelveticaNue", "Regular", 12.0f, Dali::TextStyle::REGULAR, Vector4( 0.5f, 1.0f, 1.0f, 1.0f ), "Hola", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 90.0f, { 2, 0, 4, 2 } }, { "HelveticaNue", "Regular", 18.0f, Dali::TextStyle::BOLD, Vector4( 0.5f, 1.0f, 0.5f, 1.0f ), "Bonjour", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 2, 2, 2, 4 } }, { "HelveticaNue", "Regular", 12.0f, Dali::TextStyle::REGULAR, Vector4( 1.0f, 1.0f, 0.5f, 1.0f ), "Ciao", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 2, 7, 2, 3 } }, - { "HelveticaNue", "Regular", 26.0f, Dali::TextStyle::EXTRABLACK, Vector4( 0.5f, 0.0f, 0.0f, 1.0f ), "Hello", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 4, 2, 1, 6 } }, + { "HelveticaNue", "Regular", 23.0f, Dali::TextStyle::EXTRABLACK, Vector4( 0.5f, 0.0f, 0.0f, 1.0f ), "안녕하세요", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 20.0f, 0.0f, { 4, 3, 1, 6 } }, { "HelveticaNue", "Regular", 8.0f, Dali::TextStyle::DEMIBOLD, Vector4( 0.0f, 0.5f, 0.0f, 1.0f ), "Top of the morning to you", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 90.0f, { 4, 10, 8, 2 } }, - { "HelveticaNue", "Regular", 13.0f, Dali::TextStyle::DEMIBOLD, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), "हैलो", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 6, 1, 1, 3 } }, + { "HelveticaNue", "Regular", 13.0f, Dali::TextStyle::DEMIBOLD, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), "हैलो", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 6, 1, 1, 3 } }, { "HelveticaNue", "Regular", 8.0f, Dali::TextStyle::DEMIBOLD, Vector4( 1.0f, 1.0f, 0.0f, 1.0f ), "สวัสดี", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 90.0f, { 6, 5, 2, 1 } }, { "HelveticaNue", "Regular", 18.0f, Dali::TextStyle::REGULAR, Vector4( 0.0f, 1.0f, 1.0f, 1.0f ), "你好", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalBottom, 10.0f, 0.0f, { 6, 6, 1, 3 } }, { "HelveticaNue", "Regular", 34.0f, Dali::TextStyle::REGULAR, Vector4( 0.0f, 0.0f, 1.0f, 1.0f ), "G'day", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 7, 0, 2, 10 } }, { "HelveticaNue", "Regular", 16.0f, Dali::TextStyle::EXTRABLACK, Vector4( 0.0f, 0.5f, 1.0f, 1.0f ), "مرحبا", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 9, 1, 2, 4 } }, - { "HelveticaNue", "Regular", 10.0f, Dali::TextStyle::EXTRABLACK, Vector4( 1.0f, 0.0f, 0.0f, 1.0f ), "こんにちは", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 10, 0, 2, 6 } }, + { "HelveticaNue", "Regular", 10.0f, Dali::TextStyle::EXTRABLACK, Vector4( 1.0f, 0.0f, 0.0f, 1.0f ), "こんにちは", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalCenter, 10.0f, 0.0f, { 10, 0, 2, 6 } }, { "HelveticaNue", "Regular", 14.0f, Dali::TextStyle::REGULAR, Vector4( 0.0f, 1.0f, 0.0f, 1.0f ), "aloha", Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::VerticalTop, 10.0f, 0.0f, { 10, 6, 2, 4 } } }; @@ -132,7 +132,7 @@ public: textContainer.SetParentOrigin( ParentOrigin::TOP_LEFT ); textContainer.SetAnchorPoint( AnchorPoint::TOP_LEFT ); textContainer.SetPosition( 0, TOOLBAR_HEIGHT ); - textContainer.SetSize( stage.GetSize().width, stage.GetSize().height - TOOLBAR_HEIGHT ); + textContainer.SetPreferredSize( Vector2( stage.GetSize().width, stage.GetSize().height - TOOLBAR_HEIGHT ) ); mContentLayer.Add( textContainer ); @@ -151,10 +151,12 @@ public: Toolkit::TextView textView = Toolkit::TextView::New( tableString.text ); textView.SetStyleToCurrentText( textStyle ); textView.SetOrientation( Dali::Degree( tableString.orientation ), Vector3( 0.0f, 0.0f, 1.0f ) ); + textView.SetResizePolicy( USE_NATURAL_SIZE, ALL_DIMENSIONS ); Toolkit::Alignment alignmentContainer = Toolkit::Alignment::New( tableString.horizontalAlignment, tableString.verticalAlignment ); - alignmentContainer.SetPadding( Toolkit::Alignment::Padding( tableString.padding, tableString.padding, tableString.padding, tableString.padding ) ); - alignmentContainer.SetScaling( Toolkit::Alignment::ScaleToFill ); + Actor alignmentContainerActor = alignmentContainer; + alignmentContainerActor.SetPadding( Padding( tableString.padding, tableString.padding, tableString.padding, tableString.padding ) ); + alignmentContainer.SetResizePolicy( FILL_TO_PARENT, ALL_DIMENSIONS ); alignmentContainer.Add( textView ); textContainer.AddChild( alignmentContainer, Toolkit::TableView::CellPosition( tableString.cellPosition.row, tableString.cellPosition.column, tableString.cellPosition.rowSpan, tableString.cellPosition.columnSpan ) ); diff --git a/resources/scripts/animated-buttons.json b/resources/scripts/animated-buttons.json index 234b80e..19af1d3 100644 --- a/resources/scripts/animated-buttons.json +++ b/resources/scripts/animated-buttons.json @@ -3,6 +3,7 @@ { "type": "ImageActor", "name": "On", + "relayout-enabled": false, "position": [ 374, 215, @@ -11,7 +12,7 @@ "size": [ 144, 144, - 1 + 1 ], "sizeAspectRatio": false, "color": [ @@ -33,6 +34,7 @@ { "type": "ImageActor", "name": "Off", + "relayout-enabled": false, "position": [ 129, 215, @@ -41,7 +43,7 @@ "size": [ 144, 144, - 1 + 1 ], "sizeAspectRatio": false, "color": [ @@ -63,6 +65,7 @@ { "type": "ImageActor", "name": "Right", + "relayout-enabled": false, "position": [ 418.5, 214.5, @@ -71,7 +74,7 @@ "size": [ 85, 161, - 1 + 1 ], "sizeAspectRatio": false, "visible": true, @@ -94,6 +97,7 @@ { "type": "ImageActor", "name": "Left", + "relayout-enabled": false, "position": [ 331, 214.5, @@ -102,7 +106,7 @@ "size": [ 88, 161, - 1 + 1 ], "sizeAspectRatio": false, "visible": true, @@ -125,6 +129,7 @@ { "type": "ImageActor", "name": "Middle", + "relayout-enabled": false, "position": [ 375.5, 214.5, @@ -138,7 +143,7 @@ "size": [ 1, 161, - 1 + 1 ], "sizeAspectRatio": false, "color": [ @@ -160,6 +165,7 @@ { "type": "ImageActor", "name": "Jelly", + "relayout-enabled": false, "position": [ 374, 215, @@ -168,7 +174,7 @@ "size": [ 144, 144, - 1 + 1 ], "sizeAspectRatio": false, "color": [ @@ -190,6 +196,7 @@ { "type": "Control", "name": "Left Black", + "relayout-enabled": false, "position": [ 144.5, 218.5, @@ -198,7 +205,7 @@ "size": [ 275, 243, - 1 + 1 ], "sizeAspectRatio": false, "background-color": [ @@ -218,6 +225,7 @@ { "type": "Control", "name": "Right Black", + "relayout-enabled": false, "position": [ 629.5, 218.5, @@ -226,7 +234,7 @@ "size": [ 335, 243, - 1 + 1 ], "sizeAspectRatio": false, "background-color": [ @@ -246,6 +254,7 @@ { "type": "ImageActor", "name": "JellyOff", + "relayout-enabled": false, "position": [ 121, -117, @@ -254,7 +263,7 @@ "size": [ 144, 144, - 1 + 1 ], "sizeAspectRatio": false, "color": [ @@ -276,6 +285,7 @@ { "type": "Control", "name": "Control On", + "relayout-enabled": false, "position": [ 371.26116838487997, 217.33333333333331, @@ -284,7 +294,7 @@ "size": [ 196, 184, - 1 + 1 ], "sizeAspectRatio": false, "scale": [ @@ -310,6 +320,7 @@ { "type": "Control", "name": "Control Off", + "relayout-enabled": false, "position": [ 123.5, -117, @@ -318,7 +329,7 @@ "size": [ 193, 182, - 1 + 1 ], "sizeAspectRatio": false, "color": [ diff --git a/resources/scripts/animated-colors.json b/resources/scripts/animated-colors.json index 923ec75..2b930e8 100644 --- a/resources/scripts/animated-colors.json +++ b/resources/scripts/animated-colors.json @@ -18,9 +18,11 @@ "stage": [ { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": true, "actors": [], "name": "Control 8", "position": [ @@ -60,9 +62,11 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": false, "actors": [], "name": "Container 2", "position": [ @@ -102,9 +106,11 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": false, "actors": [], "name": "Container 4", "position": [ @@ -181,9 +187,11 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": false, "actors": [], "name": "Container 5", "position": [ @@ -223,9 +231,11 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": false, "actors": [], "name": "Container 7", "position": [ @@ -302,9 +312,11 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": false, "actors": [], "name": "Container 8", "position": [ @@ -344,9 +356,11 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": false, "actors": [], "name": "Container 10", "position": [ @@ -534,9 +548,11 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": false, "actors": [], "name": "Control 4", "position": [ @@ -613,9 +629,11 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", @@ -695,6 +713,7 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [], "name": "Container 11", "position": [ @@ -734,12 +753,15 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": false, "actors": [ { "type": "Control", + "relayout-enabled": false, "actors": [], "name": "Container 15", "position": [ @@ -816,6 +838,7 @@ }, { "type": "Control", + "relayout-enabled": false, "actors": [], "name": "Container 16", "position": [ diff --git a/resources/scripts/animation.json b/resources/scripts/animation.json index ad13fd1..7a5f8aa 100644 --- a/resources/scripts/animation.json +++ b/resources/scripts/animation.json @@ -122,6 +122,7 @@ "image": { "filename": "{DALI_IMAGE_DIR}gallery-large-21.jpg" }, + "relayout-enabled": false, "position": [0, 200, 0], "size": [200, 200, 1], "signals": [{ diff --git a/resources/scripts/background-color.json b/resources/scripts/background-color.json index 30be044..dcf8103 100644 --- a/resources/scripts/background-color.json +++ b/resources/scripts/background-color.json @@ -29,6 +29,7 @@ // A container with a yellow background { "type": "Control", + "relayout-enabled": false, "parent-origin": "CENTER", "anchor-point": "BOTTOM_CENTER", "background-color": [1, 1, 0, 1], @@ -38,6 +39,7 @@ // A container with an image { "type": "Control", + "relayout-enabled": false, "parent-origin": "CENTER", "anchor-point": "TOP_CENTER", "size": [400, 150, 1], @@ -51,6 +53,7 @@ // A container with the same image blended in with a blue background { "type": "Control", + "relayout-enabled": false, "parent-origin": "BOTTOM_CENTER", "anchor-point": "BOTTOM_CENTER", "size": [400, 150, 1], diff --git a/shared/view.h b/shared/view.h index aba2d2d..0d29283 100644 --- a/shared/view.h +++ b/shared/view.h @@ -84,10 +84,12 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, const Dali::TextStyle& textStyle ) { Dali::Layer toolBarLayer = Dali::Layer::New(); + toolBarLayer.SetName( "TOOLBAR_LAYER" ); toolBarLayer.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER ); toolBarLayer.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER ); - toolBarLayer.ApplyConstraint( Dali::Constraint::New( Dali::Actor::Property::SIZE, Dali::ParentSource( Dali::Actor::Property::SIZE ), Dali::SourceWidthFixedHeight( style.mToolBarHeight ) ) ); - toolBarLayer.SetSize( 0.0f, style.mToolBarHeight ); + toolBarLayer.SetPreferredSize( Dali::Vector2( 0.0f, style.mToolBarHeight ) ); + toolBarLayer.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::WIDTH ); + toolBarLayer.SetResizePolicy( Dali::FIXED, Dali::HEIGHT ); // Raise tool bar layer to the top. toolBarLayer.RaiseToTop(); @@ -95,12 +97,14 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, // Tool bar Dali::Image image = Dali::ResourceImage::New( toolbarImagePath ); Dali::ImageActor toolBarBackground = Dali::ImageActor::New( image ); + toolBarBackground.SetName( "TOOLBAR_BACKGROUND" ); + toolBarBackground.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS ); toolBar = Dali::Toolkit::ToolBar::New(); + toolBar.SetName( "TOOLBAR" ); toolBar.SetBackground( toolBarBackground ); toolBar.SetParentOrigin( Dali::ParentOrigin::TOP_CENTER ); toolBar.SetAnchorPoint( Dali::AnchorPoint::TOP_CENTER ); - toolBar.SetSize( 0.0f, style.mToolBarHeight ); - toolBar.SetSizeMode( Dali::SIZE_EQUAL_TO_PARENT ); + toolBar.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS ); toolBarBackground.SetSortModifier(1.0f); // Add the tool bar to the too bar layer. @@ -112,7 +116,7 @@ Dali::Layer CreateToolbar( Dali::Toolkit::ToolBar& toolBar, if( !title.empty() ) { Dali::Toolkit::TextView titleActor = Dali::Toolkit::TextView::New(); - titleActor.SetName( "ToolbarTitle" ); + titleActor.SetName( "TOOLBAR_TITLE" ); titleActor.SetText( title ); titleActor.SetSize( font.MeasureText( title ) ); titleActor.SetStyleToCurrentText(textStyle); @@ -138,6 +142,7 @@ Dali::Layer CreateView( Dali::Application& application, // Create default View. view = Dali::Toolkit::View::New(); + view.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS ); // Add the view to the stage before setting the background. stage.Add( view ); @@ -164,13 +169,11 @@ Dali::Layer CreateView( Dali::Application& application, // Add tool bar layer to the view. view.AddContentLayer( toolBarLayer ); - - // Create a content layer. Dali::Layer contentLayer = Dali::Layer::New(); contentLayer.SetAnchorPoint( Dali::AnchorPoint::CENTER ); contentLayer.SetParentOrigin( Dali::ParentOrigin::CENTER ); - contentLayer.SetSizeMode( Dali::SIZE_EQUAL_TO_PARENT ); + contentLayer.SetResizePolicy( Dali::FILL_TO_PARENT, Dali::ALL_DIMENSIONS ); view.AddContentLayer( contentLayer ); contentLayer.LowerBelow( toolBarLayer ); -- 2.7.4