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 stage.KeyEventSignal().Connect(this, &SizeNegotiationController::OnKeyEvent);
119 // Creates a default view with a default tool bar.
120 // The view is added to the stage.
121 mContentLayer = DemoHelper::CreateView( application,
128 mTitleActor = DemoHelper::CreateToolBarLabel( "CUSTOM_TOOLBAR_TITLE" );
129 mTitleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, TOOLBAR_TITLE );
131 // Add title to the tool bar.
132 const float padding( DemoHelper::DEFAULT_VIEW_STYLE.mToolBarPadding );
133 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter, Toolkit::Alignment::Padding( padding, padding, padding, padding ) );
135 mItemView = Toolkit::ItemView::New( *this );
136 mItemView.SetParentOrigin( ParentOrigin::CENTER );
137 mItemView.SetAnchorPoint( AnchorPoint::CENTER );
138 mItemView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
140 // Use a grid layout for tests
141 Vector2 stageSize = stage.GetSize();
142 Toolkit::ItemLayoutPtr gridLayout = Toolkit::DefaultItemLayout::New( Toolkit::DefaultItemLayout::LIST );
144 gridLayout->GetItemSize( 0, Vector3( stageSize ), itemSize );
145 itemSize.height = stageSize.y / 10;
146 gridLayout->SetItemSize( itemSize );
147 mItemView.AddLayout( *gridLayout );
149 mItemView.ActivateLayout( 0, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
151 mContentLayer.Add( mItemView );
154 void StagePopup( Toolkit::Popup popup )
156 Stage::GetCurrent().Add( popup );
157 popup.SetDisplayState( Toolkit::Popup::SHOWN );
160 void OnPopupOutsideTouched()
164 mPopup.SetDisplayState( Toolkit::Popup::HIDDEN );
177 Toolkit::Popup CreatePopup()
179 Stage stage = Stage::GetCurrent();
180 const float POPUP_WIDTH_DP = stage.GetSize().width * 0.75f;
182 Toolkit::Popup popup = Toolkit::Popup::New();
183 popup.SetName( "popup" );
184 popup.SetParentOrigin( ParentOrigin::CENTER );
185 popup.SetAnchorPoint( AnchorPoint::CENTER );
186 popup.SetSize( POPUP_WIDTH_DP, 0.0f );
187 popup.SetProperty( Toolkit::Popup::Property::TAIL_VISIBILITY, false );
189 popup.OutsideTouchedSignal().Connect( this, &SizeNegotiationController::OnPopupOutsideTouched );
190 popup.HiddenSignal().Connect( this, &SizeNegotiationController::PopupHidden );
195 bool OnButtonClicked( Toolkit::Button button )
197 if( button.GetName() == TABLEVIEW_BUTTON_1CELL_ID )
199 mPopup = CreatePopup();
200 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
201 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
203 Toolkit::TableView table = Toolkit::TableView::New( 0, 0 );
204 table.SetName( "TABLEVIEW_BUTTON_1CELL_ID" );
205 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
207 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
208 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
209 table.Add( backing );
213 StagePopup( mPopup );
215 else if( button.GetName() == TABLEVIEW_BUTTON_3CELL_ID )
217 mPopup = CreatePopup();
218 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
219 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
221 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
222 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
225 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
226 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
227 table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) );
230 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
231 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
232 table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) );
235 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
236 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
237 table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) );
240 mPopup.SetContent( table );
242 StagePopup( mPopup );
244 else if( button.GetName() == TABLEVIEW_BUTTON_3X3CELL_ID )
246 mPopup = CreatePopup();
247 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
248 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
250 Toolkit::TableView table = Toolkit::TableView::New( 3, 3 );
251 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
255 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
256 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
257 table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 0 ) );
260 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
261 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
262 table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 0 ) );
265 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
266 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
267 table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 0 ) );
272 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
273 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
274 table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 1 ) );
277 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
278 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
279 table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 1 ) );
282 Actor backing = CreateSolidColor( Vector4( 0.0f, 0.0f, 1.0f, 1.0f ) );
283 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
284 table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 1 ) );
289 Actor backing = CreateSolidColor( Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) );
290 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
291 table.AddChild( backing, Toolkit::TableView::CellPosition( 0, 2 ) );
294 Actor backing = CreateSolidColor( Vector4( 0.5f, 0.5f, 0.5f, 1.0f ) );
295 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
296 table.AddChild( backing, Toolkit::TableView::CellPosition( 1, 2 ) );
299 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.5f, 0.0f, 1.0f ) );
300 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
301 table.AddChild( backing, Toolkit::TableView::CellPosition( 2, 2 ) );
306 StagePopup( mPopup );
308 else if( button.GetName() == TABLEVIEW_BUTTON_FIXED1_ID )
310 mPopup = CreatePopup();
311 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
312 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
314 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
315 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
316 table.SetFixedHeight( 0, 50.0f );
319 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
320 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
321 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
322 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
323 text.SetParentOrigin( ParentOrigin::CENTER );
324 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
325 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
326 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
328 table.Add( backing );
331 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
332 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
333 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
334 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
335 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
336 text.SetParentOrigin( ParentOrigin::CENTER );
337 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
338 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
340 table.Add( backing );
343 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
344 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
345 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
346 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
347 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
348 text.SetParentOrigin( ParentOrigin::CENTER );
349 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
350 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
352 table.Add( backing );
357 StagePopup( mPopup );
359 else if( button.GetName() == TABLEVIEW_BUTTON_FIXED2_ID )
361 mPopup = CreatePopup();
362 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
363 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
365 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
366 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
367 table.SetFixedHeight( 0, 50.0f );
368 table.SetFixedHeight( 2, 50.0f );
371 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
372 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
373 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
374 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
375 text.SetAnchorPoint( AnchorPoint::CENTER );
376 text.SetParentOrigin( ParentOrigin::CENTER );
377 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
378 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
379 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
382 table.Add( backing );
385 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
386 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
387 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
388 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
389 text.SetAnchorPoint( AnchorPoint::CENTER );
390 text.SetParentOrigin( ParentOrigin::CENTER );
391 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
392 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
393 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
396 table.Add( backing );
399 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
400 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
401 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
402 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
403 text.SetAnchorPoint( AnchorPoint::CENTER );
404 text.SetParentOrigin( ParentOrigin::CENTER );
405 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
406 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
407 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
410 table.Add( backing );
415 StagePopup( mPopup );
417 else if( button.GetName() == TABLEVIEW_BUTTON_FIT1_ID )
419 mPopup = CreatePopup();
420 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
421 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
423 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
424 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
425 table.SetFitHeight( 0 );
426 table.SetFitHeight( 2 );
429 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
430 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
431 backing.SetSize( 0.0f, 100.0f );
433 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
434 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
435 text.SetAnchorPoint( AnchorPoint::CENTER );
436 text.SetParentOrigin( ParentOrigin::CENTER );
437 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
438 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
439 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
443 table.Add( backing );
446 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
447 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
449 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
450 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
451 text.SetAnchorPoint( AnchorPoint::CENTER );
452 text.SetParentOrigin( ParentOrigin::CENTER );
453 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
454 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
455 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
459 table.Add( backing );
462 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
463 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
464 backing.SetSize( 0.0f, 100.0f );
466 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
467 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
468 text.SetAnchorPoint( AnchorPoint::CENTER );
469 text.SetParentOrigin( ParentOrigin::CENTER );
470 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
471 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
472 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
476 table.Add( backing );
481 StagePopup( mPopup );
483 else if( button.GetName() == TABLEVIEW_BUTTON_FIT2_ID )
485 mPopup = CreatePopup();
486 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
487 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
489 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
490 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
491 table.SetFitHeight( 1 );
494 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
495 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
497 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
498 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
499 text.SetAnchorPoint( AnchorPoint::CENTER );
500 text.SetParentOrigin( ParentOrigin::CENTER );
501 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
502 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
503 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
507 table.Add( backing );
510 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
511 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
512 backing.SetSize( 0.0f, 200.0f );
514 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
515 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
516 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
517 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
518 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
520 text.SetAnchorPoint( AnchorPoint::CENTER );
521 text.SetParentOrigin( ParentOrigin::CENTER );
524 table.Add( backing );
527 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
528 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
530 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fill" );
531 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
532 text.SetAnchorPoint( AnchorPoint::CENTER );
533 text.SetParentOrigin( ParentOrigin::CENTER );
534 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
535 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
536 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
540 table.Add( backing );
545 StagePopup( mPopup );
547 else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL1_ID )
549 mPopup = CreatePopup();
550 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
551 mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
552 mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
554 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
555 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
556 table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
557 table.SetFitHeight( 0 );
558 table.SetFitHeight( 1 );
559 table.SetFitHeight( 2 );
562 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
563 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
564 backing.SetSize( 0.0f, 100.0f );
566 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
567 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
568 text.SetAnchorPoint( AnchorPoint::CENTER );
569 text.SetParentOrigin( ParentOrigin::CENTER );
570 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
571 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
572 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
576 table.Add( backing );
579 Actor backing = CreateSolidColor( Vector4( 1.0f, 1.0f, 0.0f, 1.0f ) );
580 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
581 backing.SetSize( 0.0f, 200.0f );
583 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
584 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
585 text.SetAnchorPoint( AnchorPoint::CENTER );
586 text.SetParentOrigin( ParentOrigin::CENTER );
587 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
588 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
589 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
593 table.Add( backing );
596 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
597 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
598 backing.SetSize( 0.0f, 300.0f );
600 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
601 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
602 text.SetAnchorPoint( AnchorPoint::CENTER );
603 text.SetParentOrigin( ParentOrigin::CENTER );
604 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
605 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
606 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
610 table.Add( backing );
615 StagePopup( mPopup );
617 else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL2_ID )
619 mPopup = CreatePopup();
620 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
621 mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
622 mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
624 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
625 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
626 table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
627 table.SetFitHeight( 0 );
628 table.SetFitHeight( 1 );
631 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
632 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
633 backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::HEIGHT );
634 backing.SetSize( 0.0f, 100.0f );
636 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
637 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
638 text.SetAnchorPoint( AnchorPoint::CENTER );
639 text.SetParentOrigin( ParentOrigin::CENTER );
640 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
641 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
642 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
646 table.Add( backing );
649 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
650 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
651 backing.SetSize( 0.0f, 200.0f );
653 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
654 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
655 text.SetAnchorPoint( AnchorPoint::CENTER );
656 text.SetParentOrigin( ParentOrigin::CENTER );
657 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
658 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
659 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
663 table.Add( backing );
668 StagePopup( mPopup );
670 else if( button.GetName() == TABLEVIEW_BUTTON_NATURAL3_ID )
672 mPopup = CreatePopup();
673 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
674 mPopup.SetSizeModeFactor( Vector3( 0.75f, 1.0f, 1.0f ) );
675 mPopup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
677 Toolkit::TableView table = Toolkit::TableView::New( 3, 1 );
678 table.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
679 table.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
680 table.SetFixedHeight( 0, 20.0f );
681 table.SetFitHeight( 1 );
684 Actor backing = CreateSolidColor( Vector4( 1.0f, 0.0f, 0.0f, 1.0f ) );
685 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
687 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fixed" );
688 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
689 text.SetAnchorPoint( AnchorPoint::CENTER );
690 text.SetParentOrigin( ParentOrigin::CENTER );
691 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
692 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
693 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
697 table.Add( backing );
700 Actor backing = CreateSolidColor( Vector4( 0.0f, 1.0f, 0.0f, 1.0f ) );
701 backing.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
702 backing.SetSize( 0.0f, 200.0f );
704 Toolkit::TextLabel text = Toolkit::TextLabel::New( "Fit" );
705 text.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::WHITE );
706 text.SetAnchorPoint( AnchorPoint::CENTER );
707 text.SetParentOrigin( ParentOrigin::CENTER );
708 text.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
709 text.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
710 text.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
714 table.Add( backing );
718 StagePopup( mPopup );
720 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_SCALE_ID )
722 mPopup = CreatePopup();
723 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
724 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
726 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE );
727 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
731 StagePopup( mPopup );
733 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FIT_ID )
735 mPopup = CreatePopup();
736 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
737 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
739 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE );
740 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
741 image.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
745 StagePopup( mPopup );
747 else if( button.GetName() == POPUP_BUTTON_CONTENT_IMAGE_FILL_ID )
749 mPopup = CreatePopup();
750 mPopup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
751 mPopup.SetSizeModeFactor( Vector3( 0.75f, 0.5f, 1.0f ) );
753 Toolkit::ImageView image = Toolkit::ImageView::New( IMAGE );
754 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
755 image.SetSizeScalePolicy( SizeScalePolicy::FILL_WITH_ASPECT_RATIO );
759 StagePopup( mPopup );
765 void OnKeyEvent( const KeyEvent& event )
767 if( event.state == KeyEvent::Down )
769 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
771 // Exit application when click back or escape.
777 public: // From ItemFactory
780 * @brief Return the number of items to display in the item view
782 * @return Return the number of items to display
784 virtual unsigned int GetNumberOfItems()
786 return TABLEVIEW_BUTTON_ITEMS_COUNT;
790 * @brief Create a new item to populate the item view with
792 * @param[in] itemId The index of the item to create
793 * @return Return the created actor for the given ID
795 virtual Actor NewItem(unsigned int itemId)
797 Toolkit::PushButton popupButton = Toolkit::PushButton::New();
798 popupButton.SetName( TABLEVIEW_BUTTON_ITEMS[ itemId ].name );
799 popupButton.SetProperty( Toolkit::Button::Property::LABEL, TABLEVIEW_BUTTON_ITEMS[ itemId ].text );
800 popupButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
802 popupButton.ClickedSignal().Connect( this, &SizeNegotiationController::OnButtonClicked );
809 Application& mApplication;
810 Toolkit::Control mView; ///< The View instance.
811 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
812 Layer mContentLayer; ///< Content layer.
814 Toolkit::TextLabel mTitleActor; ///< Title text.
815 Toolkit::Popup mMenu; ///< The navigation menu.
816 Toolkit::Popup mPopup; ///< The current example popup.
818 Toolkit::ItemView mItemView; ///< ItemView to hold test images.
822 void RunTest( Application& application )
824 SizeNegotiationController test( application );
826 application.MainLoop();
829 // Entry point for Linux & SLP applications
830 int DALI_EXPORT_API main( int argc, char **argv )
832 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
834 RunTest( application );