Commit b847d459f68c04ab593225aa9dfd5d7b090893b8
1 parent
65963089
Builder examples to use Navigation View
Change-Id: Ie0ef016796a0d37b3935278c2dc0977cb18c1769
Showing
1 changed file
with
48 additions
and
70 deletions
examples/builder/examples.cpp
| ... | ... | @@ -26,6 +26,8 @@ |
| 26 | 26 | #include <dali-toolkit/devel-api/builder/tree-node.h> |
| 27 | 27 | #include <dali-toolkit/devel-api/builder/json-parser.h> |
| 28 | 28 | #include <dali-toolkit/devel-api/controls/popup/popup.h> |
| 29 | +#include <dali-toolkit/devel-api/controls/navigation-view/navigation-view.h> | |
| 30 | + | |
| 29 | 31 | #include <map> |
| 30 | 32 | #include <string> |
| 31 | 33 | #include <fstream> |
| ... | ... | @@ -136,6 +138,7 @@ const std::string ShortName( const std::string& name ) |
| 136 | 138 | |
| 137 | 139 | if( pos != std::string::npos ) |
| 138 | 140 | { |
| 141 | + pos++; | |
| 139 | 142 | return name.substr( pos ); |
| 140 | 143 | } |
| 141 | 144 | else |
| ... | ... | @@ -249,44 +252,23 @@ public: |
| 249 | 252 | mTitleActor.SetProperty( TextLabel::Property::TEXT, title ); |
| 250 | 253 | } |
| 251 | 254 | |
| 252 | - bool OnToolSelectLayout( Toolkit::Button button ) | |
| 255 | + bool OnBackButtonPressed( Toolkit::Button button ) | |
| 253 | 256 | { |
| 254 | - bool on = mItemView.IsVisible(); | |
| 255 | - | |
| 256 | - if( on ) | |
| 257 | - { | |
| 258 | - LeaveSelection(); | |
| 259 | - } | |
| 260 | - else | |
| 261 | - { | |
| 262 | - EnterSelection(); | |
| 263 | - } | |
| 264 | - | |
| 257 | + OnQuitOrBack(); | |
| 265 | 258 | return true; |
| 266 | 259 | } |
| 267 | 260 | |
| 268 | - void LeaveSelection() | |
| 269 | - { | |
| 270 | - | |
| 271 | - } | |
| 272 | - | |
| 273 | - void EnterSelection() | |
| 261 | + void SetUpItemView() | |
| 274 | 262 | { |
| 275 | 263 | Stage stage = Stage::GetCurrent(); |
| 276 | - stage.SetBackgroundColor( Color::WHITE ); | |
| 277 | 264 | |
| 278 | 265 | mTapDetector = TapGestureDetector::New(); |
| 279 | 266 | mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap ); |
| 280 | 267 | |
| 281 | - if( mItemView ) | |
| 282 | - { | |
| 283 | - stage.Remove( mItemView ); | |
| 284 | - } | |
| 285 | - | |
| 286 | 268 | mFiles.clear(); |
| 287 | 269 | |
| 288 | 270 | mItemView = ItemView::New(*this); |
| 289 | - stage.Add( mItemView ); | |
| 271 | + | |
| 290 | 272 | mItemView.SetParentOrigin(ParentOrigin::CENTER); |
| 291 | 273 | mItemView.SetAnchorPoint(AnchorPoint::CENTER); |
| 292 | 274 | mLayout = DefaultItemLayout::New( DefaultItemLayout::LIST ); |
| ... | ... | @@ -354,28 +336,11 @@ public: |
| 354 | 336 | } |
| 355 | 337 | } |
| 356 | 338 | |
| 357 | - // Display item view on the stage | |
| 358 | - stage.Add( mItemView ); | |
| 359 | - | |
| 360 | - mItemView.SetVisible( true ); | |
| 361 | - mBuilderLayer.SetVisible( false ); | |
| 362 | - | |
| 363 | - SetTitle("Select"); | |
| 364 | - | |
| 365 | 339 | // Activate the layout |
| 366 | 340 | Vector3 size(stage.GetSize()); |
| 367 | 341 | mItemView.ActivateLayout(0, size, 0.0f/*immediate*/); |
| 368 | 342 | } |
| 369 | 343 | |
| 370 | - void ExitSelection() | |
| 371 | - { | |
| 372 | - mTapDetector.Reset(); | |
| 373 | - | |
| 374 | - mItemView.SetVisible( false ); | |
| 375 | - mBuilderLayer.SetVisible( true ); | |
| 376 | - | |
| 377 | - SetTitle("View"); | |
| 378 | - } | |
| 379 | 344 | |
| 380 | 345 | void OnTap( Actor actor, const TapGesture& tap ) |
| 381 | 346 | { |
| ... | ... | @@ -411,7 +376,7 @@ public: |
| 411 | 376 | Stage stage = Stage::GetCurrent(); |
| 412 | 377 | |
| 413 | 378 | builder = Builder::New(); |
| 414 | - builder.QuitSignal().Connect( this, &ExampleApp::OnBuilderQuit ); | |
| 379 | + builder.QuitSignal().Connect( this, &ExampleApp::OnQuitOrBack ); | |
| 415 | 380 | |
| 416 | 381 | Property::Map defaultDirs; |
| 417 | 382 | defaultDirs[ TOKEN_STRING(DEMO_IMAGE_DIR) ] = DEMO_IMAGE_DIR; |
| ... | ... | @@ -485,10 +450,7 @@ public: |
| 485 | 450 | size.y -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight; |
| 486 | 451 | mBuilderLayer.SetSize( size ); |
| 487 | 452 | |
| 488 | - mBuilderLayer.LowerToBottom(); | |
| 489 | - Stage::GetCurrent().GetRootLayer().RaiseToTop(); | |
| 490 | - | |
| 491 | - ExitSelection(); | |
| 453 | + mNavigationView.Push( mBuilderLayer ); | |
| 492 | 454 | } |
| 493 | 455 | |
| 494 | 456 | void Create(Application& app) |
| ... | ... | @@ -504,21 +466,43 @@ public: |
| 504 | 466 | TOOLBAR_IMAGE, |
| 505 | 467 | "" ); |
| 506 | 468 | |
| 507 | - SetTitle("Builder"); | |
| 469 | + SetTitle("Select Example"); | |
| 508 | 470 | |
| 509 | 471 | mBuilderLayer = Layer::New(); |
| 510 | - stage.GetRootLayer().Add(mBuilderLayer); | |
| 511 | - | |
| 512 | 472 | |
| 513 | 473 | // Create an edit mode button. (left of toolbar) |
| 514 | - Toolkit::PushButton editButton = Toolkit::PushButton::New(); | |
| 515 | - editButton.SetUnselectedImage( EDIT_IMAGE ); | |
| 516 | - editButton.SetSelectedImage( EDIT_IMAGE_SELECTED ); | |
| 517 | - editButton.ClickedSignal().Connect( this, &ExampleApp::OnToolSelectLayout); | |
| 518 | - editButton.SetLeaveRequired( true ); | |
| 519 | - mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); | |
| 520 | - | |
| 521 | - EnterSelection(); | |
| 474 | + Toolkit::PushButton backButton = Toolkit::PushButton::New(); | |
| 475 | + backButton.SetUnselectedImage( EDIT_IMAGE ); | |
| 476 | + backButton.SetSelectedImage( EDIT_IMAGE_SELECTED ); | |
| 477 | + backButton.ClickedSignal().Connect( this, &ExampleApp::OnBackButtonPressed); | |
| 478 | + backButton.SetLeaveRequired( true ); | |
| 479 | + mToolBar.AddControl( backButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); | |
| 480 | + | |
| 481 | + mNavigationView = Toolkit::NavigationView::New(); | |
| 482 | + mNavigationView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); | |
| 483 | + mNavigationView.SetAnchorPoint( AnchorPoint::TOP_LEFT); | |
| 484 | + | |
| 485 | + stage.Add( mNavigationView ); | |
| 486 | + | |
| 487 | + // Set up the background gradient. | |
| 488 | + Property::Array stopOffsets; | |
| 489 | + stopOffsets.PushBack( 0.0f ); | |
| 490 | + stopOffsets.PushBack( 1.0f ); | |
| 491 | + Property::Array stopColors; | |
| 492 | + stopColors.PushBack( Color::WHITE ); | |
| 493 | + stopColors.PushBack( Vector4( 0.45f, 0.70f, 0.80f, 1.0f ) ); // Medium bright, pastel blue | |
| 494 | + const float percentageStageHeight = stage.GetSize().height * 0.6f; | |
| 495 | + | |
| 496 | + mNavigationView.SetProperty( Toolkit::Control::Property::BACKGROUND, Dali::Property::Map() | |
| 497 | + .Add( Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::GRADIENT ) | |
| 498 | + .Add( Toolkit::GradientVisual::Property::STOP_OFFSET, stopOffsets ) | |
| 499 | + .Add( Toolkit::GradientVisual::Property::STOP_COLOR, stopColors ) | |
| 500 | + .Add( Toolkit::GradientVisual::Property::START_POSITION, Vector2( 0.0f, -percentageStageHeight ) ) | |
| 501 | + .Add( Toolkit::GradientVisual::Property::END_POSITION, Vector2( 0.0f, percentageStageHeight ) ) | |
| 502 | + .Add( Toolkit::GradientVisual::Property::UNITS, Toolkit::GradientVisual::Units::USER_SPACE ) ); | |
| 503 | + | |
| 504 | + SetUpItemView(); | |
| 505 | + mNavigationView.Push( mItemView ); | |
| 522 | 506 | |
| 523 | 507 | mTimer = Timer::New( 500 ); // ms |
| 524 | 508 | mTimer.TickSignal().Connect( this, &ExampleApp::OnTimer); |
| ... | ... | @@ -546,14 +530,7 @@ public: |
| 546 | 530 | { |
| 547 | 531 | if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) |
| 548 | 532 | { |
| 549 | - if ( mItemView.IsVisible() ) | |
| 550 | - { | |
| 551 | - mApp.Quit(); | |
| 552 | - } | |
| 553 | - else | |
| 554 | - { | |
| 555 | - EnterSelection(); | |
| 556 | - } | |
| 533 | + OnQuitOrBack(); | |
| 557 | 534 | } |
| 558 | 535 | } |
| 559 | 536 | } |
| ... | ... | @@ -561,15 +538,15 @@ public: |
| 561 | 538 | /** |
| 562 | 539 | * Event handler when Builder wants to quit (we only want to close the shown json unless we're at the top-level) |
| 563 | 540 | */ |
| 564 | - void OnBuilderQuit() | |
| 541 | + void OnQuitOrBack() | |
| 565 | 542 | { |
| 566 | - if ( mItemView.IsVisible() ) | |
| 543 | + if ( mItemView.OnStage() ) | |
| 567 | 544 | { |
| 568 | 545 | mApp.Quit(); |
| 569 | 546 | } |
| 570 | 547 | else |
| 571 | 548 | { |
| 572 | - EnterSelection(); | |
| 549 | + mNavigationView.Pop(); | |
| 573 | 550 | } |
| 574 | 551 | } |
| 575 | 552 | |
| ... | ... | @@ -578,12 +555,13 @@ private: |
| 578 | 555 | |
| 579 | 556 | ItemLayoutPtr mLayout; |
| 580 | 557 | ItemView mItemView; |
| 558 | + Toolkit::NavigationView mNavigationView; | |
| 581 | 559 | |
| 582 | 560 | Toolkit::Control mView; |
| 583 | 561 | unsigned int mOrientation; |
| 584 | 562 | |
| 585 | 563 | Toolkit::ToolBar mToolBar; |
| 586 | - TextLabel mTitleActor; ///< The Toolbar's Title. | |
| 564 | + TextLabel mTitleActor; | |
| 587 | 565 | |
| 588 | 566 | Layer mBuilderLayer; |
| 589 | 567 | ... | ... |