Example #1
0
  void Create( Application& application )
  {
    // Setup precalculations for button size and start positions.
    Toolkit::PushButton button;
    int index = 0;
    Vector2 stageSize = Stage::GetCurrent().GetSize();
    float buttonSize = ( stageSize.x - ( BUTTON_GAP * ( BUTTON_COLUMNS + 1 ) ) ) / BUTTON_COLUMNS;
    float yStart = ( stageSize.y - ( ( buttonSize * BUTTON_ROWS ) + ( BUTTON_GAP * ( BUTTON_ROWS - 1 ) ) ) ) / 2.0f;

    // Create a grid of buttons.
    for( int y = 0; y < BUTTON_ROWS; ++y )
    {
      for( int x = 0; x < BUTTON_COLUMNS; ++x )
      {
        // Create a button and position it.
        button = Toolkit::PushButton::New();
        button.SetParentOrigin( ParentOrigin::TOP_LEFT );
        button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
        button.SetPosition( Vector3( BUTTON_GAP + ( x * ( buttonSize + BUTTON_GAP ) ), yStart + ( y * ( buttonSize + BUTTON_GAP ) ), 0.0f ) );
        button.SetSize( Vector3( buttonSize, buttonSize, 0) );
        button.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
        button.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );

        // Label the button with a unique value.
        std::stringstream label;
        label << index;
        button.SetLabel( label.str() );

        // Register our custom property, and use it to store a unique number.
        // Store the index to the property so we can look it up later.
        // Note: This is much faster than looking the property up by name and should always be used if possible.
        // As all our control types are the same (PushButtons) the indecies to our unique property is the same for each one.
        Property::Value tag = ( float )index;
        mTagPropertyIndex = button.RegisterProperty( TAG_PROPERTY_NAME, tag );

        // Hook a callback when the button is clicked.
        button.ClickedSignal().Connect( this, &PropertyButtonsController::OnButtonClicked );

        // Add the button to the stage.
        Stage::GetCurrent().Add( button );
        index++;
      }
    }

    // Create the last selected button text view.
    mTagText = Toolkit::TextLabel::New( "None selected" );
    mTagText.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
    mTagText.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
    mTagText.SetPosition( Vector3( 0.0f, -30.0f, 0.0f ) );
    Stage::GetCurrent().Add( mTagText );
  }