[dali_1.2.10] Merge branch 'devel/master'
[platform/core/uifw/dali-demo.git] / examples / size-negotiation / size-negotiation-example.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
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>
23
24 using namespace Dali;
25
26 using Dali::Toolkit::TextLabel;
27
28 struct ButtonItem
29 {
30   const char* name;
31   const char* text;
32 };
33
34 namespace
35 {
36
37 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg";
38 const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";
39 const char* const IMAGE = DEMO_IMAGE_DIR "background-magnifier.jpg";
40
41 const char* const TOOLBAR_TITLE = "Negotiate Size";
42
43 // This example contains size negotiation tests for TableView and Popup.
44 const char* const TABLEVIEW_BUTTON_1CELL_ID = "TABLEVIEW_BUTTON_1CELL";
45 const char* const TABLEVIEW_BUTTON_3CELL_ID = "TABLEVIEW_BUTTON_3CELL";
46 const char* const TABLEVIEW_BUTTON_3X3CELL_ID = "TABLEVIEW_BUTTON_3X3CELL";
47 const char* const TABLEVIEW_BUTTON_FIXED1_ID = "TABLEVIEW_BUTTON_FIXED1";
48 const char* const TABLEVIEW_BUTTON_FIXED2_ID = "TABLEVIEW_BUTTON_FIXED2";
49 const char* const TABLEVIEW_BUTTON_FIT1_ID = "TABLEVIEW_BUTTON_FIT1";
50 const char* const TABLEVIEW_BUTTON_FIT2_ID = "TABLEVIEW_BUTTON_FIT2";
51 const char* const TABLEVIEW_BUTTON_NATURAL1_ID = "TABLEVIEW_BUTTON_NATURAL1";
52 const char* const TABLEVIEW_BUTTON_NATURAL2_ID = "TABLEVIEW_BUTTON_NATURAL2";
53 const char* const TABLEVIEW_BUTTON_NATURAL3_ID = "TABLEVIEW_BUTTON_NATURAL3";
54 const char* const POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID = "POPUP_BUTTON_CONTENT_IMAGE_SCALE";
55 const char* const POPUP_BUTTON_CONTENT_IMAGE_FIT_ID = "POPUP_BUTTON_CONTENT_IMAGE_FIT";
56 const char* const POPUP_BUTTON_CONTENT_IMAGE_FILL_ID = "POPUP_BUTTON_CONTENT_IMAGE_FILL";
57
58 const ButtonItem TABLEVIEW_BUTTON_ITEMS[] = {
59     { TABLEVIEW_BUTTON_1CELL_ID,                    "1 Cell" },
60     { TABLEVIEW_BUTTON_3CELL_ID,                    "3 Cell" },
61     { TABLEVIEW_BUTTON_3X3CELL_ID,                  "3x3 Cells" },
62     { TABLEVIEW_BUTTON_FIXED1_ID,                   "Fixed 1" },
63     { TABLEVIEW_BUTTON_FIXED2_ID,                   "Fixed 2" },
64     { TABLEVIEW_BUTTON_FIT1_ID,                     "Fit Top Bottom" },
65     { TABLEVIEW_BUTTON_FIT2_ID,                     "Fit Middle" },
66     { TABLEVIEW_BUTTON_NATURAL1_ID,                 "Natural 1" },
67     { TABLEVIEW_BUTTON_NATURAL2_ID,                 "Natural 2" },
68     { TABLEVIEW_BUTTON_NATURAL3_ID,                 "Natural 3" },
69     { POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID,          "Image Scale" },
70     { POPUP_BUTTON_CONTENT_IMAGE_FIT_ID,            "Image Fit" },
71     { POPUP_BUTTON_CONTENT_IMAGE_FILL_ID,           "Image Fill" },
72 };
73
74 const unsigned int TABLEVIEW_BUTTON_ITEMS_COUNT = sizeof( TABLEVIEW_BUTTON_ITEMS ) / sizeof( TABLEVIEW_BUTTON_ITEMS[0] );
75
76
77 Actor CreateSolidColor( Vector4 color )
78 {
79   Toolkit::Control control = Toolkit::Control::New();
80
81   Property::Map map;
82   map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
83   map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
84   control.SetProperty( Toolkit::Control::Property::BACKGROUND, map );
85
86   return control;
87 }
88
89 }  // anonymous namespace
90
91
92 /**
93  * This example shows the usage of size negotiation.
94  */
95 class SizeNegotiationController: public ConnectionTracker, public Toolkit::ItemFactory
96 {
97 public:
98
99   SizeNegotiationController( Application& application )
100     : mApplication( application )
101   {
102     // Connect to the Application's Init signal
103     mApplication.InitSignal().Connect( this, &SizeNegotiationController::Create );
104   }
105
106   ~SizeNegotiationController()
107   {
108     // Nothing to do here
109   }
110
111   void Create( Application& application )
112   {
113     // The Init signal is received once (only) during the Application lifetime
114     Stage stage = Stage::GetCurrent();
115
116     // Respond to key events if not handled
117     Toolkit::KeyInputFocusManager keyInputFocusManager = Toolkit::KeyInputFocusManager::Get();
118     if( keyInputFocusManager )
119     {
120       keyInputFocusManager.UnhandledKeyEventSignal().Connect(this, &SizeNegotiationController::OnKeyEvent);
121     }
122
123     // Creates a default view with a default tool bar.
124     // The view is added to the stage.
125     mContentLayer = DemoHelper::CreateView( application,
126                                             mView,
127                                             mToolBar,
128                                             BACKGROUND_IMAGE,
129                                             TOOLBAR_IMAGE,
130                                             std::string("") );
131
132     mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" );
133     mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE );
134
135     // Add title to the tool bar.
136     const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding );
137     mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
138
139     mItemView = Toolkit::ItemView::New( *this );
140     mItemView.SetParentOrigin( ParentOrigin::CENTER );
141     mItemView.SetAnchorPoint( AnchorPoint::CENTER );
142     mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
143
144     // Use a grid layout for tests
145     Vector2 stageSize = stage.GetSize();
146     Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
147     Vector3 itemSize;
148     gridLayout->GetItemSize( 0, Vector3( stageSize ), itemSize );
149     itemSize.height = stageSize.y / 10;
150     gridLayout->SetItemSize( itemSize );
151     mItemView.AddLayout( *gridLayout );
152
153     mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
154
155     mContentLayer.Add( mItemView );
156   }
157
158   void StagePopup( Toolkit::Popup popup )
159   {
160     Stage::GetCurrent().Add( popup );
161     popup.SetDisplayState( Toolkit::Popup::SHOWN );
162   }
163
164   void OnPopupOutsideTouched()
165   {
166     if( mPopup )
167     {
168       mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
169     }
170   }
171
172   void PopupHidden()
173   {
174     if( mPopup )
175     {
176       mPopup.Unparent();
177       mPopup.Reset();
178     }
179   }
180
181   Toolkit::Popup CreatePopup()
182   {
183     Stage stage = Stage::GetCurrent();
184     const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
185
186     Toolkit::Popup popup = Toolkit::Popup::New();
187     popup.SetName( "popup" );
188     popup.SetParentOrigin( ParentOrigin::CENTER );
189     popup.SetAnchorPoint( AnchorPoint::CENTER );
190     popup.SetSize( POPUP_WIDTH_DP, 0.0f );
191     popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
192
193     popup.OutsideTouchedSignal().Connect( this, &SizeNegotiationController::OnPopupOutsideTouched );
194     popup.HiddenSignal().Connect( this, &SizeNegotiationController::PopupHidden );
195
196     return popup;
197   }
198
199   bool OnButtonClicked( Toolkit::Button button )
200   {
201     if( button.GetName() == TABLEVIEW_BUTTON_1CELL_ID )
202     {
203       mPopup = CreatePopup();
204       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
205       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
206
207       Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
208       table.SetName( "TABLEVIEW_BUTTON_1CELL_ID" );
209       table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
210
211       Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
212       backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
213       table.Add( backing );
214
215       mPopup.Add( table );
216
217       StagePopup( mPopup );
218     }
219     else if( button.GetName() == TABLEVIEW_BUTTON_3CELL_ID )
220     {
221       mPopup = CreatePopup();
222       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
223       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
224
225       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
226       table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
227
228       {
229         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
230         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
231         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) );
232       }
233       {
234         Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
235         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
236         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) );
237       }
238       {
239         Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
240         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
241         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) );
242       }
243
244       mPopup.SetContent( table );
245
246       StagePopup( mPopup );
247     }
248     else if( button.GetName() == TABLEVIEW_BUTTON_3X3CELL_ID )
249     {
250       mPopup = CreatePopup();
251       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
252       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
253
254       Toolkit::TableView table = Toolkit::TableView::New( 3, 3 );
255       table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
256
257       // Column 0
258       {
259         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
260         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
261         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) );
262       }
263       {
264         Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
265         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
266         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) );
267       }
268       {
269         Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
270         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
271         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) );
272       }
273
274       // Column 1
275       {
276         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
277         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
278         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 1 ) );
279       }
280       {
281         Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
282         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
283         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 1 ) );
284       }
285       {
286         Actor backing = CreateSolidColor( Vector4( 0.0f, 0.0f, 1.0f, 1.0f ) );
287         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
288         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 1 ) );
289       }
290
291       // Column 2
292       {
293         Actor backing = CreateSolidColor( Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) );
294         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
295         table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 2 ) );
296       }
297       {
298         Actor backing = CreateSolidColor( Vector4( 0.5f, 0.5f, 0.5f, 1.0f ) );
299         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
300         table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 2 ) );
301       }
302       {
303         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.5f, 0.0f, 1.0f ) );
304         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
305         table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 2 ) );
306       }
307
308       mPopup.Add( table );
309
310       StagePopup( mPopup );
311     }
312     else if( button.GetName() == TABLEVIEW_BUTTON_FIXED1_ID )
313     {
314       mPopup = CreatePopup();
315       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
316       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
317
318       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
319       table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
320       table.SetFixedHeight( 0, 50.0f );
321
322       {
323         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
324         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
325         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
326         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
327         text.SetParentOrigin( ParentOrigin::CENTER );
328         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
329         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
330         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
331         backing.Add( text );
332         table.Add( backing );
333       }
334       {
335         Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
336         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
337         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
338         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
339         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
340         text.SetParentOrigin( ParentOrigin::CENTER );
341         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
342         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
343         backing.Add( text );
344         table.Add( backing );
345       }
346       {
347         Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
348         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
349         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
350         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
351         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
352         text.SetParentOrigin( ParentOrigin::CENTER );
353         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
354         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
355         backing.Add( text );
356         table.Add( backing );
357       }
358
359       mPopup.Add( table );
360
361       StagePopup( mPopup );
362     }
363     else if( button.GetName() == TABLEVIEW_BUTTON_FIXED2_ID )
364     {
365       mPopup = CreatePopup();
366       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
367       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
368
369       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
370       table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
371       table.SetFixedHeight( 0, 50.0f );
372       table.SetFixedHeight( 2, 50.0f );
373
374       {
375         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
376         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
377         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
378         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
379         text.SetAnchorPoint( AnchorPoint::CENTER );
380         text.SetParentOrigin( ParentOrigin::CENTER );
381         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
382         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
383         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
384
385         backing.Add( text );
386         table.Add( backing );
387       }
388       {
389         Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
390         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
391         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
392         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
393         text.SetAnchorPoint( AnchorPoint::CENTER );
394         text.SetParentOrigin( ParentOrigin::CENTER );
395         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
396         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
397         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
398
399         backing.Add( text );
400         table.Add( backing );
401       }
402       {
403         Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
404         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
405         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
406         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
407         text.SetAnchorPoint( AnchorPoint::CENTER );
408         text.SetParentOrigin( ParentOrigin::CENTER );
409         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
410         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
411         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
412
413         backing.Add( text );
414         table.Add( backing );
415       }
416
417       mPopup.Add( table );
418
419       StagePopup( mPopup );
420     }
421     else if( button.GetName() == TABLEVIEW_BUTTON_FIT1_ID )
422     {
423       mPopup = CreatePopup();
424       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
425       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
426
427       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
428       table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
429       table.SetFitHeight( 0 );
430       table.SetFitHeight( 2 );
431
432       {
433         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
434         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
435         backing.SetSize( 0.0f, 100.0f );
436
437         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
438         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
439         text.SetAnchorPoint( AnchorPoint::CENTER );
440         text.SetParentOrigin( ParentOrigin::CENTER );
441         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
442         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
443         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
444
445         backing.Add( text );
446
447         table.Add( backing );
448       }
449       {
450         Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
451         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
452
453         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
454         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
455         text.SetAnchorPoint( AnchorPoint::CENTER );
456         text.SetParentOrigin( ParentOrigin::CENTER );
457         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
458         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
459         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
460
461         backing.Add( text );
462
463         table.Add( backing );
464       }
465       {
466         Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
467         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
468         backing.SetSize( 0.0f, 100.0f );
469
470         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
471         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
472         text.SetAnchorPoint( AnchorPoint::CENTER );
473         text.SetParentOrigin( ParentOrigin::CENTER );
474         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
475         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
476         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
477
478         backing.Add( text );
479
480         table.Add( backing );
481       }
482
483       mPopup.Add( table );
484
485       StagePopup( mPopup );
486     }
487     else if( button.GetName() == TABLEVIEW_BUTTON_FIT2_ID )
488     {
489       mPopup = CreatePopup();
490       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
491       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
492
493       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
494       table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
495       table.SetFitHeight( 1 );
496
497       {
498         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
499         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
500
501         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
502         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
503         text.SetAnchorPoint( AnchorPoint::CENTER );
504         text.SetParentOrigin( ParentOrigin::CENTER );
505         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
506         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
507         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
508
509         backing.Add( text );
510
511         table.Add( backing );
512       }
513       {
514         Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
515         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
516         backing.SetSize( 0.0f, 200.0f );
517
518         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
519         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
520         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
521         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
522         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
523
524         text.SetAnchorPoint( AnchorPoint::CENTER );
525         text.SetParentOrigin( ParentOrigin::CENTER );
526         backing.Add( text );
527
528         table.Add( backing );
529       }
530       {
531         Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
532         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
533
534         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
535         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
536         text.SetAnchorPoint( AnchorPoint::CENTER );
537         text.SetParentOrigin( ParentOrigin::CENTER );
538         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
539         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
540         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
541
542         backing.Add( text );
543
544         table.Add( backing );
545       }
546
547       mPopup.Add( table );
548
549       StagePopup( mPopup );
550     }
551     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL1_ID )
552     {
553       mPopup = CreatePopup();
554       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
555       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
556       mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
557
558       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
559       table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
560       table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
561       table.SetFitHeight( 0 );
562       table.SetFitHeight( 1 );
563       table.SetFitHeight( 2 );
564
565       {
566         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
567         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
568         backing.SetSize( 0.0f, 100.0f );
569
570         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
571         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
572         text.SetAnchorPoint( AnchorPoint::CENTER );
573         text.SetParentOrigin( ParentOrigin::CENTER );
574         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
575         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
576         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
577
578         backing.Add( text );
579
580         table.Add( backing );
581       }
582       {
583         Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
584         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
585         backing.SetSize( 0.0f, 200.0f );
586
587         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
588         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
589         text.SetAnchorPoint( AnchorPoint::CENTER );
590         text.SetParentOrigin( ParentOrigin::CENTER );
591         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
592         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
593         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
594
595         backing.Add( text );
596
597         table.Add( backing );
598       }
599       {
600         Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
601         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
602         backing.SetSize( 0.0f, 300.0f );
603
604         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
605         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
606         text.SetAnchorPoint( AnchorPoint::CENTER );
607         text.SetParentOrigin( ParentOrigin::CENTER );
608         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
609         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
610         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
611
612         backing.Add( text );
613
614         table.Add( backing );
615       }
616
617       mPopup.Add( table );
618
619       StagePopup( mPopup );
620     }
621     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL2_ID )
622     {
623       mPopup = CreatePopup();
624       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
625       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
626       mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
627
628       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
629       table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
630       table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
631       table.SetFitHeight( 0 );
632       table.SetFitHeight( 1 );
633
634       {
635         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
636         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
637         backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
638         backing.SetSize( 0.0f, 100.0f );
639
640         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
641         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
642         text.SetAnchorPoint( AnchorPoint::CENTER );
643         text.SetParentOrigin( ParentOrigin::CENTER );
644         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
645         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
646         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
647
648         backing.Add( text );
649
650         table.Add( backing );
651       }
652       {
653         Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
654         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
655         backing.SetSize( 0.0f, 200.0f );
656
657         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
658         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
659         text.SetAnchorPoint( AnchorPoint::CENTER );
660         text.SetParentOrigin( ParentOrigin::CENTER );
661         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
662         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
663         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
664
665         backing.Add( text );
666
667         table.Add( backing );
668       }
669
670       mPopup.Add( table );
671
672       StagePopup( mPopup );
673     }
674     else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL3_ID )
675     {
676       mPopup = CreatePopup();
677       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
678       mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
679       mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
680
681       Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
682       table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
683       table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
684       table.SetFixedHeight( 0, 20.0f );
685       table.SetFitHeight( 1 );
686
687       {
688         Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
689         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
690
691         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
692         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
693         text.SetAnchorPoint( AnchorPoint::CENTER );
694         text.SetParentOrigin( ParentOrigin::CENTER );
695         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
696         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
697         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
698
699         backing.Add( text );
700
701         table.Add( backing );
702       }
703       {
704         Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
705         backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
706         backing.SetSize( 0.0f, 200.0f );
707
708         Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
709         text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
710         text.SetAnchorPoint( AnchorPoint::CENTER );
711         text.SetParentOrigin( ParentOrigin::CENTER );
712         text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
713         text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
714         text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
715
716         backing.Add( text );
717
718         table.Add( backing );
719       }
720       mPopup.Add( table );
721
722       StagePopup( mPopup );
723     }
724     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID )
725     {
726       mPopup = CreatePopup();
727       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
728       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
729
730       Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE );
731       image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
732
733       mPopup.Add( image );
734
735       StagePopup( mPopup );
736     }
737     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FIT_ID )
738     {
739       mPopup = CreatePopup();
740       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
741       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
742
743       Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE );
744       image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
745       image.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
746
747       mPopup.Add( image );
748
749       StagePopup( mPopup );
750     }
751     else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FILL_ID )
752     {
753       mPopup = CreatePopup();
754       mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
755       mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
756
757       Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE );
758       image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
759       image.SetSizeScalePolicy( SizeScalePolicy::FILL_WITH_ASPECT_RATIO );
760
761       mPopup.Add( image );
762
763       StagePopup( mPopup );
764     }
765
766     return true;
767   }
768
769   void OnKeyEvent( const KeyEvent& event )
770   {
771     if( event.state == KeyEvent::Down )
772     {
773       if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
774       {
775         // Exit application when click back or escape.
776         mApplication.Quit();
777       }
778     }
779   }
780
781 public: // From ItemFactory
782
783   /**
784    * @brief Return the number of items to display in the item view
785    *
786    * @return Return the number of items to display
787    */
788   virtual unsigned int GetNumberOfItems()
789   {
790     return TABLEVIEW_BUTTON_ITEMS_COUNT;
791   }
792
793   /**
794    * @brief Create a new item to populate the item view with
795    *
796    * @param[in] itemId The index of the item to create
797    * @return Return the created actor for the given ID
798    */
799   virtual Actor NewItem(unsigned int itemId)
800   {
801     Toolkit::PushButton popupButton = Toolkit::PushButton::New();
802     popupButton.SetName( TABLEVIEW_BUTTON_ITEMS[ itemId ].name );
803     popupButton.SetLabelText( TABLEVIEW_BUTTON_ITEMS[ itemId ].text );
804     popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
805
806     popupButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
807
808     return popupButton;
809   }
810
811 private:
812
813   Application&       mApplication;
814   Toolkit::Control   mView;                  ///< The View instance.
815   Toolkit::ToolBar   mToolBar;               ///< The View's Toolbar.
816   Layer              mContentLayer;          ///< Content layer.
817
818   Toolkit::TextLabel mTitleActor;            ///< Title text.
819   Toolkit::Popup     mMenu;                  ///< The navigation menu.
820   Toolkit::Popup     mPopup;                 ///< The current example popup.
821
822   Toolkit::ItemView  mItemView;              ///< ItemView to hold test images.
823
824 };
825
826 void RunTest( Application& application )
827 {
828   SizeNegotiationController test( application );
829
830   application.MainLoop();
831 }
832
833 // Entry point for Linux & SLP applications
834 int DALI_EXPORT_API main( int argc, char **argv )
835 {
836   Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
837
838   RunTest( application );
839
840   return 0;
841 }