Fix for TextLabel demo styling
[platform/core/uifw/dali-demo.git] / examples / buttons / buttons-example.cpp
index af075b5..66e2293 100644 (file)
@@ -15,7 +15,7 @@
  *
  */
 
-#include "../shared/view.h"
+#include "shared/view.h"
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 
@@ -61,8 +61,8 @@ const char* const PUSHBUTTON_PRESS_IMAGE = DALI_IMAGE_DIR "button-down.9.png";
 const char* const PUSHBUTTON_DISABLED_IMAGE = DALI_IMAGE_DIR "button-disabled.9.png";
 const char* const PUSHBUTTON_BUTTON_IMAGE = DALI_IMAGE_DIR "button-up.9.png";
 
-const char* const CHECKBOX_UNCHECKED_IMAGE = DALI_IMAGE_DIR "checkbox-unchecked.png";
-const char* const CHECKBOX_CHECKED_IMAGE = DALI_IMAGE_DIR "checkbox-checked.png";
+const char* const CHECKBOX_UNSELECTED_IMAGE = DALI_IMAGE_DIR "checkbox-unselected.png";
+const char* const CHECKBOX_SELECTED_IMAGE = DALI_IMAGE_DIR "checkbox-selected.png";
 
 const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f );
 
@@ -108,6 +108,8 @@ class ButtonsController: public ConnectionTracker
   {
     // The Init signal is received once (only) during the Application lifetime
 
+    DemoHelper::RequestThemeChange();
+
     // Respond to key events
     Stage::GetCurrent().KeyEventSignal().Connect(this, &ButtonsController::OnKeyEvent);
 
@@ -127,14 +129,16 @@ class ButtonsController: public ConnectionTracker
     radioGroup2Background.SetAnchorPoint( AnchorPoint::TOP_LEFT );
     radioGroup2Background.SetParentOrigin( ParentOrigin::TOP_LEFT );
     radioGroup2Background.SetPosition( DP(MARGIN_SIZE), DP(yPos) );
-    radioGroup2Background.SetSize( DP(348), DP(GROUP2_HEIGHT) );
+    radioGroup2Background.SetRelayoutEnabled( true );
+    radioGroup2Background.SetPreferredSize( Vector2( DP(348), DP(GROUP2_HEIGHT) ) );
     mContentLayer.Add( radioGroup2Background );
 
     Actor radioButtonsGroup2 = Actor::New();
     radioButtonsGroup2.SetParentOrigin( ParentOrigin::TOP_LEFT );
     radioButtonsGroup2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
     radioButtonsGroup2.SetPosition( DP(MARGIN_SIZE), DP(MARGIN_SIZE) );
-    radioButtonsGroup2.SetSize( DP(100), DP(160) );
+    radioButtonsGroup2.SetRelayoutEnabled( true );
+    radioButtonsGroup2.SetPreferredSize( Vector2( DP(100), DP(160) ) );
 
     radioGroup2Background.Add( radioButtonsGroup2 );
 
@@ -142,8 +146,8 @@ class ButtonsController: public ConnectionTracker
 
     // Radio 1
     {
-      ImageActor imageActor = ImageActor::New( Image::New( SMALL_IMAGE_1 ) );
-      imageActor.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) );
+      ImageActor imageActor = ImageActor::New( ResourceImage::New( SMALL_IMAGE_1 ) );
+      imageActor.SetPreferredSize( Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) );
       mRadioButtonImage1 = Dali::Toolkit::RadioButton::New( imageActor );
       mRadioButtonImage1.SetParentOrigin( ParentOrigin::TOP_LEFT );
       mRadioButtonImage1.SetAnchorPoint( AnchorPoint::TOP_LEFT );
@@ -157,8 +161,8 @@ class ButtonsController: public ConnectionTracker
     {
       radioY += RADIO_LABEL_THUMBNAIL_SIZE + RADIO_IMAGE_SPACING;
 
-      ImageActor imageActor = ImageActor::New( Image::New( SMALL_IMAGE_2 ) );
-      imageActor.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) );
+      ImageActor imageActor = ImageActor::New( ResourceImage::New( SMALL_IMAGE_2 ) );
+      imageActor.SetPreferredSize( Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) );
 
       mRadioButtonImage2 = Dali::Toolkit::RadioButton::New( imageActor );
       mRadioButtonImage2.SetParentOrigin( ParentOrigin::TOP_LEFT );
@@ -172,8 +176,8 @@ class ButtonsController: public ConnectionTracker
     {
       radioY += RADIO_LABEL_THUMBNAIL_SIZE + RADIO_IMAGE_SPACING;
 
-      ImageActor imageActor = ImageActor::New( Image::New( SMALL_IMAGE_3 ) );
-      imageActor.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) );
+      ImageActor imageActor = ImageActor::New( ResourceImage::New( SMALL_IMAGE_3 ) );
+      imageActor.SetPreferredSize( Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) );
 
       mRadioButtonImage3 = Dali::Toolkit::RadioButton::New( imageActor );
       mRadioButtonImage3.SetParentOrigin( ParentOrigin::TOP_LEFT );
@@ -188,27 +192,27 @@ class ButtonsController: public ConnectionTracker
     mUpdateButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
     mUpdateButton.SetAnchorPoint( AnchorPoint::TOP_CENTER );
     mUpdateButton.SetPosition( 0, DP(MARGIN_SIZE) );
-    mUpdateButton.SetLabel("Select");
-    mUpdateButton.SetSize( DP(100), DP(BUTTON_HEIGHT) );
+    mUpdateButton.SetLabel( "Select" );
+    mUpdateButton.SetPreferredSize( Vector2( DP(100), DP(BUTTON_HEIGHT) ) );
 
-    mUpdateButton.SetSelectedImage( Dali::Image::New( PUSHBUTTON_PRESS_IMAGE ) );
-    mUpdateButton.SetDisabledImage( Dali::Image::New( PUSHBUTTON_DISABLED_IMAGE ) );
-    mUpdateButton.SetButtonImage( Dali::Image::New( PUSHBUTTON_BUTTON_IMAGE ) );
+    mUpdateButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
+    mUpdateButton.SetDisabledImage( Dali::ResourceImage::New( PUSHBUTTON_DISABLED_IMAGE ) );
+    mUpdateButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
 
     mUpdateButton.ClickedSignal().Connect( this, &ButtonsController::OnButtonClicked );
 
     radioButtonsGroup2.Add(mUpdateButton);
 
     // ImageActor to display selected image
-    mBigImage1 = Image::New( BIG_IMAGE_1 );
-    mBigImage2 = Image::New( BIG_IMAGE_2 );
-    mBigImage3 = Image::New( BIG_IMAGE_3 );
+    mBigImage1 = ResourceImage::New( BIG_IMAGE_1 );
+    mBigImage2 = ResourceImage::New( BIG_IMAGE_2 );
+    mBigImage3 = ResourceImage::New( BIG_IMAGE_3 );
 
     mImage = ImageActor::New( mBigImage1 );
     mImage.SetParentOrigin( ParentOrigin::TOP_RIGHT );
     mImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
     mImage.SetPosition( DP(MARGIN_SIZE), 0 );
-    mImage.SetSize( DP(218), DP(218) );
+    mImage.SetPreferredSize( Vector2( DP(218), DP(218) ) );
     radioButtonsGroup2.Add( mImage );
 
     // The enable/disable radio group
@@ -218,7 +222,8 @@ class ButtonsController: public ConnectionTracker
     radioGroup1Background.SetAnchorPoint( AnchorPoint::TOP_LEFT );
     radioGroup1Background.SetParentOrigin( ParentOrigin::TOP_LEFT );
     radioGroup1Background.SetPosition( DP(MARGIN_SIZE), DP(yPos) );
-    radioGroup1Background.SetSize( DP(348), DP(GROUP1_HEIGHT) );
+    radioGroup1Background.SetRelayoutEnabled( true );
+    radioGroup1Background.SetPreferredSize( Vector2( DP(348), DP(GROUP1_HEIGHT) ) );
     mContentLayer.Add( radioGroup1Background );
 
     // Radio group
@@ -232,12 +237,17 @@ class ButtonsController: public ConnectionTracker
     // First radio button
     {
       Toolkit::TableView tableView = Toolkit::TableView::New( 1, 2 );
-      tableView.SetSize( DP(260), DP(RADIO_LABEL_THUMBNAIL_SIZE) );
+      tableView.SetPreferredSize( Vector2( DP(260), 0.0f ) );
+      tableView.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
+
+      Toolkit::TextLabel textLabel = Toolkit::TextLabel::New( "Select enabled" );
+      tableView.AddChild( textLabel, Toolkit::TableView::CellPosition( 0, 0 ) );
 
-      ImageActor imageActor = ImageActor::New( Image::New( ENABLED_IMAGE ) );
-      imageActor.SetSize( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) );
+      ImageActor imageActor = ImageActor::New( ResourceImage::New( ENABLED_IMAGE ) );
+      imageActor.SetPreferredSize( Vector2( DP(RADIO_LABEL_THUMBNAIL_SIZE), DP(RADIO_LABEL_THUMBNAIL_SIZE) ) );
+      imageActor.SetResizePolicy( FIXED, ALL_DIMENSIONS );
+      imageActor.SetPadding( Padding( DP(20.0f), 0.0f, 0.0f, 0.0f ) );
       tableView.AddChild( imageActor, Toolkit::TableView::CellPosition( 0, 1 ) );
-      tableView.SetFixedWidth( 1, DP(RADIO_LABEL_THUMBNAIL_SIZE) );
 
       Toolkit::RadioButton radioButton = Dali::Toolkit::RadioButton::New( tableView );
       radioButton.SetName( "radio-select-enable" );
@@ -246,7 +256,7 @@ class ButtonsController: public ConnectionTracker
       radioButton.SetPosition( 0, 0 );
       radioButton.SetSelected( true );
 
-      radioButton.StateChangedSignal().Connect( this, &ButtonsController::EnableSelectButtonToggle );
+      radioButton.StateChangedSignal().Connect( this, &ButtonsController::EnableSelectButton );
 
       radioButtonsGroup1.Add( radioButton );
     }
@@ -259,7 +269,7 @@ class ButtonsController: public ConnectionTracker
       radioButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
       radioButton.SetPosition( 0, DP(50) );
 
-      radioButton.StateChangedSignal().Connect( this, &ButtonsController::EnableSelectButtonToggle );
+      radioButton.StateChangedSignal().Connect( this, &ButtonsController::EnableSelectButton );
 
       radioButtonsGroup1.Add( radioButton );
     }
@@ -271,11 +281,12 @@ class ButtonsController: public ConnectionTracker
     checkBoxBackground.SetAnchorPoint( AnchorPoint::TOP_LEFT );
     checkBoxBackground.SetParentOrigin( ParentOrigin::TOP_LEFT );
     checkBoxBackground.SetPosition( DP(MARGIN_SIZE), DP(yPos) );
-    checkBoxBackground.SetSize( DP(430), DP(GROUP3_HEIGHT) );
+    checkBoxBackground.SetRelayoutEnabled( true );
+    checkBoxBackground.SetPreferredSize( Vector2( DP(430), DP(GROUP3_HEIGHT) ) );
     mContentLayer.Add( checkBoxBackground );
 
-    Dali::Image unchecked = Dali::Image::New( CHECKBOX_UNCHECKED_IMAGE );
-    Dali::Image checked = Dali::Image::New( CHECKBOX_CHECKED_IMAGE );
+    Dali::Image unselected = Dali::ResourceImage::New( CHECKBOX_UNSELECTED_IMAGE );
+    Dali::Image selected = Dali::ResourceImage::New( CHECKBOX_SELECTED_IMAGE );
 
     int checkYPos = MARGIN_SIZE;
 
@@ -285,10 +296,10 @@ class ButtonsController: public ConnectionTracker
       checkBox.SetPosition( DP(MARGIN_SIZE), DP(checkYPos) );
       checkBox.SetParentOrigin( ParentOrigin::TOP_LEFT );
       checkBox.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-      checkBox.SetBackgroundImage( unchecked );
-      checkBox.SetCheckedImage( checked );
-      checkBox.SetSize( DP(48), DP(48) );
-      checkBox.StateChangedSignal().Connect( this, &ButtonsController::OnCheckBoxesToggled );
+      checkBox.SetBackgroundImage( unselected );
+      checkBox.SetSelectedImage( selected );
+      checkBox.SetLabel( "CheckBox1 is unselected" );
+      checkBox.StateChangedSignal().Connect( this, &ButtonsController::OnCheckBoxesSelected );
 
       checkBoxBackground.Add( checkBox );
     }
@@ -300,11 +311,11 @@ class ButtonsController: public ConnectionTracker
       checkBox.SetName( "checkbox2" );
       checkBox.SetPosition( DP(MARGIN_SIZE), DP(checkYPos) );
       checkBox.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-      checkBox.SetBackgroundImage( unchecked );
-      checkBox.SetCheckedImage( checked );
-      checkBox.SetSize( DP(48), DP(48) );
-      checkBox.SetChecked( true );
-      checkBox.StateChangedSignal().Connect( this, &ButtonsController::OnCheckBoxesToggled );
+      checkBox.SetBackgroundImage( unselected );
+      checkBox.SetSelectedImage( selected );
+      checkBox.SetLabel( "CheckBox2 is selected" );
+      checkBox.SetSelected( true );
+      checkBox.StateChangedSignal().Connect( this, &ButtonsController::OnCheckBoxesSelected );
 
       checkBoxBackground.Add( checkBox );
     }
@@ -316,37 +327,38 @@ class ButtonsController: public ConnectionTracker
       checkBox.SetName( "checkbox3" );
       checkBox.SetPosition( DP(MARGIN_SIZE), DP(checkYPos) );
       checkBox.SetAnchorPoint( AnchorPoint::TOP_LEFT );
-      checkBox.SetBackgroundImage( unchecked );
-      checkBox.SetCheckedImage( checked );
-      checkBox.SetSize( DP(48), DP(48) );
-      checkBox.StateChangedSignal().Connect( this, &ButtonsController::OnCheckBoxesToggled );
+      checkBox.SetBackgroundImage( unselected );
+      checkBox.SetSelectedImage( selected );
+      checkBox.SetLabel( "CheckBox3 is unselected" );
+      checkBox.StateChangedSignal().Connect( this, &ButtonsController::OnCheckBoxesSelected );
 
       checkBoxBackground.Add( checkBox );
     }
 
-    // Create toggle button
+    // Create togglabe button
     yPos += GROUP3_HEIGHT + MARGIN_SIZE;
 
     Actor toggleBackground = Toolkit::CreateSolidColorActor( BACKGROUND_COLOUR );
     toggleBackground.SetAnchorPoint( AnchorPoint::TOP_LEFT );
     toggleBackground.SetParentOrigin( ParentOrigin::TOP_LEFT );
     toggleBackground.SetPosition( DP(MARGIN_SIZE), DP(yPos) );
-    toggleBackground.SetSize( DP(150 + MARGIN_SIZE * 2), DP(GROUP4_HEIGHT) );
+    toggleBackground.SetRelayoutEnabled( true );
+    toggleBackground.SetPreferredSize( Vector2( DP(150 + MARGIN_SIZE * 2), DP(GROUP4_HEIGHT) ) );
     mContentLayer.Add( toggleBackground );
 
     Toolkit::PushButton toggleButton = Toolkit::PushButton::New();
-    toggleButton.SetToggleButton( true );
+    toggleButton.SetTogglableButton( true );
     toggleButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
     toggleButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
     toggleButton.SetPosition( DP(MARGIN_SIZE), DP(MARGIN_SIZE) );
-    toggleButton.SetLabel( "Toggle OFF" );
-    toggleButton.SetSize( DP(150), DP(BUTTON_HEIGHT) );
+    toggleButton.SetLabel( "Unselected" );
+    toggleButton.SetPreferredSize( Vector2( DP(150), DP(BUTTON_HEIGHT) ) );
 
-    toggleButton.SetSelectedImage( Dali::Image::New( PUSHBUTTON_PRESS_IMAGE ) );
-    toggleButton.SetDisabledImage( Dali::Image::New( PUSHBUTTON_DISABLED_IMAGE ) );
-    toggleButton.SetButtonImage( Dali::Image::New( PUSHBUTTON_BUTTON_IMAGE ) );
+    toggleButton.SetSelectedImage( Dali::ResourceImage::New( PUSHBUTTON_PRESS_IMAGE ) );
+    toggleButton.SetDisabledImage( Dali::ResourceImage::New( PUSHBUTTON_DISABLED_IMAGE ) );
+    toggleButton.SetButtonImage( Dali::ResourceImage::New( PUSHBUTTON_BUTTON_IMAGE ) );
 
-    toggleButton.StateChangedSignal().Connect( this, &ButtonsController::OnButtonToggled );
+    toggleButton.StateChangedSignal().Connect( this, &ButtonsController::OnButtonSelected );
 
     toggleBackground.Add( toggleButton );
   }
@@ -363,31 +375,31 @@ class ButtonsController: public ConnectionTracker
     }
   }
 
-  bool OnButtonToggled( Toolkit::Button button, bool state )
+  bool OnButtonSelected( Toolkit::Button button )
   {
     Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast( button );
     if( pushButton )
     {
-      if( state )
+      if( button.IsSelected() )
       {
-        pushButton.SetLabel( "Toggle ON" );
+        pushButton.SetLabel( "Selected" );
       }
       else
       {
-        pushButton.SetLabel( "Toggle OFF" );
+        pushButton.SetLabel( "Unselected" );
       }
     }
 
     return true;
   }
 
-  bool EnableSelectButtonToggle( Toolkit::Button button, bool state )
+  bool EnableSelectButton( Toolkit::Button button )
   {
-    if( button.GetName() == "radio-select-enable" && state == true )
+    if( button.GetName() == "radio-select-enable" && button.IsSelected() == true )
     {
       mUpdateButton.SetDisabled( false );
     }
-    else if( button.GetName() == "radio-select-disable" && state == true )
+    else if( button.GetName() == "radio-select-disable" && button.IsSelected() == true )
     {
       mUpdateButton.SetDisabled( true );
     }
@@ -412,8 +424,44 @@ class ButtonsController: public ConnectionTracker
     return true;
   }
 
-  bool OnCheckBoxesToggled( Toolkit::Button button, bool state )
+  bool OnCheckBoxesSelected( Toolkit::Button button )
   {
+    if( button.GetName() == "checkbox1" )
+    {
+      if( button.IsSelected() )
+      {
+        button.SetLabel("CheckBox1 is selected");
+      }
+      else
+      {
+        button.SetLabel("CheckBox1 is unselected");
+      }
+    }
+
+    if( button.GetName() == "checkbox2" )
+    {
+      if( button.IsSelected() )
+      {
+        button.SetLabel("CheckBox2 is selected");
+      }
+      else
+      {
+        button.SetLabel("CheckBox2 is unselected");
+      }
+    }
+
+    if( button.GetName() == "checkbox3" )
+    {
+      if( button.IsSelected() )
+      {
+        button.SetLabel("CheckBox3 is selected");
+      }
+      else
+      {
+        button.SetLabel("CheckBox3 is unselected");
+      }
+    }
+
     return true;
   }
 
@@ -443,7 +491,7 @@ void RunTest( Application& application )
   application.MainLoop();
 }
 
-// Entry point for Linux & SLP applications
+// Entry point for Linux & Tizen applications
 //
 int main( int argc, char **argv )
 {