[dali_1.0.52] Merge branch 'devel/master'
[platform/core/uifw/dali-demo.git] / examples / text-field / text-field-example.cpp
index 3de4caf..d392e2e 100644 (file)
@@ -38,6 +38,7 @@ namespace
 {
 
   const char* const FOLDER_ICON_IMAGE = DALI_IMAGE_DIR "folder_appicon_empty_bg.png";
+  const char* const FOLDER_OPEN_ICON_IMAGE = DALI_IMAGE_DIR "folder_appicon_empty_open_bg.png";
 
   const float BORDER_WIDTH = 4.0f;
 
@@ -82,13 +83,12 @@ public:
   PushButton CreateFolderButton()
   {
     PushButton button = PushButton::New();
-    ResourceImage image = ResourceImage::New( FOLDER_ICON_IMAGE );
-    ImageActor folderButton = ImageActor::New( image );
-    folderButton.SetColor( Color::WHITE );
-    button.SetButtonImage( folderButton );
+    button.SetUnselectedImage( FOLDER_ICON_IMAGE );
+    button.SetSelectedImage( FOLDER_OPEN_ICON_IMAGE );
     button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
     button.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
-    button.SetSize( image.GetWidth(), image.GetHeight() );
+    ResourceImage imageClosed = ResourceImage::New( FOLDER_ICON_IMAGE );
+    button.SetSize( imageClosed.GetWidth(), imageClosed.GetHeight() );
 
     return button;
   }
@@ -98,12 +98,15 @@ public:
     Stage stage = Stage::GetCurrent();
     Vector2 stageSize = stage.GetSize();
 
+    // Remove previously hidden pop-up
+    UnparentAndReset(mPopup);
+
     // Launch a pop-up containing TextField
     mField = CreateTextField( stageSize, mButtonLabel );
     mPopup = CreatePopup( stageSize.width * 0.8f );
     mPopup.Add( mField );
     mPopup.OutsideTouchedSignal().Connect( this, &TextFieldExample::OnPopupOutsideTouched );
-    mPopup.Show();
+    mPopup.SetDisplayState( Popup::SHOWN );
 
     return true;
   }
@@ -111,6 +114,7 @@ public:
   TextField CreateTextField( const Vector2& stageSize, const std::string& text )
   {
     TextField field = TextField::New();
+    field.SetName("text-field");
     field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
     field.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
     field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
@@ -129,7 +133,6 @@ public:
     popup.SetParentOrigin( ParentOrigin::CENTER );
     popup.SetAnchorPoint( AnchorPoint::CENTER );
     popup.SetSize( width, 0.0f );
-    popup.HideTail();
     popup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT );
     popup.SetSizeModeFactor( POPUP_SIZE_FACTOR_TO_PARENT );
     popup.TouchedSignal().Connect( this, &TextFieldExample::OnPopupTouched );
@@ -144,16 +147,15 @@ public:
     {
       Property::Value text = mField.GetProperty( TextField::Property::TEXT );
       mButtonLabel = text.Get< std::string >();
-      mButton.SetLabel( mButtonLabel );
+      mButton.SetLabelText( mButtonLabel );
     }
 
     // Hide & discard the pop-up
     if( mPopup )
     {
-      mPopup.Hide();
+      mPopup.SetDisplayState( Popup::HIDDEN );
     }
     mField.Reset();
-    mPopup.Reset();
   }
 
   bool OnPopupTouched( Actor actor, const TouchEvent& event )
@@ -171,7 +173,7 @@ public:
           {
             Property::Value text = mField.GetProperty( TextField::Property::TEXT );
             mButtonLabel = text.Get< std::string >();
-            mButton.SetLabel( mButtonLabel );
+            mButton.SetLabelText( mButtonLabel );
             mField.ClearKeyInputFocus();
           }
           break;
@@ -223,7 +225,8 @@ void RunTest( Application& application )
 /** Entry point for Linux & Tizen applications */
 int main( int argc, char **argv )
 {
-  Application application = Application::New( &argc, &argv, DALI_DEMO_THEME_PATH );
+  // DALI_DEMO_THEME_PATH not passed to Application so TextField example uses default Toolkit style sheet.
+  Application application = Application::New( &argc, &argv );
 
   RunTest( application );