2 * Copyright (c) 2015 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 = DALI_IMAGE_DIR "background-gradient.jpg";
37 const char* const TOOLBAR_IMAGE = DALI_IMAGE_DIR "top-bar.png";
39 const char* const TOOLBAR_TITLE = "Popup";
41 const char* CONTEXT_DISABLED_ICON_IMAGE = DALI_IMAGE_DIR "icon-scroll-view-carousel.png";
42 const char* CONTEXT_ENABLED_ICON_IMAGE = DALI_IMAGE_DIR "icon-scroll-view-spiral.png";
43 const char* ANIMATION_FADE_ICON_IMAGE = DALI_IMAGE_DIR "icon-effects-off.png";
44 const char* ANIMATION_ZOOM_ICON_IMAGE = DALI_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";
58 // Names to give Popup PushButton controls.
59 const char* const POPUP_CONTROL_OK_NAME = "controlOk";
60 const char* const POPUP_CONTROL_CANCEL_NAME = "controlCancel";
62 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.";
63 const char* const IMAGE1 = DALI_IMAGE_DIR "gallery-medium-5.jpg";
64 const char* const IMAGE2 = DALI_IMAGE_DIR "background-magnifier.jpg";
66 // Control area image.
67 const char* DEFAULT_CONTROL_AREA_IMAGE_PATH = DALI_IMAGE_DIR "popup_button_background.9.png"; ///< Control area image for the popup.
69 const ButtonItem POPUP_BUTTON_ITEMS[] = {
70 { POPUP_BUTTON_COMPLEX_ID, "Complex" },
71 { POPUP_BUTTON_TOAST_ID, "Toast Popup" },
72 { POPUP_BUTTON_TITLE_ID, "Title" },
73 { POPUP_BUTTON_BUTTONS_1_ID, "1 Button" },
74 { POPUP_BUTTON_BUTTONS_2_ID, "2 Buttons" },
75 { POPUP_BUTTON_FIXED_SIZE_ID, "Fixed Size" },
76 { POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID, "Title + Content + Buttons" },
77 { POPUP_BUTTON_CONTENT_TEXT_ID, "Content Text" },
78 { POPUP_BUTTON_CONTENT_IMAGE_ID, "Content Image" },
79 { POPUP_BUTTON_TITLE_CONTENT_TEXT_ID, "Title + Content" },
80 { POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID, "Title + Large Content + Buttons" }
83 const int POPUP_BUTTON_ITEMS_COUNT = sizeof( POPUP_BUTTON_ITEMS ) / sizeof( POPUP_BUTTON_ITEMS[0] );
85 } // anonymous namespace
89 * This example shows the usage of the Popup class.
91 class PopupExample: public ConnectionTracker, public Toolkit::ItemFactory
95 PopupExample( Application& application )
96 : mApplication( application ),
98 mAnimationFade( true )
100 // Connect to the Application's Init signal
101 mApplication.InitSignal().Connect( this, &PopupExample::Create );
106 // Nothing to do here
109 void Create( Application& application )
111 // The Init signal is received once (only) during the Application lifetime
112 Stage stage = Stage::GetCurrent();
114 // Respond to key events
115 stage.KeyEventSignal().Connect(this, &PopupExample::OnKeyEvent);
117 // Creates a default view with a default tool bar.
118 // The view is added to the stage.
119 mContentLayer = DemoHelper::CreateView( application,
126 mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" );
127 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE );
129 // Add title to the tool bar.
130 const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding );
131 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
133 // Create animation button.
134 mAnimationButton = Toolkit::PushButton::New();
135 mAnimationButton.SetUnselectedImage( ANIMATION_FADE_ICON_IMAGE );
136 mAnimationButton.SetSelectedImage( ANIMATION_ZOOM_ICON_IMAGE );
137 mAnimationButton.SetTogglableButton( true );
138 mAnimationButton.ClickedSignal().Connect( this, &PopupExample::OnAnimationClicked );
139 mToolBar.AddControl( mAnimationButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
141 // Create context button.
142 mContextButton = Toolkit::PushButton::New();
143 mContextButton.SetUnselectedImage( CONTEXT_DISABLED_ICON_IMAGE );
144 mContextButton.SetSelectedImage( CONTEXT_ENABLED_ICON_IMAGE );
145 mContextButton.SetTogglableButton( true );
146 mContextButton.ClickedSignal().Connect( this, &PopupExample::OnContextClicked );
147 mToolBar.AddControl( mContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
149 // Add title to the tool bar.
150 mItemView = Toolkit::ItemView::New( *this );
151 mItemView.SetParentOrigin( ParentOrigin::CENTER );
152 mItemView.SetAnchorPoint( AnchorPoint::CENTER );
153 mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
155 // Use a grid layout for tests
156 Vector2 stageSize = stage.GetSize();
157 Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
159 gridLayout->GetItemSize( 0, Vector3( stageSize ), itemSize );
160 itemSize.height = stageSize.y / 10;
161 gridLayout->SetItemSize( itemSize );
162 mItemView.AddLayout( *gridLayout );
164 mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
166 mContentLayer.Add( mItemView );
169 bool OnContextClicked( Toolkit::Button button )
171 mContextual = button.IsSelected();
175 bool OnAnimationClicked( Toolkit::Button button )
177 mAnimationFade = !button.IsSelected();
182 * This function is designed as a shortcut to convert any resize policies set for a popup to
183 * ones that will work for contextual mode (for demo purposes).
184 * Note that in a real-use case example the policies would be set to something appropriate
185 * manually, but in the case of this demo, the popup is parented from the popup-opening buttons
186 * and (incorrectly) have their policies as "SIZE_RELATIVE_TO_PARENT". This would create a tiny
187 * popup that would not be able to contain it's contents, so to illustrate contextual behaviour
188 * this function converts the old policies and size to new ones that would give the popup the
189 * same visual appearance.
190 * @param[in] popup The popup whose policies should be modified.
192 void SetupContextualResizePolicy( Toolkit::Popup& popup )
194 Vector2 stageSize = Stage::GetCurrent().GetSize();
195 // Some defaults when creating a new fixed size.
196 // This is NOT a Vector2 so we can modify each dimension in a for-loop.
197 float newSize[ Dimension::DIMENSION_COUNT ] = { stageSize.x * 0.75f, stageSize.y * 0.75f };
198 bool modifySize = false;
200 // Loop through each of two dimensions to process them.
201 for( unsigned int dimension = 0; dimension < 2; ++dimension )
203 float stageDimensionSize, sizeModeFactor;
204 Dimension::Type policyDimension = dimension == 0 ? Dimension::WIDTH : Dimension::HEIGHT;
206 // Setup information related to the current dimension we are processing.
207 if( policyDimension == Dimension::WIDTH )
209 stageDimensionSize = stageSize.x;
210 sizeModeFactor = popup.GetSizeModeFactor().x;
214 stageDimensionSize = stageSize.y;
215 sizeModeFactor = popup.GetSizeModeFactor().y;
218 bool modifyPolicy = false;
219 ResizePolicy::Type policy = popup.GetResizePolicy( policyDimension );
220 ResizePolicy::Type newPolicy( policy );
222 // Switch on each policy type to determine the new behaviour.
225 case ResizePolicy::FIXED:
226 case ResizePolicy::USE_ASSIGNED_SIZE:
231 case ResizePolicy::USE_NATURAL_SIZE:
232 case ResizePolicy::FIT_TO_CHILDREN:
233 case ResizePolicy::DIMENSION_DEPENDENCY:
235 // Set size to 0 so the policy determines size.
236 // If a non-zero size is set, policy is converted to fixed.
237 newSize[ dimension ] = 0.0f;
242 // The following cases emulate the three size-mode related resize policies.
243 case ResizePolicy::FILL_TO_PARENT:
245 newPolicy = ResizePolicy::FIXED;
246 newSize[ dimension ] = stageDimensionSize;
251 case ResizePolicy::SIZE_RELATIVE_TO_PARENT:
253 newPolicy = ResizePolicy::FIXED;
254 newSize[ dimension ] = stageDimensionSize * sizeModeFactor;
259 case ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT:
261 newPolicy = ResizePolicy::FIXED;
262 newSize[ dimension ] = stageDimensionSize + sizeModeFactor;
270 // Set the new policy for this dimension, if it has been modified.
271 popup.SetResizePolicy( newPolicy, policyDimension );
278 // The size is set once at the end.
279 popup.SetSize( Vector2( newSize[ 0 ], newSize[ 1 ] ) );
283 void SetupPopup( Toolkit::Popup popup, Actor parent )
287 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "FADE" );
291 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "ZOOM" );
296 popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, "BELOW" );
298 // Modify the preset demo resize policies (and size) to contextual ones.
299 SetupContextualResizePolicy( popup );
305 Stage::GetCurrent().Add( popup );
308 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
315 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
328 Toolkit::Popup CreatePopup()
330 Stage stage = Stage::GetCurrent();
331 const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
333 Toolkit::Popup popup = Toolkit::Popup::New();
334 popup.SetName( "popup" );
335 popup.SetParentOrigin( ParentOrigin::CENTER );
336 popup.SetAnchorPoint( AnchorPoint::CENTER );
337 popup.SetSize( POPUP_WIDTH_DP, 0.0f );
338 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
340 popup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
341 popup.HiddenSignal().Connect( this, &PopupExample::PopupHidden );
346 Toolkit::Popup CreateConfirmationPopup( int numberOfButtons )
348 Toolkit::Popup confirmationPopup = Toolkit::Popup::New();
349 confirmationPopup.SetName( "MAIN-POPUP-SELF" );
351 if( numberOfButtons > 0 )
353 // Start with a control area image.
354 Toolkit::ImageView footer = Toolkit::ImageView::New( DEFAULT_CONTROL_AREA_IMAGE_PATH );
355 footer.SetName( "controlAreaImage" );
356 // Set up the container's layout.
357 footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
358 footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
359 footer.SetSize( 0.0f, 80.0f );
360 footer.SetAnchorPoint( AnchorPoint::CENTER );
361 footer.SetParentOrigin( ParentOrigin::CENTER );
363 Actor okButton = CreateOKButton();
364 okButton.SetParentOrigin( ParentOrigin::CENTER );
365 okButton.SetAnchorPoint( AnchorPoint::CENTER );
366 okButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
367 okButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0 ) );
369 if( numberOfButtons > 1 )
371 Toolkit::TableView controlLayout = Toolkit::TableView::New( 1, 2 );
372 controlLayout.SetParentOrigin( ParentOrigin::CENTER );
373 controlLayout.SetAnchorPoint( AnchorPoint::CENTER );
374 controlLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
376 Actor cancelButton = CreateCancelButton();
377 cancelButton.SetParentOrigin( ParentOrigin::CENTER );
378 cancelButton.SetAnchorPoint( AnchorPoint::CENTER );
379 cancelButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
380 cancelButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0 ) );
382 controlLayout.SetCellPadding( Size( 10.0f, 10.0f ) );
384 controlLayout.SetRelativeWidth( 0, 0.5f );
385 controlLayout.SetRelativeWidth( 1, 0.5f );
387 controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
388 controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
389 controlLayout.AddChild( okButton, Toolkit::TableView::CellPosition( 0, 0 ) );
390 controlLayout.AddChild( cancelButton, Toolkit::TableView::CellPosition( 0, 1 ) );
392 footer.Add( controlLayout );
396 footer.Add( okButton );
399 confirmationPopup.SetFooter( footer );
402 confirmationPopup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
404 return confirmationPopup;
407 Actor CreateTitle( std::string title )
409 Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( title );
410 titleActor.SetName( "titleActor" );
411 titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
412 titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
413 titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
418 Toolkit::PushButton CreateOKButton()
420 Toolkit::PushButton okayButton = Toolkit::PushButton::New();
421 okayButton.SetName( POPUP_CONTROL_OK_NAME );
422 okayButton.SetLabelText( "OK!" );
424 okayButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
429 Toolkit::PushButton CreateCancelButton()
431 Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
432 cancelButton.SetName( POPUP_CONTROL_CANCEL_NAME );
433 cancelButton.SetLabelText( "Cancel" );
435 cancelButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
440 bool OnPopupButtonClicked( Toolkit::Button button )
442 // Handle Popup pushbuttons being clicked.
447 bool OnButtonClicked( Toolkit::Button button )
449 // Handle menu items that create popups.
450 if( button.GetName() == POPUP_BUTTON_TITLE_ID )
452 mPopup = CreatePopup();
453 mPopup.SetTitle( CreateTitle( "Popup!" ) );
455 SetupPopup( mPopup, button );
457 else if( button.GetName() == POPUP_BUTTON_BUTTONS_1_ID )
459 mPopup = CreateConfirmationPopup( 1 );
460 mPopup.SetTitle( CreateTitle( "Title" ) );
462 SetupPopup( mPopup, button );
464 else if( button.GetName() == POPUP_BUTTON_BUTTONS_2_ID )
466 mPopup = CreateConfirmationPopup( 2 );
467 mPopup.SetTitle( CreateTitle( "Title" ) );
469 SetupPopup( mPopup, button );
471 else if( button.GetName() == POPUP_BUTTON_TOAST_ID )
473 // Create a toast popup via the type registry (as it is a named-type).
474 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "popupToast" );
477 BaseHandle baseHandle = typeInfo.CreateInstance();
480 mPopup = Toolkit::Popup::DownCast( baseHandle );
481 mPopup.SetTitle( CreateTitle( "This is a Toast Popup.\nIt will auto-hide itself" ) );
483 Stage::GetCurrent().Add( mPopup );
484 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
488 else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID )
490 mPopup = CreateConfirmationPopup( 2 );
491 mPopup.SetTitle( CreateTitle( "Erase image" ) );
493 Toolkit::TextLabel text = Toolkit::TextLabel::New( "This will erase the image permanently. Are you sure?" );
494 text.SetName( "POPUP_CONTENT_TEXT" );
495 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
496 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
497 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
498 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
499 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
500 mPopup.SetContent( text );
502 SetupPopup( mPopup, button );
504 else if( button.GetName() == POPUP_BUTTON_CONTENT_TEXT_ID )
506 mPopup = CreatePopup();
508 TextLabel text = TextLabel::New( CONTENT_TEXT );
509 text.SetName( "POPUP_CONTENT_TEXT" );
510 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
511 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
512 text.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
513 text.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
514 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
515 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
516 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
520 SetupPopup( mPopup, button );
522 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_ID )
524 mPopup = CreatePopup();
525 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE2 );
526 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
527 image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
528 image.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
532 SetupPopup( mPopup, button );
534 else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID )
536 mPopup = CreatePopup();
537 mPopup.SetTitle( CreateTitle( "Popup!" ) );
539 Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
540 text.SetName( "POPUP_CONTENT_TEXT" );
541 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
542 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
543 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
544 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
545 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
549 SetupPopup( mPopup, button );
551 else if( button.GetName() == POPUP_BUTTON_FIXED_SIZE_ID )
553 mPopup = CreatePopup();
554 mPopup.SetTitle( CreateTitle( "Popup!" ) );
556 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed size popup" );
557 text.SetName( "POPUP_CONTENT_TEXT" );
558 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
559 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
560 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
564 // Fix the popup's size.
565 mPopup.SetSize( 240.0f, 400.0f );
566 mPopup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
568 SetupPopup( mPopup, button );
570 else if( button.GetName() == POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID )
572 mPopup = CreateConfirmationPopup( 2 );
573 mPopup.SetTitle( CreateTitle( "Popup!" ) );
575 Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
576 text.SetName( "POPUP_CONTENT_TEXT" );
577 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
578 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
579 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
580 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
581 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
585 SetupPopup( mPopup, button );
587 else if( button.GetName() == POPUP_BUTTON_COMPLEX_ID )
589 mPopup = CreateConfirmationPopup( 2 );
590 mPopup.SetTitle( CreateTitle( "Warning" ) );
593 Toolkit::TableView content = Toolkit::TableView::New( 2, 2 );
594 content.SetName( "COMPLEX_TABLEVIEW" );
595 content.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
596 content.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
597 content.SetFitHeight( 0 );
598 content.SetFitHeight( 1 );
599 content.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 0.0f ) );
603 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Do you really want to quit?" );
604 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
605 text.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
606 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
607 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
609 content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) );
614 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE1 );
615 image.SetName( "COMPLEX_IMAGE" );
616 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
617 image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
618 image.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 0.0f ) );
619 content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) );
624 Toolkit::TableView root = Toolkit::TableView::New( 1, 2 );
625 root.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
626 root.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
627 root.SetFitHeight( 0 );
628 root.SetFitWidth( 0 );
629 root.SetPadding( Padding( 0.0f, 0.0f, 0.0f, 20.0f ) );
631 Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();
632 checkBox.SetSize( 48, 48 );
633 root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) );
635 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Don't show again" );
636 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
637 Actor textActor = text;
638 textActor.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 10.0f ) );
640 root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) );
642 content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0 ) );
645 mPopup.SetContent( content );
647 SetupPopup( mPopup, button );
653 void OnKeyEvent( const KeyEvent& event )
655 if( event.state == KeyEvent::Down )
657 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
659 // Exit application when click back or escape.
665 public: // From ItemFactory
668 * @brief Return the number of items to display in the item view
670 * @return Return the number of items to display
672 virtual unsigned int GetNumberOfItems()
674 return POPUP_BUTTON_ITEMS_COUNT;
678 * @brief Create a new item to populate the item view with
680 * @param[in] itemId The index of the item to create
681 * @return Return the created actor for the given ID
683 virtual Actor NewItem(unsigned int itemId)
685 Toolkit::PushButton popupButton = Toolkit::PushButton::New();
686 popupButton.SetName( POPUP_BUTTON_ITEMS[ itemId ].name );
687 popupButton.SetLabelText( POPUP_BUTTON_ITEMS[ itemId ].text );
688 popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
690 popupButton.ClickedSignal().Connect( this, &PopupExample::OnButtonClicked );
698 Application& mApplication;
699 Toolkit::Control mView; ///< The View instance.
700 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
701 Toolkit::PushButton mContextButton; ///< For toggling contextual mode.
702 Toolkit::PushButton mAnimationButton; ///< For toggling the fade animation.
703 Layer mContentLayer; ///< Content layer
705 Toolkit::TextLabel mTitleActor; ///< Title text
707 bool mContextual; ///< True if currently using the contextual popup mode.
708 bool mAnimationFade; ///< True if currently using the fade animation.
710 ResourceImage mContextButtonDisabledImage; ///< The disabled context button icon.
711 ResourceImage mContextButtonEnabledImage; ///< The enabled context button icon.
712 ResourceImage mAnimationButtonZoomImage; ///< The zoom animation button icon.
713 ResourceImage mAnimationButtonFadeImage; ///< The fade animation button icon.
715 Toolkit::Popup mPopup; ///< The current example popup.
717 Toolkit::ItemView mItemView; ///< ItemView to hold test images
721 void RunTest( Application& application )
723 PopupExample test( application );
725 application.MainLoop();
728 // Entry point for Linux & SLP applications
729 int main( int argc, char **argv )
731 Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH );
733 RunTest( application );