2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "shared/view.h"
19 #include <dali/dali.h>
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali-toolkit/devel-api/controls/popup/popup.h>
25 using Dali::Toolkit::TextLabel;
36 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg";
37 const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";
39 const char* const TOOLBAR_TITLE = "Popup";
41 const char* CONTEXT_DISABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-carousel.png";
42 const char* CONTEXT_ENABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-spiral.png";
43 const char* ANIMATION_FADE_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-off.png";
44 const char* ANIMATION_ZOOM_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-on.png";
46 const char* const POPUP_BUTTON_TITLE_ID = "POPUP_BUTTON_TITLE";
47 const char* const POPUP_BUTTON_BUTTONS_1_ID = "POPUP_BUTTON_BUTTONS_1";
48 const char* const POPUP_BUTTON_BUTTONS_2_ID = "POPUP_BUTTON_BUTTONS_2";
49 const char* const POPUP_BUTTON_TOAST_ID = "POPUP_BUTTON_TOAST";
50 const char* const POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_CONTENT_BUTTONS";
51 const char* const POPUP_BUTTON_CONTENT_TEXT_ID = "POPUP_BUTTON_CONTENT_TEXT";
52 const char* const POPUP_BUTTON_CONTENT_IMAGE_ID = "POPUP_BUTTON_CONTENT_IMAGE";
53 const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_ID = "POPUP_BUTTON_TITLE_CONTENT_TEXT";
54 const char* const POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS";
55 const char* const POPUP_BUTTON_FIXED_SIZE_ID = "POPUP_BUTTON_FIXED_SIZE_ID";
56 const char* const POPUP_BUTTON_COMPLEX_ID = "POPUP_BUTTON_COMPLEX";
57 const char* const POPUP_BUTTON_CUSTOM_STYLE = "POPUP_BUTTON_CUSTOM_STYLE";
59 // Names to give Popup PushButton controls.
60 const char* const POPUP_CONTROL_OK_NAME = "controlOk";
61 const char* const POPUP_CONTROL_CANCEL_NAME = "controlCancel";
63 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.";
64 const char* const IMAGE1 = DEMO_IMAGE_DIR "gallery-medium-5.jpg";
65 const char* const IMAGE2 = DEMO_IMAGE_DIR "background-magnifier.jpg";
67 // Control area image.
68 const char* DEFAULT_CONTROL_AREA_IMAGE_PATH = DEMO_IMAGE_DIR "popup_button_background.9.png"; ///< Control area image for the popup.
70 const ButtonItem POPUP_BUTTON_ITEMS[] = {
71 { POPUP_BUTTON_COMPLEX_ID, "Complex" },
72 { POPUP_BUTTON_TOAST_ID, "Toast Popup" },
73 { POPUP_BUTTON_TITLE_ID, "Title" },
74 { POPUP_BUTTON_BUTTONS_1_ID, "1 Button" },
75 { POPUP_BUTTON_BUTTONS_2_ID, "2 Buttons" },
76 { POPUP_BUTTON_FIXED_SIZE_ID, "Fixed Size" },
77 { POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID, "Title + Content + Buttons" },
78 { POPUP_BUTTON_CONTENT_TEXT_ID, "Content Text" },
79 { POPUP_BUTTON_CONTENT_IMAGE_ID, "Content Image" },
80 { POPUP_BUTTON_TITLE_CONTENT_TEXT_ID, "Title + Content" },
81 { POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID, "Title + Large Content + Buttons" },
82 { POPUP_BUTTON_CUSTOM_STYLE, "Custom Styled Popup" }
85 const int POPUP_BUTTON_ITEMS_COUNT = sizeof( POPUP_BUTTON_ITEMS ) / sizeof( POPUP_BUTTON_ITEMS[0] );
87 const char * const CUSTOM_POPUP_STYLE_NAME = "CustomPopupStyle"; ///< Custom popup style name
88 } // anonymous namespace
92 * This example shows the usage of the Popup class.
94 class PopupExample: public ConnectionTracker, public Toolkit::ItemFactory
98 PopupExample( Application& application )
99 : mApplication( application ),
100 mContextual( false ),
101 mAnimationFade( true )
103 // Connect to the Application's Init signal
104 mApplication.InitSignal().Connect( this, &PopupExample::Create );
109 // Nothing to do here
112 void Create( Application& application )
114 // The Init signal is received once (only) during the Application lifetime
115 Stage stage = Stage::GetCurrent();
117 // Respond to key events if not handled
118 stage.KeyEventSignal().Connect( this, &PopupExample::OnKeyEvent );
120 // Creates a default view with a default tool bar.
121 // The view is added to the stage.
122 mContentLayer = DemoHelper::CreateView( application,
129 mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" );
130 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE );
132 // Add title to the tool bar.
133 const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding );
134 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
136 // Create animation button.
137 mAnimationButton = Toolkit::PushButton::New();
138 mAnimationButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, ANIMATION_FADE_ICON_IMAGE );
139 mAnimationButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, ANIMATION_ZOOM_ICON_IMAGE );
140 mAnimationButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true );
141 mAnimationButton.ClickedSignal().Connect( this, &PopupExample::OnAnimationClicked );
142 mToolBar.AddControl( mAnimationButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
144 // Create context button.
145 mContextButton = Toolkit::PushButton::New();
146 mContextButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, CONTEXT_DISABLED_ICON_IMAGE );
147 mContextButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, CONTEXT_ENABLED_ICON_IMAGE );
148 mContextButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true );
149 mContextButton.ClickedSignal().Connect( this, &PopupExample::OnContextClicked );
150 mToolBar.AddControl( mContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
152 // Add title to the tool bar.
153 mItemView = Toolkit::ItemView::New( *this );
154 mItemView.SetParentOrigin( ParentOrigin::CENTER );
155 mItemView.SetAnchorPoint( AnchorPoint::CENTER );
156 mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
158 // Use a grid layout for tests
159 Vector2 stageSize = stage.GetSize();
160 Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
162 gridLayout->GetItemSize( 0, Vector3( stageSize ), itemSize );
163 itemSize.height = stageSize.y / 10;
164 gridLayout->SetItemSize( itemSize );
165 mItemView.AddLayout( *gridLayout );
167 mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
169 mContentLayer.Add( mItemView );
172 bool OnContextClicked( Toolkit::Button button )
174 mContextual = button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>();
178 bool OnAnimationClicked( Toolkit::Button button )
180 mAnimationFade = ! ( button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>() );
185 * This function is designed as a shortcut to convert any resize policies set for a popup to
186 * ones that will work for contextual mode (for demo purposes).
187 * Note that in a real-use case example the policies would be set to something appropriate
188 * manually, but in the case of this demo, the popup is parented from the popup-opening buttons
189 * and (incorrectly) have their policies as "SIZE_RELATIVE_TO_PARENT". This would create a tiny
190 * popup that would not be able to contain it's contents, so to illustrate contextual behaviour
191 * this function converts the old policies and size to new ones that would give the popup the
192 * same visual appearance.
193 * @param[in] popup The popup whose policies should be modified.
195 void SetupContextualResizePolicy( Toolkit::Popup& popup )
197 Vector2 stageSize = Stage::GetCurrent().GetSize();
198 // Some defaults when creating a new fixed size.
199 // This is NOT a Vector2 so we can modify each dimension in a for-loop.
200 float newSize[ Dimension::DIMENSION_COUNT ] = { stageSize.x * 0.75f, stageSize.y * 0.75f };
201 bool modifySize = false;
203 // Loop through each of two dimensions to process them.
204 for( unsigned int dimension = 0; dimension < 2; ++dimension )
206 float stageDimensionSize, sizeModeFactor;
207 Dimension::Type policyDimension = dimension == 0 ? Dimension::WIDTH : Dimension::HEIGHT;
209 // Setup information related to the current dimension we are processing.
210 if( policyDimension == Dimension::WIDTH )
212 stageDimensionSize = stageSize.x;
213 sizeModeFactor = popup.GetSizeModeFactor().x;
217 stageDimensionSize = stageSize.y;
218 sizeModeFactor = popup.GetSizeModeFactor().y;
221 bool modifyPolicy = false;
222 ResizePolicy::Type policy = popup.GetResizePolicy( policyDimension );
223 ResizePolicy::Type newPolicy( policy );
225 // Switch on each policy type to determine the new behaviour.
228 case ResizePolicy::FIXED:
229 case ResizePolicy::USE_ASSIGNED_SIZE:
234 case ResizePolicy::USE_NATURAL_SIZE:
235 case ResizePolicy::FIT_TO_CHILDREN:
236 case ResizePolicy::DIMENSION_DEPENDENCY:
238 // Set size to 0 so the policy determines size.
239 // If a non-zero size is set, policy is converted to fixed.
240 newSize[ dimension ] = 0.0f;
245 // The following cases emulate the three size-mode related resize policies.
246 case ResizePolicy::FILL_TO_PARENT:
248 newPolicy = ResizePolicy::FIXED;
249 newSize[ dimension ] = stageDimensionSize;
254 case ResizePolicy::SIZE_RELATIVE_TO_PARENT:
256 newPolicy = ResizePolicy::FIXED;
257 newSize[ dimension ] = stageDimensionSize * sizeModeFactor;
262 case ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT:
264 newPolicy = ResizePolicy::FIXED;
265 newSize[ dimension ] = stageDimensionSize + sizeModeFactor;
273 // Set the new policy for this dimension, if it has been modified.
274 popup.SetResizePolicy( newPolicy, policyDimension );
281 // The size is set once at the end.
282 popup.SetSize( Vector2( newSize[ 0 ], newSize[ 1 ] ) );
286 void SetupPopup( Toolkit::Popup popup, Actor parent )
290 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "FADE" );
294 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "ZOOM" );
299 popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, "BELOW" );
301 // Modify the preset demo resize policies (and size) to contextual ones.
302 SetupContextualResizePolicy( popup );
308 Stage::GetCurrent().Add( popup );
311 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
318 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
331 Toolkit::Popup CreatePopup()
333 Stage stage = Stage::GetCurrent();
334 const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
336 Toolkit::Popup popup = Toolkit::Popup::New();
337 popup.SetName( "popup" );
338 popup.SetParentOrigin( ParentOrigin::CENTER );
339 popup.SetAnchorPoint( AnchorPoint::CENTER );
340 popup.SetSize( POPUP_WIDTH_DP, 0.0f );
341 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
343 popup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
344 popup.HiddenSignal().Connect( this, &PopupExample::PopupHidden );
349 Toolkit::Popup CreateConfirmationPopup( int numberOfButtons )
351 Toolkit::Popup confirmationPopup = Toolkit::Popup::New();
352 confirmationPopup.SetName( "MAIN-POPUP-SELF" );
354 if( numberOfButtons > 0 )
356 // Start with a control area image.
357 Toolkit::ImageView footer = Toolkit::ImageView::New( DEFAULT_CONTROL_AREA_IMAGE_PATH );
358 footer.SetName( "controlAreaImage" );
359 // Set up the container's layout.
360 footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
361 footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
362 footer.SetSize( 0.0f, 130.0f );
363 footer.SetAnchorPoint( AnchorPoint::CENTER );
364 footer.SetParentOrigin( ParentOrigin::CENTER );
366 Actor okButton = CreateOKButton();
367 okButton.SetParentOrigin( ParentOrigin::CENTER );
368 okButton.SetAnchorPoint( AnchorPoint::CENTER );
369 okButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
370 okButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0 ) );
372 if( numberOfButtons > 1 )
374 Toolkit::TableView controlLayout = Toolkit::TableView::New( 1, 2 );
375 controlLayout.SetParentOrigin( ParentOrigin::CENTER );
376 controlLayout.SetAnchorPoint( AnchorPoint::CENTER );
377 controlLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
379 Actor cancelButton = CreateCancelButton();
380 cancelButton.SetParentOrigin( ParentOrigin::CENTER );
381 cancelButton.SetAnchorPoint( AnchorPoint::CENTER );
382 cancelButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
383 cancelButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0 ) );
385 controlLayout.SetCellPadding( Size( 10.0f, 10.0f ) );
387 controlLayout.SetRelativeWidth( 0, 0.5f );
388 controlLayout.SetRelativeWidth( 1, 0.5f );
390 controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
391 controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
392 controlLayout.AddChild( okButton, Toolkit::TableView::CellPosition( 0, 0 ) );
393 controlLayout.AddChild( cancelButton, Toolkit::TableView::CellPosition( 0, 1 ) );
395 footer.Add( controlLayout );
399 footer.Add( okButton );
402 confirmationPopup.SetFooter( footer );
405 confirmationPopup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
407 return confirmationPopup;
410 Actor CreateTitle( std::string title )
412 Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( title );
413 titleActor.SetName( "titleActor" );
414 titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
415 titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
416 titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
421 Toolkit::PushButton CreateOKButton()
423 Toolkit::PushButton okayButton = Toolkit::PushButton::New();
424 okayButton.SetName( POPUP_CONTROL_OK_NAME );
425 okayButton.SetProperty( Toolkit::Button::Property::LABEL, "OK!" );
427 okayButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
432 Toolkit::PushButton CreateCancelButton()
434 Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
435 cancelButton.SetName( POPUP_CONTROL_CANCEL_NAME );
436 cancelButton.SetProperty( Toolkit::Button::Property::LABEL, "Cancel" );
438 cancelButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
443 bool OnPopupButtonClicked( Toolkit::Button button )
445 // Handle Popup pushbuttons being clicked.
450 bool OnButtonClicked( Toolkit::Button button )
452 // Handle menu items that create popups.
453 if( button.GetName() == POPUP_BUTTON_TITLE_ID )
455 mPopup = CreatePopup();
456 mPopup.SetTitle( CreateTitle( "Popup!" ) );
458 SetupPopup( mPopup, button );
460 else if( button.GetName() == POPUP_BUTTON_BUTTONS_1_ID )
462 mPopup = CreateConfirmationPopup( 1 );
463 mPopup.SetTitle( CreateTitle( "Title" ) );
465 SetupPopup( mPopup, button );
467 else if( button.GetName() == POPUP_BUTTON_BUTTONS_2_ID )
469 mPopup = CreateConfirmationPopup( 2 );
470 mPopup.SetTitle( CreateTitle( "Title" ) );
472 SetupPopup( mPopup, button );
474 else if( button.GetName() == POPUP_BUTTON_TOAST_ID )
476 // Create a toast popup via the type registry (as it is a named-type).
477 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "PopupToast" );
480 BaseHandle baseHandle = typeInfo.CreateInstance();
483 mPopup = Toolkit::Popup::DownCast( baseHandle );
484 mPopup.SetTitle( CreateTitle( "This is a Toast Popup.\nIt will auto-hide itself" ) );
486 Stage::GetCurrent().Add( mPopup );
487 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
491 else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID )
493 mPopup = CreateConfirmationPopup( 2 );
494 mPopup.SetTitle( CreateTitle( "Erase image" ) );
496 Toolkit::TextLabel text = Toolkit::TextLabel::New( "This will erase the image permanently. Are you sure?" );
497 text.SetName( "POPUP_CONTENT_TEXT" );
498 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
499 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
500 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
501 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
502 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
503 mPopup.SetContent( text );
505 SetupPopup( mPopup, button );
507 else if( button.GetName() == POPUP_BUTTON_CONTENT_TEXT_ID )
509 mPopup = CreatePopup();
511 TextLabel text = TextLabel::New( CONTENT_TEXT );
512 text.SetName( "POPUP_CONTENT_TEXT" );
513 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
514 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
515 text.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
516 text.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
517 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
518 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
519 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
523 SetupPopup( mPopup, button );
525 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_ID )
527 mPopup = CreatePopup();
528 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE2 );
529 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
530 image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
531 image.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
535 SetupPopup( mPopup, button );
537 else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID )
539 mPopup = CreatePopup();
540 mPopup.SetTitle( CreateTitle( "Popup!" ) );
542 Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
543 text.SetName( "POPUP_CONTENT_TEXT" );
544 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
545 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
546 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
547 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
548 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
552 SetupPopup( mPopup, button );
554 else if( button.GetName() == POPUP_BUTTON_FIXED_SIZE_ID )
556 mPopup = CreatePopup();
557 mPopup.SetTitle( CreateTitle( "Popup!" ) );
559 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed size popup" );
560 text.SetName( "POPUP_CONTENT_TEXT" );
561 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
562 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
563 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
567 // Fix the popup's size.
568 mPopup.SetSize( 240.0f, 400.0f );
569 mPopup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
571 SetupPopup( mPopup, button );
573 else if( button.GetName() == POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID )
575 mPopup = CreateConfirmationPopup( 2 );
576 mPopup.SetTitle( CreateTitle( "Popup!" ) );
578 Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
579 text.SetName( "POPUP_CONTENT_TEXT" );
580 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
581 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
582 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
583 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
584 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
588 SetupPopup( mPopup, button );
590 else if( button.GetName() == POPUP_BUTTON_COMPLEX_ID )
592 mPopup = CreateConfirmationPopup( 2 );
593 mPopup.SetTitle( CreateTitle( "Warning" ) );
596 Toolkit::TableView content = Toolkit::TableView::New( 2, 2 );
597 content.SetName( "COMPLEX_TABLEVIEW" );
598 content.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
599 content.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
600 content.SetFitHeight( 0 );
601 content.SetFitHeight( 1 );
602 content.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 0.0f ) );
606 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Do you really want to quit?" );
607 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
608 text.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
609 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
610 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
612 content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) );
617 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE1 );
618 image.SetName( "COMPLEX_IMAGE" );
619 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
620 image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
621 image.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 0.0f ) );
622 content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) );
627 Toolkit::TableView root = Toolkit::TableView::New( 1, 2 );
628 root.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
629 root.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
630 root.SetFitHeight( 0 );
631 root.SetFitWidth( 0 );
632 root.SetPadding( Padding( 0.0f, 0.0f, 0.0f, 20.0f ) );
634 Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();
635 checkBox.SetSize( 48, 48 );
636 root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) );
638 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Don't show again" );
639 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
640 Actor textActor = text;
641 textActor.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 10.0f ) );
643 root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) );
645 content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0 ) );
648 mPopup.SetContent( content );
650 SetupPopup( mPopup, button );
652 else if( button.GetName() == POPUP_BUTTON_CUSTOM_STYLE )
654 mPopup = CreateConfirmationPopup( 2 );
656 Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Styled Popup" );
657 titleActor.SetName( "titleActor" );
658 titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::RED );
659 titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
660 titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
661 mPopup.SetTitle( titleActor );
663 SetupPopup( mPopup, button );
665 mPopup.SetStyleName( CUSTOM_POPUP_STYLE_NAME );
671 void OnKeyEvent( const KeyEvent& event )
673 if( event.state == KeyEvent::Down )
675 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
677 // Exit application when click back or escape.
683 public: // From ItemFactory
686 * @brief Return the number of items to display in the item view
688 * @return Return the number of items to display
690 virtual unsigned int GetNumberOfItems()
692 return POPUP_BUTTON_ITEMS_COUNT;
696 * @brief Create a new item to populate the item view with
698 * @param[in] itemId The index of the item to create
699 * @return Return the created actor for the given ID
701 virtual Actor NewItem(unsigned int itemId)
703 Toolkit::PushButton popupButton = Toolkit::PushButton::New();
704 popupButton.SetName( POPUP_BUTTON_ITEMS[ itemId ].name );
705 popupButton.SetProperty( Toolkit::Button::Property::LABEL, POPUP_BUTTON_ITEMS[ itemId ].text );
706 popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
708 popupButton.ClickedSignal().Connect( this, &PopupExample::OnButtonClicked );
716 Application& mApplication;
717 Toolkit::Control mView; ///< The View instance.
718 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
719 Toolkit::PushButton mContextButton; ///< For toggling contextual mode.
720 Toolkit::PushButton mAnimationButton; ///< For toggling the fade animation.
721 Layer mContentLayer; ///< Content layer
723 Toolkit::TextLabel mTitleActor; ///< Title text
725 bool mContextual; ///< True if currently using the contextual popup mode.
726 bool mAnimationFade; ///< True if currently using the fade animation.
728 Toolkit::Popup mPopup; ///< The current example popup.
730 Toolkit::ItemView mItemView; ///< ItemView to hold test images
734 int DALI_EXPORT_API main( int argc, char **argv )
736 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
737 PopupExample test( application );
738 application.MainLoop();