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