2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "shared/view.h"
19 #include <dali/dali.h>
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali-toolkit/devel-api/controls/popup/popup.h>
22 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
26 using Dali::Toolkit::TextLabel;
37 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg";
38 const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";
39 const char* const IMAGE = DEMO_IMAGE_DIR "background-magnifier.jpg";
41 const char* const TOOLBAR_TITLE = "Negotiate Size";
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";
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" },
74 const unsigned int TABLEVIEW_BUTTON_ITEMS_COUNT = sizeof( TABLEVIEW_BUTTON_ITEMS ) / sizeof( TABLEVIEW_BUTTON_ITEMS[0] );
77 Actor CreateSolidColor( Vector4 color )
79 Toolkit::Control control = Toolkit::Control::New();
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 );
89 } // anonymous namespace
93 * This example shows the usage of size negotiation.
95 class SizeNegotiationController: public ConnectionTracker, public Toolkit::ItemFactory
99 SizeNegotiationController( Application& application )
100 : mApplication( application )
102 // Connect to the Application's Init signal
103 mApplication.InitSignal().Connect( this, &SizeNegotiationController::Create );
106 ~SizeNegotiationController()
108 // Nothing to do here
111 void Create( Application& application )
113 // The Init signal is received once (only) during the Application lifetime
114 Stage stage = Stage::GetCurrent();
116 // Respond to key events if not handled
117 Toolkit::KeyInputFocusManager keyInputFocusManager = Toolkit::KeyInputFocusManager::Get();
118 if( keyInputFocusManager )
120 keyInputFocusManager.UnhandledKeyEventSignal().Connect(this, &SizeNegotiationController::OnKeyEvent);
123 // Creates a default view with a default tool bar.
124 // The view is added to the stage.
125 mContentLayer = DemoHelper::CreateView( application,
132 mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" );
133 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE );
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 ) );
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 );
144 // Use a grid layout for tests
145 Vector2 stageSize = stage.GetSize();
146 Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
148 gridLayout->GetItemSize( 0, Vector3( stageSize ), itemSize );
149 itemSize.height = stageSize.y / 10;
150 gridLayout->SetItemSize( itemSize );
151 mItemView.AddLayout( *gridLayout );
153 mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
155 mContentLayer.Add( mItemView );
158 void StagePopup( Toolkit::Popup popup )
160 Stage::GetCurrent().Add( popup );
161 popup.SetDisplayState( Toolkit::Popup::SHOWN );
164 void OnPopupOutsideTouched()
168 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
181 Toolkit::Popup CreatePopup()
183 Stage stage = Stage::GetCurrent();
184 const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
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 );
193 popup.OutsideTouchedSignal().Connect( this, &SizeNegotiationController::OnPopupOutsideTouched );
194 popup.HiddenSignal().Connect( this, &SizeNegotiationController::PopupHidden );
199 bool OnButtonClicked( Toolkit::Button button )
201 if( button.GetName() == TABLEVIEW_BUTTON_1CELL_ID )
203 mPopup = CreatePopup();
204 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
205 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
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 );
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 );
217 StagePopup( mPopup );
219 else if( button.GetName() == TABLEVIEW_BUTTON_3CELL_ID )
221 mPopup = CreatePopup();
222 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
223 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
225 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
226 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
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 ) );
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 ) );
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 ) );
244 mPopup.SetContent( table );
246 StagePopup( mPopup );
248 else if( button.GetName() == TABLEVIEW_BUTTON_3X3CELL_ID )
250 mPopup = CreatePopup();
251 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
252 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
254 Toolkit::TableView table = Toolkit::TableView::New( 3, 3 );
255 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
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 ) );
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 ) );
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 ) );
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 ) );
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 ) );
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 ) );
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 ) );
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 ) );
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 ) );
310 StagePopup( mPopup );
312 else if( button.GetName() == TABLEVIEW_BUTTON_FIXED1_ID )
314 mPopup = CreatePopup();
315 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
316 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
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 );
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" );
332 table.Add( backing );
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" );
344 table.Add( backing );
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" );
356 table.Add( backing );
361 StagePopup( mPopup );
363 else if( button.GetName() == TABLEVIEW_BUTTON_FIXED2_ID )
365 mPopup = CreatePopup();
366 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
367 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
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 );
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" );
386 table.Add( backing );
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" );
400 table.Add( backing );
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" );
414 table.Add( backing );
419 StagePopup( mPopup );
421 else if( button.GetName() == TABLEVIEW_BUTTON_FIT1_ID )
423 mPopup = CreatePopup();
424 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
425 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
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 );
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 );
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" );
447 table.Add( backing );
450 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
451 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
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" );
463 table.Add( backing );
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 );
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" );
480 table.Add( backing );
485 StagePopup( mPopup );
487 else if( button.GetName() == TABLEVIEW_BUTTON_FIT2_ID )
489 mPopup = CreatePopup();
490 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
491 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
493 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
494 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
495 table.SetFitHeight( 1 );
498 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
499 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
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" );
511 table.Add( backing );
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 );
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" );
524 text.SetAnchorPoint( AnchorPoint::CENTER );
525 text.SetParentOrigin( ParentOrigin::CENTER );
528 table.Add( backing );
531 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
532 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
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" );
544 table.Add( backing );
549 StagePopup( mPopup );
551 else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL1_ID )
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 );
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 );
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 );
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" );
580 table.Add( backing );
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 );
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" );
597 table.Add( backing );
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 );
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" );
614 table.Add( backing );
619 StagePopup( mPopup );
621 else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL2_ID )
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 );
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 );
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 );
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" );
650 table.Add( backing );
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 );
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" );
667 table.Add( backing );
672 StagePopup( mPopup );
674 else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL3_ID )
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 );
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 );
688 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
689 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
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" );
701 table.Add( backing );
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 );
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" );
718 table.Add( backing );
722 StagePopup( mPopup );
724 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID )
726 mPopup = CreatePopup();
727 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
728 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
730 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE );
731 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
735 StagePopup( mPopup );
737 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FIT_ID )
739 mPopup = CreatePopup();
740 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
741 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
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 );
749 StagePopup( mPopup );
751 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FILL_ID )
753 mPopup = CreatePopup();
754 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
755 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
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 );
763 StagePopup( mPopup );
769 void OnKeyEvent( const KeyEvent& event )
771 if( event.state == KeyEvent::Down )
773 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
775 // Exit application when click back or escape.
781 public: // From ItemFactory
784 * @brief Return the number of items to display in the item view
786 * @return Return the number of items to display
788 virtual unsigned int GetNumberOfItems()
790 return TABLEVIEW_BUTTON_ITEMS_COUNT;
794 * @brief Create a new item to populate the item view with
796 * @param[in] itemId The index of the item to create
797 * @return Return the created actor for the given ID
799 virtual Actor NewItem(unsigned int itemId)
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 );
806 popupButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
813 Application& mApplication;
814 Toolkit::Control mView; ///< The View instance.
815 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
816 Layer mContentLayer; ///< Content layer.
818 Toolkit::TextLabel mTitleActor; ///< Title text.
819 Toolkit::Popup mMenu; ///< The navigation menu.
820 Toolkit::Popup mPopup; ///< The current example popup.
822 Toolkit::ItemView mItemView; ///< ItemView to hold test images.
826 void RunTest( Application& application )
828 SizeNegotiationController test( application );
830 application.MainLoop();
833 // Entry point for Linux & SLP applications
834 int DALI_EXPORT_API main( int argc, char **argv )
836 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
838 RunTest( application );