X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fpopup%2Fpopup-impl.cpp;h=4ba3a032069615c294d2b0fbe58232a2fcefb173;hp=8f1c9ef00a90c295dc0682d12317a1b7fd10b501;hb=df92f45e89c92ca9b2286d51116ff7b69e75c569;hpb=bf2155ead4441b35df9e85eb10743c5bedba777e diff --git a/dali-toolkit/internal/controls/popup/popup-impl.cpp b/dali-toolkit/internal/controls/popup/popup-impl.cpp index 8f1c9ef..4ba3a03 100755 --- a/dali-toolkit/internal/controls/popup/popup-impl.cpp +++ b/dali-toolkit/internal/controls/popup/popup-impl.cpp @@ -1,125 +1,45 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.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://floralicense.org/license/ -// -// 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. -// +/* + * 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. + * + */ +// CLASS HEADER #include +// EXTERNAL INCLUDES +#include // for strcmp +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// INTERNAL INCLUDES #include -#include #include - -#include -#include - +#include #include -#include +#include using namespace Dali; -using namespace std; - -namespace -{ -const float CONTENT_DEPTH = 1.0f; ///< 3D Effect of buttons/title etc. appearing off the popup. -const float POPUP_ANIMATION_DURATION = 0.5f; ///< Duration of hide/show animations -const float BACKING_DEPTH = -1.0f; ///< Depth of backing (positioned just behind dialog, so dialog catches hit events first) - -const float POPUP_WIDTH = 720.0f; ///< Width of Popup -const float POPUP_OUT_MARGIN_WIDTH = 16.f; ///< Space between the screen edge and the popup edge in the horizontal dimension. -const float POPUP_OUT_MARGIN_HEIGHT = 36.f; ///< Space between the screen edge and the popup edge in the vertical dimension. -const float POPUP_TITLE_WIDTH = 648.0f; ///( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); - self.Add(mLayer); - - mPopupBg = Actor::New(); - mPopupBg.SetParentOrigin(ParentOrigin::CENTER); - mPopupBg.SetAnchorPoint(AnchorPoint::CENTER); - mPopupBg.ApplyConstraint( Constraint::New( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); - mLayer.Add(mPopupBg); + mLayer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mLayer.SetDrawMode( DrawMode::OVERLAY ); // Any content after this point which is added to Self() will be reparented to // mContent. mAlterAddedChild = true; - // Add Backing (Dim effect) CreateBacking(); + mAlterAddedChild = false; // Add Dialog ( background image, title, content container, button container and tail ) CreateDialog(); + mLayer.Add( self ); + + mPopupLayout = Toolkit::TableView::New( 3, 1 ); + mPopupLayout.SetName( "POPUP_LAYOUT_TABLE" ); + mPopupLayout.SetParentOrigin(ParentOrigin::CENTER); + mPopupLayout.SetAnchorPoint(AnchorPoint::CENTER); + mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT ); + mPopupLayout.SetFitHeight( 0 ); // Set row to fit + mPopupLayout.SetFitHeight( 1 ); // Set row to fit + self.Add( mPopupLayout ); + + // Any content after this point which is added to Self() will be reparented to + // mContent. + mAlterAddedChild = true; + // Default content. - ShowTail(ParentOrigin::BOTTOM_CENTER); +// ShowTail(ParentOrigin::BOTTOM_CENTER); // Hide content by default. SetState( Toolkit::Popup::POPUP_HIDE, 0.0f ); @@ -243,6 +194,7 @@ void Popup::OnPropertySet( Property::Index index, Property::Value propertyValue Popup::~Popup() { + mLayer.Unparent(); } size_t Popup::GetButtonCount() const @@ -253,26 +205,38 @@ size_t Popup::GetButtonCount() const void Popup::SetBackgroundImage( Actor image ) { // Removes any previous background. - if( mBackgroundImage && mPopupBg ) + if( mBackgroundImage && mPopupLayout ) { - mPopupBg.Remove( mBackgroundImage ); + mPopupLayout.Remove( mBackgroundImage ); } // Adds new background to the dialog. mBackgroundImage = image; + mBackgroundImage.SetName( "POPUP_BACKGROUND_IMAGE" ); + // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing. mBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched ); - mPopupBg.Add( mBackgroundImage ); + mBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS ); + mBackgroundImage.SetAnchorPoint( AnchorPoint::CENTER ); + mBackgroundImage.SetParentOrigin( ParentOrigin::CENTER ); + + Vector3 border( mPopupStyle->backgroundOuterBorder.x, mPopupStyle->backgroundOuterBorder.z, 0.0f ); + mBackgroundImage.SetSizeModeFactor( border ); + + const bool prevAlter = mAlterAddedChild; + mAlterAddedChild = false; + Self().Add( mBackgroundImage ); + mAlterAddedChild = prevAlter; } void Popup::SetButtonAreaImage( Actor image ) { // Removes any previous area image. - if( mButtonAreaImage && mPopupBg ) + if( mButtonAreaImage && mPopupLayout ) { - mPopupBg.Remove( mButtonAreaImage ); + mPopupLayout.Remove( mButtonAreaImage ); } // Adds new area image to the dialog. @@ -281,43 +245,80 @@ void Popup::SetButtonAreaImage( Actor image ) // OnDialogTouched only consume the event. It prevents the touch event to be caught by the backing. mButtonAreaImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched ); - mPopupBg.Add( mButtonAreaImage ); -} + mButtonAreaImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + mButtonAreaImage.SetAnchorPoint( AnchorPoint::CENTER ); + mButtonAreaImage.SetParentOrigin( ParentOrigin::CENTER ); -void Popup::SetTitle( const std::string& text ) -{ - Toolkit::TextView titleActor = Toolkit::TextView::New(); - titleActor.SetText( text ); - titleActor.SetColor( Color::BLACK ); - titleActor.SetMultilinePolicy( Toolkit::TextView::SplitByWord ); - titleActor.SetWidthExceedPolicy( Toolkit::TextView::Split ); - titleActor.SetLineJustification( Toolkit::TextView::Center ); - - SetTitle( titleActor ); + if( GetButtonCount() > 0 ) + { + mBottomBg.Add( mButtonAreaImage ); + } } -void Popup::SetTitle( Toolkit::TextView titleActor ) +void Popup::SetTitle( const std::string& text ) { // Replaces the current title actor. - if( mTitle && mPopupBg ) + if( mPopupLayout ) { - mPopupBg.Remove( mTitle ); + mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 0, 0 ) ); } - mTitle = titleActor; - mPopupBg.Add( mTitle ); + mTitle = Toolkit::TextLabel::New( text ); + mTitle.SetName( "POPUP_TITLE" ); + mTitle.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true ); + mTitle.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" ); + + if( mPopupLayout ) + { + mTitle.SetPadding( Padding( 0.0f, 0.0f, mPopupStyle->margin, mPopupStyle->margin ) ); + mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); + mTitle.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); + mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) ); + } RelayoutRequest(); } -Toolkit::TextView Popup::GetTitle() const +std::string Popup::GetTitle() const { - return mTitle; + if( mTitle ) + { + return mTitle.GetProperty( Toolkit::TextLabel::Property::TEXT ); + } + + return std::string(); +} + +void Popup::CreateFooter() +{ + if( !mBottomBg ) + { + // Adds bottom background + mBottomBg = Actor::New(); + mBottomBg.SetName( "POPUP_BOTTOM_BG" ); + mBottomBg.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); + + mPopupLayout.SetFixedHeight( 2, mPopupStyle->bottomSize.height ); // Buttons + mPopupLayout.AddChild( mBottomBg, Toolkit::TableView::CellPosition( 2, 0 ) ); + } } void Popup::AddButton( Toolkit::Button button ) { mButtons.push_back( button ); + button.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::ALL_DIMENSIONS ); // Size will be assigned to it + + // If this is the first button added + if( mButtons.size() == 1 ) + { + CreateFooter(); + + if( mButtonAreaImage ) + { + mBottomBg.Add( mButtonAreaImage ); + } + } + mBottomBg.Add( button ); RelayoutRequest(); @@ -370,13 +371,15 @@ void Popup::ShowTail(const Vector3& position) if(image != "") { - Image tail = Image::New( image ); + Image tail = ResourceImage::New( image ); mTailImage = ImageActor::New(tail); - const Vector3 anchorPoint = AnchorPoint::FRONT_BOTTOM_RIGHT - position; + const Vector3 anchorPoint = AnchorPoint::BOTTOM_RIGHT - position; mTailImage.SetParentOrigin(position); mTailImage.SetAnchorPoint(anchorPoint); + CreateFooter(); + mBottomBg.Add(mTailImage); } } @@ -399,30 +402,25 @@ PopupStylePtr Popup::GetStyle() const void Popup::SetDefaultBackgroundImage() { - Image bg = Image::New( mPopupStyle->backgroundImage ); - ImageActor bgImage = ImageActor::New( bg ); - bgImage.SetStyle( ImageActor::STYLE_NINE_PATCH ); - bgImage.SetNinePatchBorder( mPopupStyle->backgroundScale9Border ); - - Image buttonBg = Image::New( mPopupStyle->buttonAreaImage ); + Image buttonBg = ResourceImage::New( mPopupStyle->buttonAreaImage ); ImageActor buttonBgImage = ImageActor::New( buttonBg ); buttonBgImage.SetStyle( ImageActor::STYLE_NINE_PATCH ); buttonBgImage.SetNinePatchBorder( mPopupStyle->buttonArea9PatchBorder ); - SetBackgroundImage( bgImage ); + SetBackgroundImage( ImageActor::New( ResourceImage::New( mPopupStyle->backgroundImage ) ) ); SetButtonAreaImage( buttonBgImage ); } void Popup::CreateBacking() { mBacking = Dali::Toolkit::CreateSolidColorActor( mPopupStyle->backingColor ); + mBacking.SetName( "POPUP_BACKING" ); - mBacking.SetPositionInheritanceMode(DONT_INHERIT_POSITION); + mBacking.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mBacking.SetSensitive(true); - mLayer.Add(mBacking); + mLayer.Add( mBacking ); mBacking.SetOpacity(0.0f); - mBacking.SetPosition(0.0f, 0.0f, BACKING_DEPTH); mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched ); mBacking.MouseWheelEventSignal().Connect(this, &Popup::OnBackingMouseWheelEvent); } @@ -431,19 +429,12 @@ void Popup::CreateDialog() { // Adds default background image. SetDefaultBackgroundImage(); - - // Adds bottom background - mBottomBg = Actor::New(); - mPopupBg.Add( mBottomBg ); } void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration ) { - const Vector2& stageSize( Stage::GetCurrent().GetSize() ); - Vector3 targetSize; float targetBackingAlpha; - Vector3 targetBackingSize; if(mState == state) { @@ -456,7 +447,6 @@ void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration { targetSize = Vector3(0.0f, 0.0f, 1.0f); targetBackingAlpha = 0.0f; - targetBackingSize = Vector3(0.0f, 0.0f, 1.0f); mShowing = false; ClearKeyInputFocus(); @@ -478,17 +468,16 @@ void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration { targetSize = Vector3(1.0f, 1.0f, 1.0f); targetBackingAlpha = 1.0f; - float length = (stageSize.width > stageSize.height) ? stageSize.width : stageSize.height; - targetBackingSize = Vector3( length, length, 1.0f ); mShowing = true; // Add contents to stage for showing. if( !mLayer.GetParent() ) { - mAlterAddedChild = false; - Self().Add(mLayer); - mAlterAddedChild = true; + Dali::Stage stage = Dali::Stage::GetCurrent(); + stage.Add( mLayer ); + mLayer.RaiseToTop(); } + Self().SetSensitive(true); SetKeyInputFocus(); @@ -517,8 +506,7 @@ void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration } } - mBacking.SetSize( targetBackingSize ); - + Actor self = Self(); if(duration > Math::MACHINE_EPSILON_1) { if ( mAnimation ) @@ -531,13 +519,13 @@ void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration if(mShowing) { - mAnimation.AnimateTo( Property(mBacking, Actor::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) ); - mAnimation.AnimateTo( Property(mPopupBg, Actor::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(duration * 0.5f, duration * 0.5f) ); + mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, duration * 0.5f) ); + mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunction::EASE_IN_OUT, TimePeriod(duration * 0.5f, duration * 0.5f) ); } else { - mAnimation.AnimateTo( Property(mBacking, Actor::COLOR_ALPHA), targetBackingAlpha, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) ); - mAnimation.AnimateTo( Property(mPopupBg, Actor::SCALE), targetSize, AlphaFunctions::EaseInOut, TimePeriod(0.0f, duration * 0.5f) ); + mAnimation.AnimateTo( Property(mBacking, Actor::Property::COLOR_ALPHA), targetBackingAlpha, AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, duration * 0.5f) ); + mAnimation.AnimateTo( Property(self, Actor::Property::SCALE), targetSize, AlphaFunction::EASE_IN_OUT, TimePeriod(0.0f, duration * 0.5f) ); } mAnimation.Play(); mAnimation.FinishedSignal().Connect(this, &Popup::OnStateAnimationFinished); @@ -545,7 +533,7 @@ void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration else { mBacking.SetOpacity( targetBackingAlpha ); - mPopupBg.SetScale( targetSize ); + self.SetScale( targetSize ); HandleStateChangeComplete(); } @@ -554,25 +542,25 @@ void Popup::HandleStateChange( Toolkit::Popup::PopupState state, float duration void Popup::HandleStateChangeComplete() { // Remove contents from stage if completely hidden. - if( (mState == Toolkit::Popup::POPUP_HIDE) && (mLayer.GetParent()) ) + if( ( mState == Toolkit::Popup::POPUP_HIDE ) && mLayer.GetParent() ) { - Self().Remove(mLayer); + mLayer.Unparent(); Self().SetSensitive( false ); // Guard against destruction during signal emission Toolkit::Popup handle( GetOwner() ); - mHiddenSignalV2.Emit(); + mHiddenSignal.Emit(); } } -Toolkit::Popup::TouchedOutsideSignalV2& Popup::OutsideTouchedSignal() +Toolkit::Popup::TouchedOutsideSignalType& Popup::OutsideTouchedSignal() { - return mTouchedOutsideSignalV2; + return mTouchedOutsideSignal; } -Toolkit::Popup::HiddenSignalV2& Popup::HiddenSignal() +Toolkit::Popup::HiddenSignalType& Popup::HiddenSignal() { - return mHiddenSignalV2; + return mHiddenSignal; } bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) @@ -580,13 +568,13 @@ bool Popup::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tra Dali::BaseHandle handle( object ); bool connected( true ); - Toolkit::Popup popup = Toolkit::Popup::DownCast(handle); + Toolkit::Popup popup = Toolkit::Popup::DownCast( handle ); - if( Dali::Toolkit::Popup::SIGNAL_TOUCHED_OUTSIDE == signalName ) + if( 0 == strcmp( signalName.c_str(), SIGNAL_TOUCHED_OUTSIDE ) ) { popup.OutsideTouchedSignal().Connect( tracker, functor ); } - else if( Dali::Toolkit::Popup::SIGNAL_HIDDEN == signalName ) + else if( 0 == strcmp( signalName.c_str(), SIGNAL_HIDDEN ) ) { popup.HiddenSignal().Connect( tracker, functor ); } @@ -615,7 +603,7 @@ bool Popup::OnBackingTouched(Actor actor, const TouchEvent& event) // Guard against destruction during signal emission Toolkit::Popup handle( GetOwner() ); - mTouchedOutsideSignalV2.Emit(); + mTouchedOutsideSignal.Emit(); } } @@ -642,169 +630,78 @@ void Popup::OnControlChildAdd( Actor& child ) // Removes previously added content. if( mContent ) { - mPopupBg.Remove( mContent ); + mPopupLayout.RemoveChildAt( Toolkit::TableView::CellPosition( 1, 0 ) ); } - // Reparent new content. - Self().Remove( child ); - // keep a handle to the new content. mContent = child; - mPopupBg.Add( mContent ); + mPopupLayout.AddChild( mContent, Toolkit::TableView::CellPosition( 1, 0 ) ); } } -void Popup::OnRelaidOut( Vector2 size, ActorSizeContainer& container ) +void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container ) { - // Set the popup size - Vector2 popupSize; - popupSize.width = size.width - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ); - popupSize.height = size.height - 2.f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ); - - // Update sizes of all popup's components. - - // Relayout background image. - // Adjust background position and size relative to parent to cater to outer Border. - // Some backgrounds are intended to over-spill. That is some content - // should appear outside the Dialog on all sides i.e. Shadows, glow effects. - const Vector4 outerBorder = mPopupStyle->backgroundOuterBorder; - - if( mBackgroundImage ) - { - Constraint constraint = Constraint::New( Actor::SIZE, - ParentSource( Actor::SIZE ), - BackgroundSizeConstraint(outerBorder) ); - - mBackgroundImage.RemoveConstraints(); - mBackgroundImage.ApplyConstraint( constraint ); - - mBackgroundImage.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - mBackgroundImage.SetParentOrigin( ParentOrigin::TOP_LEFT ); - mBackgroundImage.SetPosition( -outerBorder.x, -outerBorder.y, 0.0f ); - } - - if( mPopupBg && mButtonAreaImage ) - { - // If there are no buttons, button background is also removed. - if ( mButtons.size() == 0 ) - { - mPopupBg.Remove( mButtonAreaImage ); - } - else - { - Constraint constraint = Constraint::New( Actor::SIZE, - ParentSource( Actor::SIZE ), - ButtonAreaSizeConstraint(outerBorder) ); - - mButtonAreaImage.RemoveConstraints(); - mButtonAreaImage.ApplyConstraint( constraint ); - - mButtonAreaImage.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); - mButtonAreaImage.SetParentOrigin( ParentOrigin::BOTTOM_CENTER ); - mButtonAreaImage.SetY( -outerBorder.z - POPUP_OUT_MARGIN_HEIGHT ); - - mPopupBg.Add( mButtonAreaImage ); - } - } - - // Relayout title - Vector3 positionOffset( 0.0f, mPopupStyle->margin + POPUP_OUT_MARGIN_WIDTH, CONTENT_DEPTH ); - if( mTitle ) - { - Vector2 titleSize; - titleSize.width = popupSize.width; - titleSize.height = mTitle.GetHeightForWidth( titleSize.width ); - - // As the default size policy for text-view is Fixed & Fixed, a size needs to be set. - // Otherwise size-negotiation algorithm uses the GetNaturalSize() with doesn't take - // into account the multiline and exceed policies, giving as result a wrong size. - mTitle.SetSize( titleSize ); - Relayout( mTitle, titleSize, container ); - - mTitle.SetAnchorPoint( AnchorPoint::TOP_CENTER ); - mTitle.SetParentOrigin( ParentOrigin::TOP_CENTER ); - mTitle.SetPosition( positionOffset ); - - positionOffset.y += titleSize.height + mPopupStyle->margin; - } - - // Relayout content - if( mContent ) - { - Vector2 contentSize; - contentSize.width = popupSize.width; - - Toolkit::Control control = Toolkit::Control::DownCast( mContent ); - if( control ) - { - contentSize.height = control.GetHeightForWidth( contentSize.width ); - } - else - { - contentSize.height = RelayoutHelper::GetHeightForWidth( mContent, contentSize.width ); - } - - mContent.SetSize( contentSize ); - Relayout( mContent, contentSize, container ); - - mContent.SetParentOrigin(ParentOrigin::TOP_CENTER); - mContent.SetAnchorPoint(AnchorPoint::TOP_CENTER); - - mContent.SetPosition( positionOffset ); - - positionOffset.y += contentSize.height + mPopupStyle->margin; - } - - // Relayout Button Area - if( mBottomBg ) - { - mBottomBg.SetSize( popupSize.width, mPopupStyle->bottomSize.height ); - - mBottomBg.SetParentOrigin(ParentOrigin::TOP_CENTER); - mBottomBg.SetAnchorPoint(AnchorPoint::TOP_CENTER); - - mBottomBg.SetPosition( positionOffset ); - } + // Hide the background image + mBackgroundImage.SetVisible( !( mButtons.empty() && mPopupLayout.GetChildCount() == 0 ) ); // Relayout All buttons if ( !mButtons.empty() ) { // All buttons should be the same size and fill the button area. The button spacing needs to be accounted for as well. - Vector2 buttonSize( ( ( popupSize.width - mPopupStyle->buttonSpacing * ( mButtons.size() - 1 ) ) / mButtons.size() ), + Vector2 buttonSize( ( ( size.width - mPopupStyle->buttonSpacing * ( mButtons.size() + 1 ) ) / mButtons.size() ), mPopupStyle->bottomSize.height - mPopupStyle->margin ); - Vector3 buttonPosition; + Vector3 buttonPosition( mPopupStyle->buttonSpacing, 0.0f, 0.0f ); for ( ActorIter iter = mButtons.begin(), endIter = mButtons.end(); iter != endIter; ++iter, buttonPosition.x += mPopupStyle->buttonSpacing + buttonSize.width ) { - iter->SetPosition( buttonPosition ); + Actor button = *iter; // If there is only one button, it needs to be laid out on center. if ( mButtons.size() == 1 ) { - iter->SetAnchorPoint( AnchorPoint::CENTER ); - iter->SetParentOrigin( ParentOrigin::CENTER ); + buttonPosition.x = 0.0f; + button.SetAnchorPoint( AnchorPoint::CENTER ); + button.SetParentOrigin( ParentOrigin::CENTER ); } else { - iter->SetAnchorPoint( AnchorPoint::CENTER_LEFT ); - iter->SetParentOrigin( ParentOrigin::CENTER_LEFT ); + button.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + button.SetParentOrigin( ParentOrigin::CENTER_LEFT ); } - Relayout( *iter, buttonSize, container ); + button.SetPosition( buttonPosition ); + + button.PropagateRelayoutFlags(); // Reset relayout flags for relayout + container.Add( button, buttonSize ); } } +} - if( mShowing && mBacking ) +void Popup::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) +{ + if( mPopupLayout ) { - Vector2 stageSize = Stage::GetCurrent().GetSize(); - float length = (stageSize.width > stageSize.height) ? stageSize.width : stageSize.height; - Vector3 targetBackingSize = Vector3( length, length, 1.0f ); - - mBacking.SetSize( targetBackingSize ); + if( policy == ResizePolicy::FIT_TO_CHILDREN ) + { + mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, dimension ); + if( dimension & Dimension::HEIGHT ) + { + mPopupLayout.SetFitHeight( 1 ); + } + } + else + { + mPopupLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, dimension ); + // Make the content cell fill the whole of the available space + if( dimension & Dimension::HEIGHT ) + { + mPopupLayout.SetRelativeHeight( 1, 1.0f ); + } + } } } @@ -826,29 +723,44 @@ bool Popup::OnKeyEvent(const KeyEvent& event) Vector3 Popup::GetNaturalSize() { - Vector3 naturalSize; + float margin = 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ); + const float maxWidth = Stage::GetCurrent().GetSize().width - margin; - if ( mTitle ) - { - naturalSize += mTitle.GetImplementation().GetNaturalSize(); - naturalSize.height += mPopupStyle->margin; - } + Vector3 naturalSize( 0.0f, 0.0f, 0.0f ); - if( mContent ) + if ( mTitle ) { - Vector3 contentSize; + Vector3 titleNaturalSize = mTitle.GetImplementation().GetNaturalSize(); + // Buffer to avoid errors. The width of the popup could potentially be the width of the title text. + // It was observed in this case that text wrapping was then inconsistent when seen on device + const float titleBuffer = 0.5f; + titleNaturalSize.width += titleBuffer; - Toolkit::Control control = Toolkit::Control::DownCast( mContent ); - if( control ) + // As TextLabel GetNaturalSize does not take wrapping into account, limit the width + // to that of the stage + if( titleNaturalSize.width >= maxWidth) { - contentSize = control.GetImplementation().GetNaturalSize(); + naturalSize.width = maxWidth; + naturalSize.height = mTitle.GetImplementation().GetHeightForWidth( naturalSize.width ); } else { - contentSize = RelayoutHelper::GetNaturalSize( mContent ); + naturalSize += titleNaturalSize; } + naturalSize.height += mPopupStyle->margin; + } + + if( mContent ) + { + Vector3 contentSize = mContent.GetNaturalSize(); + // Choose the biggest width naturalSize.width = std::max( naturalSize.width, contentSize.width ); + if( naturalSize.width > maxWidth ) + { + naturalSize.width = maxWidth; + contentSize.height = mContent.GetHeightForWidth( maxWidth ); + } naturalSize.height += contentSize.height + mPopupStyle->margin; } @@ -858,7 +770,6 @@ Vector3 Popup::GetNaturalSize() } // Add the margins - float margin( 2.0f * ( POPUP_OUT_MARGIN_WIDTH + mPopupStyle->margin ) ); naturalSize.width += margin; naturalSize.height += margin; @@ -878,19 +789,7 @@ float Popup::GetHeightForWidth( float width ) if( mContent ) { - float contentHeight; - - Toolkit::Control control = Toolkit::Control::DownCast( mContent ); - if( control ) - { - contentHeight = control.GetImplementation().GetHeightForWidth( popupWidth ); - } - else - { - contentHeight = RelayoutHelper::GetHeightForWidth( mContent, popupWidth ); - } - - height += contentHeight + mPopupStyle->margin; + height += mContent.GetHeightForWidth( popupWidth ) + mPopupStyle->margin; } if( !mButtons.empty() ) @@ -910,7 +809,7 @@ float Popup::GetWidthForHeight( float height ) return GetNaturalSize().width; } -Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::KeyboardFocusNavigationDirection direction, bool loopEnabled) +Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled) { Actor nextFocusableActor( currentFocusedActor ); @@ -953,7 +852,7 @@ Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::K { switch ( direction ) { - case Control::Left: + case Toolkit::Control::Left: { if ( iter == focusableActors.begin() ) { @@ -965,7 +864,7 @@ Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::K } break; } - case Control::Right: + case Toolkit::Control::Right: { if ( iter == focusableActors.end() - 1 ) { @@ -978,7 +877,7 @@ Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::K break; } - case Control::Up: + case Toolkit::Control::Up: { if ( *iter == mContent ) { @@ -1005,7 +904,7 @@ Actor Popup::GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::K break; } - case Control::Down: + case Toolkit::Control::Down: { if ( mContent && mContent.IsKeyboardFocusable() ) {