2 * Copyright (c) 2017 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/buttons/button-devel.h>
22 #include <dali-toolkit/devel-api/controls/popup/popup.h>
23 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
27 using Dali::Toolkit::TextLabel;
38 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg";
39 const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";
41 const char* const TOOLBAR_TITLE = "Popup";
43 const char* CONTEXT_DISABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-carousel.png";
44 const char* CONTEXT_ENABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-spiral.png";
45 const char* ANIMATION_FADE_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-off.png";
46 const char* ANIMATION_ZOOM_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-on.png";
48 const char* const POPUP_BUTTON_TITLE_ID = "POPUP_BUTTON_TITLE";
49 const char* const POPUP_BUTTON_BUTTONS_1_ID = "POPUP_BUTTON_BUTTONS_1";
50 const char* const POPUP_BUTTON_BUTTONS_2_ID = "POPUP_BUTTON_BUTTONS_2";
51 const char* const POPUP_BUTTON_TOAST_ID = "POPUP_BUTTON_TOAST";
52 const char* const POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_CONTENT_BUTTONS";
53 const char* const POPUP_BUTTON_CONTENT_TEXT_ID = "POPUP_BUTTON_CONTENT_TEXT";
54 const char* const POPUP_BUTTON_CONTENT_IMAGE_ID = "POPUP_BUTTON_CONTENT_IMAGE";
55 const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_ID = "POPUP_BUTTON_TITLE_CONTENT_TEXT";
56 const char* const POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS";
57 const char* const POPUP_BUTTON_FIXED_SIZE_ID = "POPUP_BUTTON_FIXED_SIZE_ID";
58 const char* const POPUP_BUTTON_COMPLEX_ID = "POPUP_BUTTON_COMPLEX";
59 const char* const POPUP_BUTTON_CUSTOM_STYLE = "POPUP_BUTTON_CUSTOM_STYLE";
61 // Names to give Popup PushButton controls.
62 const char* const POPUP_CONTROL_OK_NAME = "controlOk";
63 const char* const POPUP_CONTROL_CANCEL_NAME = "controlCancel";
65 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.";
66 const char* const IMAGE1 = DEMO_IMAGE_DIR "gallery-medium-5.jpg";
67 const char* const IMAGE2 = DEMO_IMAGE_DIR "background-magnifier.jpg";
69 // Control area image.
70 const char* DEFAULT_CONTROL_AREA_IMAGE_PATH = DEMO_IMAGE_DIR "popup_button_background.9.png"; ///< Control area image for the popup.
72 const ButtonItem POPUP_BUTTON_ITEMS[] = {
73 { POPUP_BUTTON_COMPLEX_ID, "Complex" },
74 { POPUP_BUTTON_TOAST_ID, "Toast Popup" },
75 { POPUP_BUTTON_TITLE_ID, "Title" },
76 { POPUP_BUTTON_BUTTONS_1_ID, "1 Button" },
77 { POPUP_BUTTON_BUTTONS_2_ID, "2 Buttons" },
78 { POPUP_BUTTON_FIXED_SIZE_ID, "Fixed Size" },
79 { POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID, "Title + Content + Buttons" },
80 { POPUP_BUTTON_CONTENT_TEXT_ID, "Content Text" },
81 { POPUP_BUTTON_CONTENT_IMAGE_ID, "Content Image" },
82 { POPUP_BUTTON_TITLE_CONTENT_TEXT_ID, "Title + Content" },
83 { POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID, "Title + Large Content + Buttons" },
84 { POPUP_BUTTON_CUSTOM_STYLE, "Custom Styled Popup" }
87 const int POPUP_BUTTON_ITEMS_COUNT = sizeof( POPUP_BUTTON_ITEMS ) / sizeof( POPUP_BUTTON_ITEMS[0] );
89 const char * const CUSTOM_POPUP_STYLE_NAME = "CustomPopupStyle"; ///< Custom popup style name
90 } // anonymous namespace
94 * This example shows the usage of the Popup class.
96 class PopupExample: public ConnectionTracker, public Toolkit::ItemFactory
100 PopupExample( Application& application )
101 : mApplication( application ),
102 mContextual( false ),
103 mAnimationFade( true )
105 // Connect to the Application's Init signal
106 mApplication.InitSignal().Connect( this, &PopupExample::Create );
111 // Nothing to do here
114 void Create( Application& application )
116 // The Init signal is received once (only) during the Application lifetime
117 Stage stage = Stage::GetCurrent();
119 // Respond to key events if not handled
120 Toolkit::KeyInputFocusManager keyInputFocusManager = Toolkit::KeyInputFocusManager::Get();
121 if( keyInputFocusManager )
123 keyInputFocusManager.UnhandledKeyEventSignal().Connect( this, &PopupExample::OnKeyEvent );
126 // Creates a default view with a default tool bar.
127 // The view is added to the stage.
128 mContentLayer = DemoHelper::CreateView( application,
135 mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" );
136 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE );
138 // Add title to the tool bar.
139 const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding );
140 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
142 // Create animation button.
143 mAnimationButton = Toolkit::PushButton::New();
144 mAnimationButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, ANIMATION_FADE_ICON_IMAGE );
145 mAnimationButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, ANIMATION_ZOOM_ICON_IMAGE );
146 mAnimationButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true );
147 mAnimationButton.ClickedSignal().Connect( this, &PopupExample::OnAnimationClicked );
148 mToolBar.AddControl( mAnimationButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
150 // Create context button.
151 mContextButton = Toolkit::PushButton::New();
152 mContextButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, CONTEXT_DISABLED_ICON_IMAGE );
153 mContextButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, CONTEXT_ENABLED_ICON_IMAGE );
154 mContextButton.SetProperty( Toolkit::Button::Property::TOGGLABLE, true );
155 mContextButton.ClickedSignal().Connect( this, &PopupExample::OnContextClicked );
156 mToolBar.AddControl( mContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
158 // Add title to the tool bar.
159 mItemView = Toolkit::ItemView::New( *this );
160 mItemView.SetParentOrigin( ParentOrigin::CENTER );
161 mItemView.SetAnchorPoint( AnchorPoint::CENTER );
162 mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
164 // Use a grid layout for tests
165 Vector2 stageSize = stage.GetSize();
166 Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
168 gridLayout->GetItemSize( 0, Vector3( stageSize ), itemSize );
169 itemSize.height = stageSize.y / 10;
170 gridLayout->SetItemSize( itemSize );
171 mItemView.AddLayout( *gridLayout );
173 mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
175 mContentLayer.Add( mItemView );
178 bool OnContextClicked( Toolkit::Button button )
180 mContextual = button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>();
184 bool OnAnimationClicked( Toolkit::Button button )
186 mAnimationFade = ! ( button.GetProperty( Toolkit::Button::Property::SELECTED ).Get<bool>() );
191 * This function is designed as a shortcut to convert any resize policies set for a popup to
192 * ones that will work for contextual mode (for demo purposes).
193 * Note that in a real-use case example the policies would be set to something appropriate
194 * manually, but in the case of this demo, the popup is parented from the popup-opening buttons
195 * and (incorrectly) have their policies as "SIZE_RELATIVE_TO_PARENT". This would create a tiny
196 * popup that would not be able to contain it's contents, so to illustrate contextual behaviour
197 * this function converts the old policies and size to new ones that would give the popup the
198 * same visual appearance.
199 * @param[in] popup The popup whose policies should be modified.
201 void SetupContextualResizePolicy( Toolkit::Popup& popup )
203 Vector2 stageSize = Stage::GetCurrent().GetSize();
204 // Some defaults when creating a new fixed size.
205 // This is NOT a Vector2 so we can modify each dimension in a for-loop.
206 float newSize[ Dimension::DIMENSION_COUNT ] = { stageSize.x * 0.75f, stageSize.y * 0.75f };
207 bool modifySize = false;
209 // Loop through each of two dimensions to process them.
210 for( unsigned int dimension = 0; dimension < 2; ++dimension )
212 float stageDimensionSize, sizeModeFactor;
213 Dimension::Type policyDimension = dimension == 0 ? Dimension::WIDTH : Dimension::HEIGHT;
215 // Setup information related to the current dimension we are processing.
216 if( policyDimension == Dimension::WIDTH )
218 stageDimensionSize = stageSize.x;
219 sizeModeFactor = popup.GetSizeModeFactor().x;
223 stageDimensionSize = stageSize.y;
224 sizeModeFactor = popup.GetSizeModeFactor().y;
227 bool modifyPolicy = false;
228 ResizePolicy::Type policy = popup.GetResizePolicy( policyDimension );
229 ResizePolicy::Type newPolicy( policy );
231 // Switch on each policy type to determine the new behaviour.
234 case ResizePolicy::FIXED:
235 case ResizePolicy::USE_ASSIGNED_SIZE:
240 case ResizePolicy::USE_NATURAL_SIZE:
241 case ResizePolicy::FIT_TO_CHILDREN:
242 case ResizePolicy::DIMENSION_DEPENDENCY:
244 // Set size to 0 so the policy determines size.
245 // If a non-zero size is set, policy is converted to fixed.
246 newSize[ dimension ] = 0.0f;
251 // The following cases emulate the three size-mode related resize policies.
252 case ResizePolicy::FILL_TO_PARENT:
254 newPolicy = ResizePolicy::FIXED;
255 newSize[ dimension ] = stageDimensionSize;
260 case ResizePolicy::SIZE_RELATIVE_TO_PARENT:
262 newPolicy = ResizePolicy::FIXED;
263 newSize[ dimension ] = stageDimensionSize * sizeModeFactor;
268 case ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT:
270 newPolicy = ResizePolicy::FIXED;
271 newSize[ dimension ] = stageDimensionSize + sizeModeFactor;
279 // Set the new policy for this dimension, if it has been modified.
280 popup.SetResizePolicy( newPolicy, policyDimension );
287 // The size is set once at the end.
288 popup.SetSize( Vector2( newSize[ 0 ], newSize[ 1 ] ) );
292 void SetupPopup( Toolkit::Popup popup, Actor parent )
296 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "FADE" );
300 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "ZOOM" );
305 popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, "BELOW" );
307 // Modify the preset demo resize policies (and size) to contextual ones.
308 SetupContextualResizePolicy( popup );
314 Stage::GetCurrent().Add( popup );
317 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
324 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
337 Toolkit::Popup CreatePopup()
339 Stage stage = Stage::GetCurrent();
340 const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
342 Toolkit::Popup popup = Toolkit::Popup::New();
343 popup.SetName( "popup" );
344 popup.SetParentOrigin( ParentOrigin::CENTER );
345 popup.SetAnchorPoint( AnchorPoint::CENTER );
346 popup.SetSize( POPUP_WIDTH_DP, 0.0f );
347 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
349 popup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
350 popup.HiddenSignal().Connect( this, &PopupExample::PopupHidden );
355 Toolkit::Popup CreateConfirmationPopup( int numberOfButtons )
357 Toolkit::Popup confirmationPopup = Toolkit::Popup::New();
358 confirmationPopup.SetName( "MAIN-POPUP-SELF" );
360 if( numberOfButtons > 0 )
362 // Start with a control area image.
363 Toolkit::ImageView footer = Toolkit::ImageView::New( DEFAULT_CONTROL_AREA_IMAGE_PATH );
364 footer.SetName( "controlAreaImage" );
365 // Set up the container's layout.
366 footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
367 footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
368 footer.SetSize( 0.0f, 130.0f );
369 footer.SetAnchorPoint( AnchorPoint::CENTER );
370 footer.SetParentOrigin( ParentOrigin::CENTER );
372 Actor okButton = CreateOKButton();
373 okButton.SetParentOrigin( ParentOrigin::CENTER );
374 okButton.SetAnchorPoint( AnchorPoint::CENTER );
375 okButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
376 okButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0 ) );
378 if( numberOfButtons > 1 )
380 Toolkit::TableView controlLayout = Toolkit::TableView::New( 1, 2 );
381 controlLayout.SetParentOrigin( ParentOrigin::CENTER );
382 controlLayout.SetAnchorPoint( AnchorPoint::CENTER );
383 controlLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
385 Actor cancelButton = CreateCancelButton();
386 cancelButton.SetParentOrigin( ParentOrigin::CENTER );
387 cancelButton.SetAnchorPoint( AnchorPoint::CENTER );
388 cancelButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
389 cancelButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0 ) );
391 controlLayout.SetCellPadding( Size( 10.0f, 10.0f ) );
393 controlLayout.SetRelativeWidth( 0, 0.5f );
394 controlLayout.SetRelativeWidth( 1, 0.5f );
396 controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
397 controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
398 controlLayout.AddChild( okButton, Toolkit::TableView::CellPosition( 0, 0 ) );
399 controlLayout.AddChild( cancelButton, Toolkit::TableView::CellPosition( 0, 1 ) );
401 footer.Add( controlLayout );
405 footer.Add( okButton );
408 confirmationPopup.SetFooter( footer );
411 confirmationPopup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
413 return confirmationPopup;
416 Actor CreateTitle( std::string title )
418 Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( title );
419 titleActor.SetName( "titleActor" );
420 titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
421 titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
422 titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
427 Toolkit::PushButton CreateOKButton()
429 Toolkit::PushButton okayButton = Toolkit::PushButton::New();
430 okayButton.SetName( POPUP_CONTROL_OK_NAME );
431 okayButton.SetProperty( Toolkit::Button::Property::LABEL, "OK!" );
433 okayButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
438 Toolkit::PushButton CreateCancelButton()
440 Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
441 cancelButton.SetName( POPUP_CONTROL_CANCEL_NAME );
442 cancelButton.SetProperty( Toolkit::Button::Property::LABEL, "Cancel" );
444 cancelButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
449 bool OnPopupButtonClicked( Toolkit::Button button )
451 // Handle Popup pushbuttons being clicked.
456 bool OnButtonClicked( Toolkit::Button button )
458 // Handle menu items that create popups.
459 if( button.GetName() == POPUP_BUTTON_TITLE_ID )
461 mPopup = CreatePopup();
462 mPopup.SetTitle( CreateTitle( "Popup!" ) );
464 SetupPopup( mPopup, button );
466 else if( button.GetName() == POPUP_BUTTON_BUTTONS_1_ID )
468 mPopup = CreateConfirmationPopup( 1 );
469 mPopup.SetTitle( CreateTitle( "Title" ) );
471 SetupPopup( mPopup, button );
473 else if( button.GetName() == POPUP_BUTTON_BUTTONS_2_ID )
475 mPopup = CreateConfirmationPopup( 2 );
476 mPopup.SetTitle( CreateTitle( "Title" ) );
478 SetupPopup( mPopup, button );
480 else if( button.GetName() == POPUP_BUTTON_TOAST_ID )
482 // Create a toast popup via the type registry (as it is a named-type).
483 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "PopupToast" );
486 BaseHandle baseHandle = typeInfo.CreateInstance();
489 mPopup = Toolkit::Popup::DownCast( baseHandle );
490 mPopup.SetTitle( CreateTitle( "This is a Toast Popup.\nIt will auto-hide itself" ) );
492 Stage::GetCurrent().Add( mPopup );
493 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
497 else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID )
499 mPopup = CreateConfirmationPopup( 2 );
500 mPopup.SetTitle( CreateTitle( "Erase image" ) );
502 Toolkit::TextLabel text = Toolkit::TextLabel::New( "This will erase the image permanently. Are you sure?" );
503 text.SetName( "POPUP_CONTENT_TEXT" );
504 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
505 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
506 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
507 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
508 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
509 mPopup.SetContent( text );
511 SetupPopup( mPopup, button );
513 else if( button.GetName() == POPUP_BUTTON_CONTENT_TEXT_ID )
515 mPopup = CreatePopup();
517 TextLabel text = TextLabel::New( CONTENT_TEXT );
518 text.SetName( "POPUP_CONTENT_TEXT" );
519 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
520 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
521 text.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
522 text.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
523 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
524 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
525 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
529 SetupPopup( mPopup, button );
531 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_ID )
533 mPopup = CreatePopup();
534 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE2 );
535 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
536 image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
537 image.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
541 SetupPopup( mPopup, button );
543 else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID )
545 mPopup = CreatePopup();
546 mPopup.SetTitle( CreateTitle( "Popup!" ) );
548 Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
549 text.SetName( "POPUP_CONTENT_TEXT" );
550 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
551 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
552 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
553 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
554 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
558 SetupPopup( mPopup, button );
560 else if( button.GetName() == POPUP_BUTTON_FIXED_SIZE_ID )
562 mPopup = CreatePopup();
563 mPopup.SetTitle( CreateTitle( "Popup!" ) );
565 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed size popup" );
566 text.SetName( "POPUP_CONTENT_TEXT" );
567 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
568 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
569 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
573 // Fix the popup's size.
574 mPopup.SetSize( 240.0f, 400.0f );
575 mPopup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
577 SetupPopup( mPopup, button );
579 else if( button.GetName() == POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID )
581 mPopup = CreateConfirmationPopup( 2 );
582 mPopup.SetTitle( CreateTitle( "Popup!" ) );
584 Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
585 text.SetName( "POPUP_CONTENT_TEXT" );
586 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
587 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
588 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
589 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
590 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
594 SetupPopup( mPopup, button );
596 else if( button.GetName() == POPUP_BUTTON_COMPLEX_ID )
598 mPopup = CreateConfirmationPopup( 2 );
599 mPopup.SetTitle( CreateTitle( "Warning" ) );
602 Toolkit::TableView content = Toolkit::TableView::New( 2, 2 );
603 content.SetName( "COMPLEX_TABLEVIEW" );
604 content.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
605 content.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
606 content.SetFitHeight( 0 );
607 content.SetFitHeight( 1 );
608 content.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 0.0f ) );
612 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Do you really want to quit?" );
613 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
614 text.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
615 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
616 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
618 content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) );
623 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE1 );
624 image.SetName( "COMPLEX_IMAGE" );
625 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
626 image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
627 image.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 0.0f ) );
628 content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) );
633 Toolkit::TableView root = Toolkit::TableView::New( 1, 2 );
634 root.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
635 root.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
636 root.SetFitHeight( 0 );
637 root.SetFitWidth( 0 );
638 root.SetPadding( Padding( 0.0f, 0.0f, 0.0f, 20.0f ) );
640 Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();
641 checkBox.SetSize( 48, 48 );
642 root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) );
644 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Don't show again" );
645 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
646 Actor textActor = text;
647 textActor.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 10.0f ) );
649 root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) );
651 content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0 ) );
654 mPopup.SetContent( content );
656 SetupPopup( mPopup, button );
658 else if( button.GetName() == POPUP_BUTTON_CUSTOM_STYLE )
660 mPopup = CreateConfirmationPopup( 2 );
662 Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Styled Popup" );
663 titleActor.SetName( "titleActor" );
664 titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::RED );
665 titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
666 titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
667 mPopup.SetTitle( titleActor );
669 SetupPopup( mPopup, button );
671 mPopup.SetStyleName( CUSTOM_POPUP_STYLE_NAME );
677 void OnKeyEvent( const KeyEvent& event )
679 if( event.state == KeyEvent::Down )
681 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
683 // Exit application when click back or escape.
689 public: // From ItemFactory
692 * @brief Return the number of items to display in the item view
694 * @return Return the number of items to display
696 virtual unsigned int GetNumberOfItems()
698 return POPUP_BUTTON_ITEMS_COUNT;
702 * @brief Create a new item to populate the item view with
704 * @param[in] itemId The index of the item to create
705 * @return Return the created actor for the given ID
707 virtual Actor NewItem(unsigned int itemId)
709 Toolkit::PushButton popupButton = Toolkit::PushButton::New();
710 popupButton.SetName( POPUP_BUTTON_ITEMS[ itemId ].name );
711 popupButton.SetProperty( Toolkit::Button::Property::LABEL, POPUP_BUTTON_ITEMS[ itemId ].text );
712 popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
714 popupButton.ClickedSignal().Connect( this, &PopupExample::OnButtonClicked );
722 Application& mApplication;
723 Toolkit::Control mView; ///< The View instance.
724 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
725 Toolkit::PushButton mContextButton; ///< For toggling contextual mode.
726 Toolkit::PushButton mAnimationButton; ///< For toggling the fade animation.
727 Layer mContentLayer; ///< Content layer
729 Toolkit::TextLabel mTitleActor; ///< Title text
731 bool mContextual; ///< True if currently using the contextual popup mode.
732 bool mAnimationFade; ///< True if currently using the fade animation.
734 Toolkit::Popup mPopup; ///< The current example popup.
736 Toolkit::ItemView mItemView; ///< ItemView to hold test images
740 void RunTest( Application& application )
742 PopupExample test( application );
744 application.MainLoop();
747 // Entry point for Linux & SLP applications
748 int DALI_EXPORT_API main( int argc, char **argv )
750 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
752 RunTest( application );