2 * Copyright (c) 2020 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/controls/table-view/table-view.h>
23 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
27 using Dali::Toolkit::TextLabel;
38 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg";
39 const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";
40 const char* const IMAGE = DEMO_IMAGE_DIR "background-magnifier.jpg";
42 const char* const TOOLBAR_TITLE = "Negotiate Size";
44 // This example contains size negotiation tests for TableView and Popup.
45 const char* const TABLEVIEW_BUTTON_1CELL_ID = "TABLEVIEW_BUTTON_1CELL";
46 const char* const TABLEVIEW_BUTTON_3CELL_ID = "TABLEVIEW_BUTTON_3CELL";
47 const char* const TABLEVIEW_BUTTON_3X3CELL_ID = "TABLEVIEW_BUTTON_3X3CELL";
48 const char* const TABLEVIEW_BUTTON_FIXED1_ID = "TABLEVIEW_BUTTON_FIXED1";
49 const char* const TABLEVIEW_BUTTON_FIXED2_ID = "TABLEVIEW_BUTTON_FIXED2";
50 const char* const TABLEVIEW_BUTTON_FIT1_ID = "TABLEVIEW_BUTTON_FIT1";
51 const char* const TABLEVIEW_BUTTON_FIT2_ID = "TABLEVIEW_BUTTON_FIT2";
52 const char* const TABLEVIEW_BUTTON_NATURAL1_ID = "TABLEVIEW_BUTTON_NATURAL1";
53 const char* const TABLEVIEW_BUTTON_NATURAL2_ID = "TABLEVIEW_BUTTON_NATURAL2";
54 const char* const TABLEVIEW_BUTTON_NATURAL3_ID = "TABLEVIEW_BUTTON_NATURAL3";
55 const char* const POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID = "POPUP_BUTTON_CONTENT_IMAGE_SCALE";
56 const char* const POPUP_BUTTON_CONTENT_IMAGE_FIT_ID = "POPUP_BUTTON_CONTENT_IMAGE_FIT";
57 const char* const POPUP_BUTTON_CONTENT_IMAGE_FILL_ID = "POPUP_BUTTON_CONTENT_IMAGE_FILL";
59 const ButtonItem TABLEVIEW_BUTTON_ITEMS[] = {
60 { TABLEVIEW_BUTTON_1CELL_ID, "1 Cell" },
61 { TABLEVIEW_BUTTON_3CELL_ID, "3 Cell" },
62 { TABLEVIEW_BUTTON_3X3CELL_ID, "3x3 Cells" },
63 { TABLEVIEW_BUTTON_FIXED1_ID, "Fixed 1" },
64 { TABLEVIEW_BUTTON_FIXED2_ID, "Fixed 2" },
65 { TABLEVIEW_BUTTON_FIT1_ID, "Fit Top Bottom" },
66 { TABLEVIEW_BUTTON_FIT2_ID, "Fit Middle" },
67 { TABLEVIEW_BUTTON_NATURAL1_ID, "Natural 1" },
68 { TABLEVIEW_BUTTON_NATURAL2_ID, "Natural 2" },
69 { TABLEVIEW_BUTTON_NATURAL3_ID, "Natural 3" },
70 { POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID, "Image Scale" },
71 { POPUP_BUTTON_CONTENT_IMAGE_FIT_ID, "Image Fit" },
72 { POPUP_BUTTON_CONTENT_IMAGE_FILL_ID, "Image Fill" },
75 const unsigned int TABLEVIEW_BUTTON_ITEMS_COUNT = sizeof( TABLEVIEW_BUTTON_ITEMS ) / sizeof( TABLEVIEW_BUTTON_ITEMS[0] );
78 Actor CreateSolidColor( Vector4 color )
80 Toolkit::Control control = Toolkit::Control::New();
83 map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR;
84 map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color;
85 control.SetProperty( Toolkit::Control::Property::BACKGROUND, map );
90 } // anonymous namespace
94 * This example shows the usage of size negotiation.
96 class SizeNegotiationController: public ConnectionTracker, public Toolkit::ItemFactory
100 SizeNegotiationController( Application& application )
101 : mApplication( application )
103 // Connect to the Application's Init signal
104 mApplication.InitSignal().Connect( this, &SizeNegotiationController::Create );
107 ~SizeNegotiationController()
109 // Nothing to do here
112 void Create( Application& application )
114 // The Init signal is received once (only) during the Application lifetime
115 Window window = application.GetWindow();
117 // Respond to key events if not handled
118 window.KeyEventSignal().Connect(this, &SizeNegotiationController::OnKeyEvent);
120 // Creates a default view with a default tool bar.
121 // The view is added to the window.
122 mContentLayer = DemoHelper::CreateView( application,
129 mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" );
130 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE );
132 // Add title to the tool bar.
133 const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding );
134 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
136 mItemView = Toolkit::ItemView::New( *this );
137 mItemView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
138 mItemView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
139 mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
141 // Use a grid layout for tests
142 Vector2 windowSize = window.GetSize();
143 Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
145 gridLayout->GetItemSize( 0, Vector3( windowSize ), itemSize );
146 itemSize.height = windowSize.y / 10;
147 gridLayout->SetItemSize( itemSize );
148 mItemView.AddLayout( *gridLayout );
150 mItemView.ActivateLayout( 0, Vector3(windowSize.x, windowSize.y, windowSize.x), 0.0f );
152 mContentLayer.Add( mItemView );
155 void ShowPopup( Toolkit::Popup popup )
157 mApplication.GetWindow().Add( popup );
158 popup.SetDisplayState( Toolkit::Popup::SHOWN );
161 void OnPopupOutsideTouched()
165 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
178 Toolkit::Popup CreatePopup()
180 Window window = mApplication.GetWindow();
181 const float POPUP_WIDTH_DP = window.GetSize().GetWidth() * 0.75f;
183 Toolkit::Popup popup = Toolkit::Popup::New();
184 popup.SetProperty( Dali::Actor::Property::NAME, "popup" );
185 popup.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
186 popup.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
187 popup.SetProperty( Actor::Property::SIZE, Vector2( POPUP_WIDTH_DP, 0.0f ) );
188 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
190 popup.OutsideTouchedSignal().Connect( this, &SizeNegotiationController::OnPopupOutsideTouched );
191 popup.HiddenSignal().Connect( this, &SizeNegotiationController::PopupHidden );
196 bool OnButtonClicked( Toolkit::Button button )
198 if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_1CELL_ID )
200 mPopup = CreatePopup();
201 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
202 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) );
204 Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
205 table.SetProperty( Dali::Actor::Property::NAME, "TABLEVIEW_BUTTON_1CELL_ID" );
206 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
208 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
209 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
210 table.Add( backing );
216 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_3CELL_ID )
218 mPopup = CreatePopup();
219 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
220 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) );
222 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
223 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
226 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
227 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
228 table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) );
231 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
232 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
233 table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) );
236 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
237 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
238 table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) );
241 mPopup.SetContent( table );
245 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_3X3CELL_ID )
247 mPopup = CreatePopup();
248 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
249 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) );
251 Toolkit::TableView table = Toolkit::TableView::New( 3, 3 );
252 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
256 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
257 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
258 table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) );
261 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
262 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
263 table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) );
266 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
267 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
268 table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) );
273 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
274 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
275 table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 1 ) );
278 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
279 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
280 table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 1 ) );
283 Actor backing = CreateSolidColor( Vector4( 0.0f, 0.0f, 1.0f, 1.0f ) );
284 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
285 table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 1 ) );
290 Actor backing = CreateSolidColor( Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) );
291 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
292 table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 2 ) );
295 Actor backing = CreateSolidColor( Vector4( 0.5f, 0.5f, 0.5f, 1.0f ) );
296 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
297 table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 2 ) );
300 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.5f, 0.0f, 1.0f ) );
301 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
302 table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 2 ) );
309 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_FIXED1_ID )
311 mPopup = CreatePopup();
312 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
313 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) );
315 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
316 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
317 table.SetFixedHeight( 0, 50.0f );
320 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
321 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
322 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
323 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
324 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
325 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
326 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
327 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
329 table.Add( backing );
332 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
333 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
334 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
335 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
336 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
337 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
338 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
339 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
341 table.Add( backing );
344 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
345 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
346 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
347 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
348 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
349 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
350 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
351 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
353 table.Add( backing );
360 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_FIXED2_ID )
362 mPopup = CreatePopup();
363 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
364 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) );
366 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
367 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
368 table.SetFixedHeight( 0, 50.0f );
369 table.SetFixedHeight( 2, 50.0f );
372 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
373 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
374 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
375 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
376 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
377 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
378 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
379 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
380 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
383 table.Add( backing );
386 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
387 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
388 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
389 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
390 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
391 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
392 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
393 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
394 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
397 table.Add( backing );
400 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
401 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
402 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
403 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
404 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
405 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
406 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
407 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
408 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
411 table.Add( backing );
418 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_FIT1_ID )
420 mPopup = CreatePopup();
421 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
422 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) );
424 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
425 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
426 table.SetFitHeight( 0 );
427 table.SetFitHeight( 2 );
430 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
431 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
432 backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 100.0f ) );
434 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
435 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
436 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
437 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
438 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
439 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
440 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
444 table.Add( backing );
447 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
448 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
450 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
451 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
452 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
453 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
454 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
455 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
456 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
460 table.Add( backing );
463 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
464 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
465 backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 100.0f ) );
467 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
468 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
469 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
470 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
471 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
472 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
473 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
477 table.Add( backing );
484 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_FIT2_ID )
486 mPopup = CreatePopup();
487 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
488 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) );
490 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
491 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
492 table.SetFitHeight( 1 );
495 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
496 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
498 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
499 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
500 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
501 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
502 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
503 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
504 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
508 table.Add( backing );
511 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
512 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
513 backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 200.0f ) );
515 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
516 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
517 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
518 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
519 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
521 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
522 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
525 table.Add( backing );
528 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
529 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
531 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
532 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
533 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
534 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
535 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
536 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
537 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
541 table.Add( backing );
548 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_NATURAL1_ID )
550 mPopup = CreatePopup();
551 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
552 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 1.0f, 1.0f ) );
553 mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
555 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
556 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
557 table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
558 table.SetFitHeight( 0 );
559 table.SetFitHeight( 1 );
560 table.SetFitHeight( 2 );
563 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
564 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
565 backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 100.0f ) );
567 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
568 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
569 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
570 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
571 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
572 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
573 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
577 table.Add( backing );
580 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
581 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
582 backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 200.0f ) );
584 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
585 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
586 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
587 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
588 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
589 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
590 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
594 table.Add( backing );
597 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
598 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
599 backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 300.0f ) );
601 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
602 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
603 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
604 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
605 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
606 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
607 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
611 table.Add( backing );
618 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_NATURAL2_ID )
620 mPopup = CreatePopup();
621 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
622 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 1.0f, 1.0f ) );
623 mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
625 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
626 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
627 table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
628 table.SetFitHeight( 0 );
629 table.SetFitHeight( 1 );
632 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
633 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
634 backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
635 backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 100.0f ) );
637 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
638 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
639 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
640 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
641 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
642 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
643 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
647 table.Add( backing );
650 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
651 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
652 backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 200.0f ) );
654 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
655 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
656 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
657 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
658 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
659 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
660 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
664 table.Add( backing );
671 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == TABLEVIEW_BUTTON_NATURAL3_ID )
673 mPopup = CreatePopup();
674 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
675 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 1.0f, 1.0f ) );
676 mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
678 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
679 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
680 table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
681 table.SetFixedHeight( 0, 20.0f );
682 table.SetFitHeight( 1 );
685 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
686 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
688 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
689 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
690 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
691 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
692 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
693 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
694 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
698 table.Add( backing );
701 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
702 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
703 backing.SetProperty( Actor::Property::SIZE, Vector2( 0.0f, 200.0f ) );
705 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
706 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
707 text.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
708 text.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
709 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
710 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
711 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
715 table.Add( backing );
721 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID )
723 mPopup = CreatePopup();
724 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
725 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) );
727 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE );
728 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
734 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CONTENT_IMAGE_FIT_ID )
736 mPopup = CreatePopup();
737 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
738 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) );
740 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE );
741 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
742 image.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
748 else if( button.GetProperty< std::string >( Dali::Actor::Property::NAME ) == POPUP_BUTTON_CONTENT_IMAGE_FILL_ID )
750 mPopup = CreatePopup();
751 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
752 mPopup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.75f, 0.5f, 1.0f ) );
754 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE );
755 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
756 image.SetProperty( Actor::Property::SIZE_SCALE_POLICY, SizeScalePolicy::FILL_WITH_ASPECT_RATIO );
766 void OnKeyEvent( const KeyEvent& event )
768 if( event.GetState() == KeyEvent::Down )
770 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
772 // Exit application when click back or escape.
778 public: // From ItemFactory
781 * @brief Return the number of items to display in the item view
783 * @return Return the number of items to display
785 virtual unsigned int GetNumberOfItems()
787 return TABLEVIEW_BUTTON_ITEMS_COUNT;
791 * @brief Create a new item to populate the item view with
793 * @param[in] itemId The index of the item to create
794 * @return Return the created actor for the given ID
796 virtual Actor NewItem(unsigned int itemId)
798 Toolkit::PushButton popupButton = Toolkit::PushButton::New();
799 popupButton.SetProperty( Dali::Actor::Property::NAME, TABLEVIEW_BUTTON_ITEMS[ itemId ].name );
800 popupButton.SetProperty( Toolkit::Button::Property::LABEL, TABLEVIEW_BUTTON_ITEMS[ itemId ].text );
801 popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
803 popupButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
810 Application& mApplication;
811 Toolkit::Control mView; ///< The View instance.
812 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
813 Layer mContentLayer; ///< Content layer.
815 Toolkit::TextLabel mTitleActor; ///< Title text.
816 Toolkit::Popup mMenu; ///< The navigation menu.
817 Toolkit::Popup mPopup; ///< The current example popup.
819 Toolkit::ItemView mItemView; ///< ItemView to hold test images.
823 int DALI_EXPORT_API main( int argc, char **argv )
825 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
826 SizeNegotiationController test( application );
827 application.MainLoop();