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 = "control-ok";
60 const char* const POPUP_CONTROL_CANCEL_NAME = "control-cancel";
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.png"; ///< Control area image for the popup.
68 const Vector4 DEFAULT_CONTROL_AREA_9_PATCH_BORDER( 13.0f, 8.0f, 13.0f, 8.0f ); ///< Nine patch information for the control area background.
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" }
84 const int POPUP_BUTTON_ITEMS_COUNT = sizeof( POPUP_BUTTON_ITEMS ) / sizeof( POPUP_BUTTON_ITEMS[0] );
86 } // anonymous namespace
90 * This example shows the usage of the Popup class.
92 class PopupExample: public ConnectionTracker, public Toolkit::ItemFactory
96 PopupExample( Application& application )
97 : mApplication( application ),
99 mAnimationFade( true )
101 // Connect to the Application's Init signal
102 mApplication.InitSignal().Connect( this, &PopupExample::Create );
107 // Nothing to do here
110 void Create( Application& application )
112 // The Init signal is received once (only) during the Application lifetime
113 Stage stage = Stage::GetCurrent();
115 // Respond to key events
116 stage.KeyEventSignal().Connect(this, &PopupExample::OnKeyEvent);
118 // Creates a default view with a default tool bar.
119 // The view is added to the stage.
120 mContentLayer = DemoHelper::CreateView( application,
127 mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" );
128 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE );
130 // Add title to the tool bar.
131 const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding );
132 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
134 // Create animation button.
135 mAnimationButton = Toolkit::PushButton::New();
136 mAnimationButton.SetUnselectedImage( ANIMATION_FADE_ICON_IMAGE );
137 mAnimationButton.SetSelectedImage( ANIMATION_ZOOM_ICON_IMAGE );
138 mAnimationButton.SetTogglableButton( true );
139 mAnimationButton.ClickedSignal().Connect( this, &PopupExample::OnAnimationClicked );
140 mToolBar.AddControl( mAnimationButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
142 // Create context button.
143 mContextButton = Toolkit::PushButton::New();
144 mContextButton.SetUnselectedImage( CONTEXT_DISABLED_ICON_IMAGE );
145 mContextButton.SetSelectedImage( CONTEXT_ENABLED_ICON_IMAGE );
146 mContextButton.SetTogglableButton( true );
147 mContextButton.ClickedSignal().Connect( this, &PopupExample::OnContextClicked );
148 mToolBar.AddControl( mContextButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
150 // Add title to the tool bar.
151 mItemView = Toolkit::ItemView::New( *this );
152 mItemView.SetParentOrigin( ParentOrigin::CENTER );
153 mItemView.SetAnchorPoint( AnchorPoint::CENTER );
154 mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
156 // Use a grid layout for tests
157 Vector2 stageSize = stage.GetSize();
158 Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
160 gridLayout->GetItemSize( 0, Vector3( stageSize ), itemSize );
161 itemSize.height = stageSize.y / 10;
162 gridLayout->SetItemSize( itemSize );
163 mItemView.AddLayout( *gridLayout );
165 mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
167 mContentLayer.Add( mItemView );
170 bool OnContextClicked( Toolkit::Button button )
172 mContextual = button.IsSelected();
176 bool OnAnimationClicked( Toolkit::Button button )
178 mAnimationFade = !button.IsSelected();
183 * This function is designed as a shortcut to convert any resize policies set for a popup to
184 * ones that will work for contextual mode (for demo purposes).
185 * Note that in a real-use case example the policies would be set to something appropriate
186 * manually, but in the case of this demo, the popup is parented from the popup-opening buttons
187 * and (incorrectly) have their policies as "SIZE_RELATIVE_TO_PARENT". This would create a tiny
188 * popup that would not be able to contain it's contents, so to illustrate contextual behaviour
189 * this function converts the old policies and size to new ones that would give the popup the
190 * same visual appearance.
191 * @param[in] popup The popup whose policies should be modified.
193 void SetupContextualResizePolicy( Toolkit::Popup& popup )
195 Vector2 stageSize = Stage::GetCurrent().GetSize();
196 // Some defaults when creating a new fixed size.
197 // This is NOT a Vector2 so we can modify each dimension in a for-loop.
198 float newSize[ Dimension::DIMENSION_COUNT ] = { stageSize.x * 0.75f, stageSize.y * 0.75f };
199 bool modifySize = false;
201 // Loop through each of two dimensions to process them.
202 for( unsigned int dimension = 0; dimension < 2; ++dimension )
204 float stageDimensionSize, sizeModeFactor;
205 Dimension::Type policyDimension = dimension == 0 ? Dimension::WIDTH : Dimension::HEIGHT;
207 // Setup information related to the current dimension we are processing.
208 if( policyDimension == Dimension::WIDTH )
210 stageDimensionSize = stageSize.x;
211 sizeModeFactor = popup.GetSizeModeFactor().x;
215 stageDimensionSize = stageSize.y;
216 sizeModeFactor = popup.GetSizeModeFactor().y;
219 bool modifyPolicy = false;
220 ResizePolicy::Type policy = popup.GetResizePolicy( policyDimension );
221 ResizePolicy::Type newPolicy( policy );
223 // Switch on each policy type to determine the new behaviour.
226 case ResizePolicy::FIXED:
227 case ResizePolicy::USE_ASSIGNED_SIZE:
232 case ResizePolicy::USE_NATURAL_SIZE:
233 case ResizePolicy::FIT_TO_CHILDREN:
234 case ResizePolicy::DIMENSION_DEPENDENCY:
236 // Set size to 0 so the policy determines size.
237 // If a non-zero size is set, policy is converted to fixed.
238 newSize[ dimension ] = 0.0f;
243 // The following cases emulate the three size-mode related resize policies.
244 case ResizePolicy::FILL_TO_PARENT:
246 newPolicy = ResizePolicy::FIXED;
247 newSize[ dimension ] = stageDimensionSize;
252 case ResizePolicy::SIZE_RELATIVE_TO_PARENT:
254 newPolicy = ResizePolicy::FIXED;
255 newSize[ dimension ] = stageDimensionSize * sizeModeFactor;
260 case ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT:
262 newPolicy = ResizePolicy::FIXED;
263 newSize[ dimension ] = stageDimensionSize + sizeModeFactor;
271 // Set the new policy for this dimension, if it has been modified.
272 popup.SetResizePolicy( newPolicy, policyDimension );
279 // The size is set once at the end.
280 popup.SetSize( Vector2( newSize[ 0 ], newSize[ 1 ] ) );
284 void SetupPopup( Toolkit::Popup popup, Actor parent )
288 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "FADE" );
292 popup.SetProperty( Toolkit::Popup::Property::ANIMATION_MODE, "ZOOM" );
297 popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, "BELOW" );
299 // Modify the preset demo resize policies (and size) to contextual ones.
300 SetupContextualResizePolicy( popup );
306 Stage::GetCurrent().Add( popup );
309 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
316 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
329 Toolkit::Popup CreatePopup()
331 Stage stage = Stage::GetCurrent();
332 const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
334 Toolkit::Popup popup = Toolkit::Popup::New();
335 popup.SetName( "popup" );
336 popup.SetParentOrigin( ParentOrigin::CENTER );
337 popup.SetAnchorPoint( AnchorPoint::CENTER );
338 popup.SetSize( POPUP_WIDTH_DP, 0.0f );
339 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
341 popup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
342 popup.HiddenSignal().Connect( this, &PopupExample::PopupHidden );
347 Toolkit::Popup CreateConfirmationPopup( int numberOfButtons )
349 Toolkit::Popup confirmationPopup = Toolkit::Popup::New();
350 confirmationPopup.SetName( "MAIN-POPUP-SELF" );
352 if( numberOfButtons > 0 )
354 // Start with a control area image.
355 ImageActor footer = ImageActor::New( ResourceImage::New( DEFAULT_CONTROL_AREA_IMAGE_PATH ) );
356 // Nine patch information is only used for the default control area image.
357 footer.SetStyle( ImageActor::STYLE_NINE_PATCH );
358 footer.SetNinePatchBorder( DEFAULT_CONTROL_AREA_9_PATCH_BORDER );
359 footer.SetName( "control-area-image" );
360 // Set up the container's layout.
361 footer.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
362 footer.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
363 footer.SetSize( 0.0f, 80.0f );
364 footer.SetAnchorPoint( AnchorPoint::CENTER );
365 footer.SetParentOrigin( ParentOrigin::CENTER );
367 Actor okButton = CreateOKButton();
368 okButton.SetParentOrigin( ParentOrigin::CENTER );
369 okButton.SetAnchorPoint( AnchorPoint::CENTER );
370 okButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
371 okButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0 ) );
373 if( numberOfButtons > 1 )
375 Toolkit::TableView controlLayout = Toolkit::TableView::New( 1, 2 );
376 controlLayout.SetParentOrigin( ParentOrigin::CENTER );
377 controlLayout.SetAnchorPoint( AnchorPoint::CENTER );
378 controlLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
380 Actor cancelButton = CreateCancelButton();
381 cancelButton.SetParentOrigin( ParentOrigin::CENTER );
382 cancelButton.SetAnchorPoint( AnchorPoint::CENTER );
383 cancelButton.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
384 cancelButton.SetSizeModeFactor( Vector3( -20.0f, -20.0f, 0.0 ) );
386 controlLayout.SetCellPadding( Size( 10.0f, 10.0f ) );
388 controlLayout.SetRelativeWidth( 0, 0.5f );
389 controlLayout.SetRelativeWidth( 1, 0.5f );
391 controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 0 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
392 controlLayout.SetCellAlignment( Toolkit::TableView::CellPosition( 0, 1 ), HorizontalAlignment::CENTER, VerticalAlignment::CENTER );
393 controlLayout.AddChild( okButton, Toolkit::TableView::CellPosition( 0, 0 ) );
394 controlLayout.AddChild( cancelButton, Toolkit::TableView::CellPosition( 0, 1 ) );
396 footer.Add( controlLayout );
400 footer.Add( okButton );
403 confirmationPopup.SetFooter( footer );
406 confirmationPopup.OutsideTouchedSignal().Connect( this, &PopupExample::HidePopup );
408 return confirmationPopup;
411 Actor CreateTitle( std::string title )
413 Toolkit::TextLabel titleActor = Toolkit::TextLabel::New( title );
414 titleActor.SetName( "title-actor" );
415 titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
416 titleActor.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
417 titleActor.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
422 Toolkit::PushButton CreateOKButton()
424 Toolkit::PushButton okayButton = Toolkit::PushButton::New();
425 okayButton.SetName( POPUP_CONTROL_OK_NAME );
426 okayButton.SetLabelText( "OK!" );
428 okayButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
433 Toolkit::PushButton CreateCancelButton()
435 Toolkit::PushButton cancelButton = Toolkit::PushButton::New();
436 cancelButton.SetName( POPUP_CONTROL_CANCEL_NAME );
437 cancelButton.SetLabelText( "Cancel" );
439 cancelButton.ClickedSignal().Connect( this, &PopupExample::OnPopupButtonClicked );
444 bool OnPopupButtonClicked( Toolkit::Button button )
446 // Handle Popup pushbuttons being clicked.
451 bool OnButtonClicked( Toolkit::Button button )
453 // Handle menu items that create popups.
454 if( button.GetName() == POPUP_BUTTON_TITLE_ID )
456 mPopup = CreatePopup();
457 mPopup.SetTitle( CreateTitle( "Popup!" ) );
459 SetupPopup( mPopup, button );
461 else if( button.GetName() == POPUP_BUTTON_BUTTONS_1_ID )
463 mPopup = CreateConfirmationPopup( 1 );
464 mPopup.SetTitle( CreateTitle( "Title" ) );
466 SetupPopup( mPopup, button );
468 else if( button.GetName() == POPUP_BUTTON_BUTTONS_2_ID )
470 mPopup = CreateConfirmationPopup( 2 );
471 mPopup.SetTitle( CreateTitle( "Title" ) );
473 SetupPopup( mPopup, button );
475 else if( button.GetName() == POPUP_BUTTON_TOAST_ID )
477 // Create a toast popup via the type registry (as it is a named-type).
478 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "popup-toast" );
481 BaseHandle baseHandle = typeInfo.CreateInstance();
484 mPopup = Toolkit::Popup::DownCast( baseHandle );
485 mPopup.SetTitle( CreateTitle( "This is a Toast Popup.\nIt will auto-hide itself" ) );
487 Stage::GetCurrent().Add( mPopup );
488 mPopup.SetDisplayState( Toolkit::Popup::SHOWN );
492 else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_BUTTONS_ID )
494 mPopup = CreateConfirmationPopup( 2 );
495 mPopup.SetTitle( CreateTitle( "Erase image" ) );
497 Toolkit::TextLabel text = Toolkit::TextLabel::New( "This will erase the image permanently. Are you sure?" );
498 text.SetName( "POPUP_CONTENT_TEXT" );
499 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
500 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
501 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
502 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
503 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
504 mPopup.SetContent( text );
506 SetupPopup( mPopup, button );
508 else if( button.GetName() == POPUP_BUTTON_CONTENT_TEXT_ID )
510 mPopup = CreatePopup();
512 TextLabel text = TextLabel::New( CONTENT_TEXT );
513 text.SetName( "POPUP_CONTENT_TEXT" );
514 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
515 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
516 text.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
517 text.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
518 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
519 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
520 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
524 SetupPopup( mPopup, button );
526 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_ID )
528 mPopup = CreatePopup();
529 ImageActor image = ImageActor::New( ResourceImage::New( IMAGE2 ) );
530 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
531 image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
532 image.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
536 SetupPopup( mPopup, button );
538 else if( button.GetName() == POPUP_BUTTON_TITLE_CONTENT_TEXT_ID )
540 mPopup = CreatePopup();
541 mPopup.SetTitle( CreateTitle( "Popup!" ) );
543 Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
544 text.SetName( "POPUP_CONTENT_TEXT" );
545 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
546 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
547 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
548 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
549 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
553 SetupPopup( mPopup, button );
555 else if( button.GetName() == POPUP_BUTTON_FIXED_SIZE_ID )
557 mPopup = CreatePopup();
558 mPopup.SetTitle( CreateTitle( "Popup!" ) );
560 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed size popup" );
561 text.SetName( "POPUP_CONTENT_TEXT" );
562 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
563 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
564 text.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 20.0f ) );
568 // Fix the popup's size.
569 mPopup.SetSize( 240.0f, 400.0f );
570 mPopup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
572 SetupPopup( mPopup, button );
574 else if( button.GetName() == POPUP_BUTTON_TITLE_LARGE_CONTENT_BUTTONS_ID )
576 mPopup = CreateConfirmationPopup( 2 );
577 mPopup.SetTitle( CreateTitle( "Popup!" ) );
579 Toolkit::TextLabel text = Toolkit::TextLabel::New( CONTENT_TEXT );
580 text.SetName( "POPUP_CONTENT_TEXT" );
581 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
582 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
583 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
584 text.SetProperty( TextLabel::Property::MULTI_LINE, true );
585 text.SetPadding( Padding( 10.0f, 10.0f, 20.0f, 0.0f ) );
589 SetupPopup( mPopup, button );
591 else if( button.GetName() == POPUP_BUTTON_COMPLEX_ID )
593 mPopup = CreateConfirmationPopup( 2 );
594 mPopup.SetTitle( CreateTitle( "Warning" ) );
597 Toolkit::TableView content = Toolkit::TableView::New( 2, 2 );
598 content.SetName( "COMPLEX_TABLEVIEW" );
599 content.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
600 content.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
601 content.SetFitHeight( 0 );
602 content.SetFitHeight( 1 );
603 content.SetPadding( Padding( 20.0f, 20.0f, 20.0f, 0.0f ) );
607 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Do you really want to quit?" );
608 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
609 text.SetProperty( Toolkit::TextLabel::Property::MULTI_LINE, true );
610 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
611 text.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
613 content.AddChild( text, Toolkit::TableView::CellPosition( 0, 0 ) );
618 ImageActor image = ImageActor::New( ResourceImage::New( IMAGE1 ) );
619 image.SetName( "COMPLEX_IMAGE" );
620 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
621 image.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
622 image.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 0.0f ) );
623 content.AddChild( image, Toolkit::TableView::CellPosition( 0, 1 ) );
628 Toolkit::TableView root = Toolkit::TableView::New( 1, 2 );
629 root.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
630 root.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
631 root.SetFitHeight( 0 );
632 root.SetFitWidth( 0 );
633 root.SetPadding( Padding( 0.0f, 0.0f, 0.0f, 20.0f ) );
635 Toolkit::CheckBoxButton checkBox = Toolkit::CheckBoxButton::New();
636 checkBox.SetSize( 48, 48 );
637 root.AddChild( checkBox, Toolkit::TableView::CellPosition( 0, 0 ) );
639 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Don't show again" );
640 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
641 Actor textActor = text;
642 textActor.SetPadding( Padding( 20.0f, 0.0f, 0.0f, 10.0f ) );
644 root.AddChild( text, Toolkit::TableView::CellPosition( 0, 1 ) );
646 content.AddChild( root, Toolkit::TableView::CellPosition( 1, 0 ) );
649 mPopup.SetContent( content );
651 SetupPopup( mPopup, button );
657 void OnKeyEvent( const KeyEvent& event )
659 if( event.state == KeyEvent::Down )
661 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
663 // Exit application when click back or escape.
669 public: // From ItemFactory
672 * @brief Return the number of items to display in the item view
674 * @return Return the number of items to display
676 virtual unsigned int GetNumberOfItems()
678 return POPUP_BUTTON_ITEMS_COUNT;
682 * @brief Create a new item to populate the item view with
684 * @param[in] itemId The index of the item to create
685 * @return Return the created actor for the given ID
687 virtual Actor NewItem(unsigned int itemId)
689 Toolkit::PushButton popupButton = Toolkit::PushButton::New();
690 popupButton.SetName( POPUP_BUTTON_ITEMS[ itemId ].name );
691 popupButton.SetLabelText( POPUP_BUTTON_ITEMS[ itemId ].text );
692 popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
694 popupButton.ClickedSignal().Connect( this, &PopupExample::OnButtonClicked );
702 Application& mApplication;
703 Toolkit::Control mView; ///< The View instance.
704 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
705 Toolkit::PushButton mContextButton; ///< For toggling contextual mode.
706 Toolkit::PushButton mAnimationButton; ///< For toggling the fade animation.
707 Layer mContentLayer; ///< Content layer
709 Toolkit::TextLabel mTitleActor; ///< Title text
711 bool mContextual; ///< True if currently using the contextual popup mode.
712 bool mAnimationFade; ///< True if currently using the fade animation.
714 ResourceImage mContextButtonDisabledImage; ///< The disabled context button icon.
715 ResourceImage mContextButtonEnabledImage; ///< The enabled context button icon.
716 ResourceImage mAnimationButtonZoomImage; ///< The zoom animation button icon.
717 ResourceImage mAnimationButtonFadeImage; ///< The fade animation button icon.
719 Toolkit::Popup mPopup; ///< The current example popup.
721 Toolkit::ItemView mItemView; ///< ItemView to hold test images
725 void RunTest( Application& application )
727 PopupExample test( application );
729 application.MainLoop();
732 // Entry point for Linux & SLP applications
733 int main( int argc, char **argv )
735 Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH );
737 RunTest( application );