2 * Copyright (c) 2016 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>
22 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
26 using Dali::Toolkit::TextLabel;
37 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg";
38 const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";
40 const char* const TOOLBAR_TITLE = "Popup";
42 const char* CONTEXT_DISABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-carousel.png";
43 const char* CONTEXT_ENABLED_ICON_IMAGE = DEMO_IMAGE_DIR "icon-scroll-view-spiral.png";
44 const char* ANIMATION_FADE_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-off.png";
45 const char* ANIMATION_ZOOM_ICON_IMAGE = DEMO_IMAGE_DIR "icon-effects-on.png";
47 const char* const POPUP_BUTTON_TITLE_ID = "POPUP_BUTTON_TITLE";
48 const char* const POPUP_BUTTON_BUTTONS_1_ID = "POPUP_BUTTON_BUTTONS_1";
49 const char* const POPUP_BUTTON_BUTTONS_2_ID = "POPUP_BUTTON_BUTTONS_2";
50 const char* const POPUP_BUTTON_TOAST_ID = "POPUP_BUTTON_TOAST";
51 const char* const POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_CONTENT_BUTTONS";
52 const char* const POPUP_BUTTON_CONTENT_TEXT_ID = "POPUP_BUTTON_CONTENT_TEXT";
53 const char* const POPUP_BUTTON_CONTENT_IMAGE_ID = "POPUP_BUTTON_CONTENT_IMAGE";
54 const char* const POPUP_BUTTON_TITLE_CONTENT_TEXT_ID = "POPUP_BUTTON_TITLE_CONTENT_TEXT";
55 const char* const POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID = "POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS";
56 const char* const POPUP_BUTTON_FIXED_SIZE_ID = "POPUP_BUTTON_FIXED_SIZE_ID";
57 const char* const POPUP_BUTTON_COMPLEX_ID = "POPUP_BUTTON_COMPLEX";
58 const char* const POPUP_BUTTON_CUSTOM_STYLE = "POPUP_BUTTON_CUSTOM_STYLE";
60 // Names to give Popup PushButton controls.
61 const char* const POPUP_CONTROL_OK_NAME = "controlOk";
62 const char* const POPUP_CONTROL_CANCEL_NAME = "controlCancel";
64 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.";
65 const char* const IMAGE1 = DEMO_IMAGE_DIR "gallery-medium-5.jpg";
66 const char* const IMAGE2 = DEMO_IMAGE_DIR "background-magnifier.jpg";
68 // Control area image.
69 const char* DEFAULT_CONTROL_AREA_IMAGE_PATH = DEMO_IMAGE_DIR "popup_button_background.9.png"; ///< Control area image for the popup.
71 const ButtonItem POPUP_BUTTON_ITEMS[] = {
72 { POPUP_BUTTON_COMPLEX_ID, "Complex" },
73 { POPUP_BUTTON_TOAST_ID, "Toast Popup" },
74 { POPUP_BUTTON_TITLE_ID, "Title" },
75 { POPUP_BUTTON_BUTTONS_1_ID, "1 Button" },
76 { POPUP_BUTTON_BUTTONS_2_ID, "2 Buttons" },
77 { POPUP_BUTTON_FIXED_SIZE_ID, "Fixed Size" },
78 { POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID, "Title + Content + Buttons" },
79 { POPUP_BUTTON_CONTENT_TEXT_ID, "Content Text" },
80 { POPUP_BUTTON_CONTENT_IMAGE_ID, "Content Image" },
81 { POPUP_BUTTON_TITLE_CONTENT_TEXT_ID, "Title + Content" },
82 { POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID, "Title + Large Content + Buttons" },
83 { POPUP_BUTTON_CUSTOM_STYLE, "Custom Styled Popup" }
86 const int POPUP_BUTTON_ITEMS_COUNT = sizeof( POPUP_BUTTON_ITEMS ) / sizeof( POPUP_BUTTON_ITEMS[0] );
88 const char * const CUSTOM_POPUP_STYLE_NAME = "CustomPopupStyle"; ///< Custom popup style name
89 } // anonymous namespace
93 * This example shows the usage of the Popup class.
95 class PopupExample: public ConnectionTracker, public Toolkit::ItemFactory
99 PopupExample( Application& application )
100 : mApplication( application ),
101 mContextual( false ),
102 mAnimationFade( true )
104 // Connect to the Application's Init signal
105 mApplication.InitSignal().Connect( this, &PopupExample::Create );
110 // Nothing to do here
113 void Create( Application& application )
115 // The Init signal is received once (only) during the Application lifetime
116 Stage stage = Stage::GetCurrent();
118 // Respond to key events if not handled
119 Toolkit::KeyInputFocusManager keyInputFocusManager = Toolkit::KeyInputFocusManager::Get();
120 if( keyInputFocusManager )
122 keyInputFocusManager.UnhandledKeyEventSignal().Connect( this, &PopupExample::OnKeyEvent );
125 // Creates a default view with a default tool bar.
126 // The view is added to the stage.
127 mContentLayer = DemoHelper::CreateView( application,
134 mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" );
135 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE );
137 // Add title to the tool bar.
138 const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding );
139 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
141 // Create animation button.
142 mAnimationButton = Toolkit::PushButton::New();
143 mAnimationButton.SetUnselectedImage( ANIMATION_FADE_ICON_IMAGE );
144 mAnimationButton.SetSelectedImage( ANIMATION_ZOOM_ICON_IMAGE );
145 mAnimationButton.SetTogglableButton( true );
146 mAnimationButton.ClickedSignal().Connect( this, &PopupExample::OnAnimationClicked );
147 mToolBar.AddControl( mAnimationButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
149 // Create context button.
150 mContextButton = Toolkit::PushButton::New();
151 mContextButton.SetUnselectedImage( CONTEXT_DISABLED_ICON_IMAGE );
152 mContextButton.SetSelectedImage( CONTEXT_ENABLED_ICON_IMAGE );
153 mContextButton.SetTogglableButton( true );
154 mContextButton.ClickedSignal().Connect( this, &PopupExample::OnContextClicked );
155 mToolBar.AddControl( mContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
157 // Add title to the tool bar.
158 mItemView = Toolkit::ItemView::New( *this );
159 mItemView.SetParentOrigin( ParentOrigin::CENTER );
160 mItemView.SetAnchorPoint( AnchorPoint::CENTER );
161 mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
163 // Use a grid layout for tests
164 Vector2 stageSize = stage.GetSize();
165 Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
167 gridLayout->GetItemSize( 0, Vector3( stageSize ), itemSize );
168 itemSize.height = stageSize.y / 10;
169 gridLayout->SetItemSize( itemSize );
170 mItemView.AddLayout( *gridLayout );
172 mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
174 mContentLayer.Add( mItemView );
177 bool OnContextClicked( Toolkit::Button button )
179 mContextual = button.IsSelected();
183 bool OnAnimationClicked( Toolkit::Button button )
185 mAnimationFade = !button.IsSelected();
190 * This function is designed as a shortcut to convert any resize policies set for a popup to
191 * ones that will work for contextual mode (for demo purposes).
192 * Note that in a real-use case example the policies would be set to something appropriate
193 * manually, but in the case of this demo, the popup is parented from the popup-opening buttons
194 * and (incorrectly) have their policies as "SIZE_RELATIVE_TO_PARENT". This would create a tiny
195 * popup that would not be able to contain it's contents, so to illustrate contextual behaviour
196 * this function converts the old policies and size to new ones that would give the popup the
197 * same visual appearance.
198 * @param[in] popup The popup whose policies should be modified.
200 void SetupContextualResizePolicy( Toolkit::Popup& popup )
202 Vector2 stageSize = Stage::GetCurrent().GetSize();
203 // Some defaults when creating a new fixed size.
204 // This is NOT a Vector2 so we can modify each dimension in a for-loop.
205 float newSize[ Dimension::DIMENSION_COUNT ] = { stageSize.x * 0.75f, stageSize.y * 0.75f };
206 bool modifySize = false;
208 // Loop through each of two dimensions to process them.
209 for( unsigned int dimension = 0; dimension < 2; ++dimension )
211 float stageDimensionSize, sizeModeFactor;
212 Dimension::Type policyDimension = dimension == 0 ? Dimension::WIDTH : Dimension::HEIGHT;
214 // Setup information related to the current dimension we are processing.
215 if( policyDimension == Dimension::WIDTH )
217 stageDimensionSize = stageSize.x;
218 sizeModeFactor = popup.GetSizeModeFactor().x;
222 stageDimensionSize = stageSize.y;
223 sizeModeFactor = popup.GetSizeModeFactor().y;
226 bool modifyPolicy = false;
227 ResizePolicy::Type policy = popup.GetResizePolicy( policyDimension );
228 ResizePolicy::Type newPolicy( policy );
230 // Switch on each policy type to determine the new behaviour.
233 case ResizePolicy::FIXED:
234 case ResizePolicy::USE_ASSIGNED_SIZE:
239 case ResizePolicy::USE_NATURAL_SIZE:
240 case ResizePolicy::FIT_TO_CHILDREN:
241 case ResizePolicy::DIMENSION_DEPENDENCY:
243 // Set size to 0 so the policy determines size.
244 // If a non-zero size is set, policy is converted to fixed.
245 newSize[ dimension ] = 0.0f;
250 // The following cases emulate the three size-mode related resize policies.
251 case ResizePolicy::FILL_TO_PARENT:
253 newPolicy = ResizePolicy::FIXED;
254 newSize[ dimension ] = stageDimensionSize;
259 case ResizePolicy::SIZE_RELATIVE_TO_PARENT:
261 newPolicy = ResizePolicy::FIXED;
262 newSize[ dimension ] = stageDimensionSize * sizeModeFactor;
267 case ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT:
269 newPolicy = ResizePolicy::FIXED;
270 newSize[ dimension ] = stageDimensionSize + sizeModeFactor;
278 // Set the new policy for this dimension, if it has been modified.
279 popup.SetResizePolicy( newPolicy, policyDimension );
286 // The size is set once at the end.
287 popup.SetSize( Vector2( newSize[ 0 ], newSize[ 1 ] ) );
291 void SetupPopup( Toolkit::Popup popup, Actor parent )
295 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "FADE" );
299 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "ZOOM" );
304 popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, "BELOW" );
306 // Modify the preset demo resize policies (and size) to contextual ones.
307 SetupContextualResizePolicy( popup );
313 Stage::GetCurrent().Add( popup );
316 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
323 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
336 Toolkit::Popup CreatePopup()
338 Stage stage = Stage::GetCurrent();
339 const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
341 Toolkit::Popup popup = Toolkit::Popup::New();
342 popup.SetName( "popup" );
343 popup.SetParentOrigin( ParentOrigin::CENTER );
344 popup.SetAnchorPoint( AnchorPoint::CENTER );
345 popup.SetSize( POPUP_WIDTH_DP, 0.0f );
346 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
348 popup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
349 popup.HiddenSignal().Connect( this, &PopupExample::PopupHidden );
354 Toolkit::Popup CreateConfirmationPopup( int numberOfButtons )
356 Toolkit::Popup confirmationPopup = Toolkit::Popup::New();
357 confirmationPopup.SetName( "MAIN-POPUP-SELF" );
359 if( numberOfButtons > 0 )
361 // Start with a control area image.
362 Toolkit::ImageView footer = Toolkit::ImageView::New( DEFAULT_CONTROL_AREA_IMAGE_PATH );
363 footer.SetName( "controlAreaImage" );
364 // Set up the container's layout.
365 footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
366 footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
367 footer.SetSize( 0.0f, 130.0f );
368 footer.SetAnchorPoint( AnchorPoint::CENTER );
369 footer.SetParentOrigin( ParentOrigin::CENTER );
371 Actor okButton = CreateOKButton();
372 okButton.SetParentOrigin( ParentOrigin::CENTER );
373 okButton.SetAnchorPoint( AnchorPoint::CENTER );
374 okButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
375 okButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0 ) );
377 if( numberOfButtons > 1 )
379 Toolkit::TableView controlLayout = Toolkit::TableView::New( 1, 2 );
380 controlLayout.SetParentOrigin( ParentOrigin::CENTER );
381 controlLayout.SetAnchorPoint( AnchorPoint::CENTER );
382 controlLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
384 Actor cancelButton = CreateCancelButton();
385 cancelButton.SetParentOrigin( ParentOrigin::CENTER );
386 cancelButton.SetAnchorPoint( AnchorPoint::CENTER );
387 cancelButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
388 cancelButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0 ) );
390 controlLayout.SetCellPadding( Size( 10.0f, 10.0f ) );
392 controlLayout.SetRelativeWidth( 0, 0.5f );
393 controlLayout.SetRelativeWidth( 1, 0.5f );
395 controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
396 controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
397 controlLayout.AddChild( okButton, Toolkit::TableView::CellPosition( 0, 0 ) );
398 controlLayout.AddChild( cancelButton, Toolkit::TableView::CellPosition( 0, 1 ) );
400 footer.Add( controlLayout );
404 footer.Add( okButton );
407 confirmationPopup.SetFooter( footer );
410 confirmationPopup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
412 return confirmationPopup;
415 Actor CreateTitle( std::string title )
417 Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( title );
418 titleActor.SetName( "titleActor" );
419 titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
420 titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
421 titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
426 Toolkit::PushButton CreateOKButton()
428 Toolkit::PushButton okayButton = Toolkit::PushButton::New();
429 okayButton.SetName( POPUP_CONTROL_OK_NAME );
430 okayButton.SetLabelText( "OK!" );
432 okayButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
437 Toolkit::PushButton CreateCancelButton()
439 Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
440 cancelButton.SetName( POPUP_CONTROL_CANCEL_NAME );
441 cancelButton.SetLabelText( "Cancel" );
443 cancelButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
448 bool OnPopupButtonClicked( Toolkit::Button button )
450 // Handle Popup pushbuttons being clicked.
455 bool OnButtonClicked( Toolkit::Button button )
457 // Handle menu items that create popups.
458 if( button.GetName() == POPUP_BUTTON_TITLE_ID )
460 mPopup = CreatePopup();
461 mPopup.SetTitle( CreateTitle( "Popup!" ) );
463 SetupPopup( mPopup, button );
465 else if( button.GetName() == POPUP_BUTTON_BUTTONS_1_ID )
467 mPopup = CreateConfirmationPopup( 1 );
468 mPopup.SetTitle( CreateTitle( "Title" ) );
470 SetupPopup( mPopup, button );
472 else if( button.GetName() == POPUP_BUTTON_BUTTONS_2_ID )
474 mPopup = CreateConfirmationPopup( 2 );
475 mPopup.SetTitle( CreateTitle( "Title" ) );
477 SetupPopup( mPopup, button );
479 else if( button.GetName() == POPUP_BUTTON_TOAST_ID )
481 // Create a toast popup via the type registry (as it is a named-type).
482 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "PopupToast" );
485 BaseHandle baseHandle = typeInfo.CreateInstance();
488 mPopup = Toolkit::Popup::DownCast( baseHandle );
489 mPopup.SetTitle( CreateTitle( "This is a Toast Popup.\nIt will auto-hide itself" ) );
491 Stage::GetCurrent().Add( mPopup );
492 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
496 else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID )
498 mPopup = CreateConfirmationPopup( 2 );
499 mPopup.SetTitle( CreateTitle( "Erase image" ) );
501 Toolkit::TextLabel text = Toolkit::TextLabel::New( "This will erase the image permanently. Are you sure?" );
502 text.SetName( "POPUP_CONTENT_TEXT" );
503 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
504 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
505 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
506 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
507 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
508 mPopup.SetContent( text );
510 SetupPopup( mPopup, button );
512 else if( button.GetName() == POPUP_BUTTON_CONTENT_TEXT_ID )
514 mPopup = CreatePopup();
516 TextLabel text = TextLabel::New( CONTENT_TEXT );
517 text.SetName( "POPUP_CONTENT_TEXT" );
518 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
519 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
520 text.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
521 text.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
522 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
523 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
524 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
528 SetupPopup( mPopup, button );
530 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_ID )
532 mPopup = CreatePopup();
533 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE2 );
534 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
535 image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
536 image.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
540 SetupPopup( mPopup, button );
542 else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID )
544 mPopup = CreatePopup();
545 mPopup.SetTitle( CreateTitle( "Popup!" ) );
547 Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
548 text.SetName( "POPUP_CONTENT_TEXT" );
549 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
550 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
551 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
552 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
553 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
557 SetupPopup( mPopup, button );
559 else if( button.GetName() == POPUP_BUTTON_FIXED_SIZE_ID )
561 mPopup = CreatePopup();
562 mPopup.SetTitle( CreateTitle( "Popup!" ) );
564 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed size popup" );
565 text.SetName( "POPUP_CONTENT_TEXT" );
566 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
567 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
568 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
572 // Fix the popup's size.
573 mPopup.SetSize( 240.0f, 400.0f );
574 mPopup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
576 SetupPopup( mPopup, button );
578 else if( button.GetName() == POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID )
580 mPopup = CreateConfirmationPopup( 2 );
581 mPopup.SetTitle( CreateTitle( "Popup!" ) );
583 Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
584 text.SetName( "POPUP_CONTENT_TEXT" );
585 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
586 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
587 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
588 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
589 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
593 SetupPopup( mPopup, button );
595 else if( button.GetName() == POPUP_BUTTON_COMPLEX_ID )
597 mPopup = CreateConfirmationPopup( 2 );
598 mPopup.SetTitle( CreateTitle( "Warning" ) );
601 Toolkit::TableView content = Toolkit::TableView::New( 2, 2 );
602 content.SetName( "COMPLEX_TABLEVIEW" );
603 content.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
604 content.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
605 content.SetFitHeight( 0 );
606 content.SetFitHeight( 1 );
607 content.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 0.0f ) );
611 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Do you really want to quit?" );
612 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
613 text.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
614 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
615 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
617 content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) );
622 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE1 );
623 image.SetName( "COMPLEX_IMAGE" );
624 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
625 image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
626 image.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 0.0f ) );
627 content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) );
632 Toolkit::TableView root = Toolkit::TableView::New( 1, 2 );
633 root.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
634 root.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
635 root.SetFitHeight( 0 );
636 root.SetFitWidth( 0 );
637 root.SetPadding( Padding( 0.0f, 0.0f, 0.0f, 20.0f ) );
639 Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();
640 checkBox.SetSize( 48, 48 );
641 root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) );
643 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Don't show again" );
644 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
645 Actor textActor = text;
646 textActor.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 10.0f ) );
648 root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) );
650 content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0 ) );
653 mPopup.SetContent( content );
655 SetupPopup( mPopup, button );
657 else if( button.GetName() == POPUP_BUTTON_CUSTOM_STYLE )
659 mPopup = CreateConfirmationPopup( 2 );
661 Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( "Styled Popup" );
662 titleActor.SetName( "titleActor" );
663 titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::RED );
664 titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
665 titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
666 mPopup.SetTitle( titleActor );
668 SetupPopup( mPopup, button );
670 mPopup.SetStyleName( CUSTOM_POPUP_STYLE_NAME );
676 void OnKeyEvent( const KeyEvent& event )
678 if( event.state == KeyEvent::Down )
680 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
682 // Exit application when click back or escape.
688 public: // From ItemFactory
691 * @brief Return the number of items to display in the item view
693 * @return Return the number of items to display
695 virtual unsigned int GetNumberOfItems()
697 return POPUP_BUTTON_ITEMS_COUNT;
701 * @brief Create a new item to populate the item view with
703 * @param[in] itemId The index of the item to create
704 * @return Return the created actor for the given ID
706 virtual Actor NewItem(unsigned int itemId)
708 Toolkit::PushButton popupButton = Toolkit::PushButton::New();
709 popupButton.SetName( POPUP_BUTTON_ITEMS[ itemId ].name );
710 popupButton.SetLabelText( POPUP_BUTTON_ITEMS[ itemId ].text );
711 popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
713 popupButton.ClickedSignal().Connect( this, &PopupExample::OnButtonClicked );
721 Application& mApplication;
722 Toolkit::Control mView; ///< The View instance.
723 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
724 Toolkit::PushButton mContextButton; ///< For toggling contextual mode.
725 Toolkit::PushButton mAnimationButton; ///< For toggling the fade animation.
726 Layer mContentLayer; ///< Content layer
728 Toolkit::TextLabel mTitleActor; ///< Title text
730 bool mContextual; ///< True if currently using the contextual popup mode.
731 bool mAnimationFade; ///< True if currently using the fade animation.
733 Toolkit::Popup mPopup; ///< The current example popup.
735 Toolkit::ItemView mItemView; ///< ItemView to hold test images
739 void RunTest( Application& application )
741 PopupExample test( application );
743 application.MainLoop();
746 // Entry point for Linux & SLP applications
747 int DALI_EXPORT_API main( int argc, char **argv )
749 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
751 RunTest( application );