Use Window instead of Stage
[platform/core/uifw/dali-demo.git] / examples / text-editor / text-editor-example.cpp
index af02cd8..4fb9fc9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/controls/table-view/table-view.h>
 #include <sstream>
 
 // INTERNAL INCLUDES
@@ -38,10 +39,10 @@ const Vector4 BACKGROUND_COLOR( 0.04f, 0.345f, 0.392f, 1.0f );      ///< The bac
 const char*   TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";         ///< The tool-bar image.
 const float   TOOLBAR_BUTTON_PERCENTAGE = 0.1f;                     ///< The button's space width as a percentage of the toolbar's width.
 const float   TOOLBAR_TITLE_PERCENTAGE = 0.7f;                      ///< The title's width as a percentage of the toolbar's width.
-const float   TOOLBAR_HEIGHT_PERCENTAGE = 0.05f;                    ///< The toolbar's height as a percentage of the stage's height.
+const float   TOOLBAR_HEIGHT_PERCENTAGE = 0.05f;                    ///< The toolbar's height as a percentage of the window's height.
 const float   TOOLBAR_PADDING = 4.f;                                ///< The padding in pixels.
 const float   BUTTON_PERCENTAGE = 0.8f;                             ///< The button's height as a percentage of the space for the buttons in the toolbar.
-const Vector3 TEXT_EDITOR_RELATIVE_SIZE( 1.f, 0.45f, 1.0f );        ///< The size of the text editor as a percentage of the stage's size.
+const Vector3 TEXT_EDITOR_RELATIVE_SIZE( 0.9f, 0.5f, 1.0f );        ///< The size of the text editor as a percentage of the window's size.
 const Vector4 TEXT_EDITOR_BACKGROUND_COLOR( 1.f, 1.f, 1.f, 0.15f ); ///< The background color of the text editor.
 
 const Vector4 COLORS[] = { Color::RED,
@@ -79,22 +80,22 @@ public:
    */
   void Create( Application& application )
   {
-    Stage stage = Stage::GetCurrent();
+    Window window = application.GetWindow();
 
     // Respond to key events
-    stage.KeyEventSignal().Connect(this, &TextEditorExample::OnKeyEvent);
+    window.KeyEventSignal().Connect(this, &TextEditorExample::OnKeyEvent);
 
     // Set a background color.
-    stage.SetBackgroundColor( BACKGROUND_COLOR );
+    window.SetBackgroundColor( BACKGROUND_COLOR );
 
-    // The stage size.
-    const Vector2 stageSize = stage.GetSize();
+    // The window size.
+    const Vector2 windowSize = window.GetSize();
 
     // Creates a default view with a default tool bar.
-    // The view is added to the stage.
+    // The view is added to the window.
 
     // Set the toolbar style
-    const float toolBarHeight = TOOLBAR_HEIGHT_PERCENTAGE * stageSize.height;
+    const float toolBarHeight = TOOLBAR_HEIGHT_PERCENTAGE * windowSize.height;
     const DemoHelper::ViewStyle viewStyle( TOOLBAR_BUTTON_PERCENTAGE,
                                            TOOLBAR_TITLE_PERCENTAGE,
                                            toolBarHeight,
@@ -119,11 +120,11 @@ public:
     mColorContainer = Control::New();
     mColorContainer.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::WIDTH );
     mColorContainer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT );
-    mColorContainer.SetSizeModeFactor( Vector3( 0.0f, BUTTON_PERCENTAGE, 0.0f ) );
+    mColorContainer.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.0f, BUTTON_PERCENTAGE, 0.0f ) );
 
     // Place to right of parent.
-    mColorContainer.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
-    mColorContainer.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
+    mColorContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER_RIGHT );
+    mColorContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER_LEFT );
     colorLabel.Add( mColorContainer );
 
     // Add border to highlight harder-to-see colors.
@@ -136,9 +137,9 @@ public:
     // Create a 'select color' button.
     mColorButtonOption = Toolkit::PushButton::New();
     mColorButtonOption.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    mColorButtonOption.SetSizeModeFactor( Vector3( 0.9f, 0.9f, 0.0f ) ); // Smaller than container to show border.
-    mColorButtonOption.SetParentOrigin( ParentOrigin::CENTER );
-    mColorButtonOption.SetAnchorPoint( AnchorPoint::CENTER );
+    mColorButtonOption.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 0.9f, 0.9f, 0.0f ) ); // Smaller than container to show border.
+    mColorButtonOption.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
+    mColorButtonOption.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
 
     SetButtonColor( mColorButtonOption, Color::BLACK );
 
@@ -150,15 +151,15 @@ public:
 
     // Create the text editor.
     mEditor = TextEditor::New();
-    mEditor.SetParentOrigin( ParentOrigin::TOP_CENTER );
-    mEditor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-    mEditor.SetPosition( 0.f, toolBarHeight, 0.f );
+    mEditor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
+    mEditor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+    mEditor.SetProperty( Actor::Property::POSITION, Vector3( 0.f, toolBarHeight * 2.0f, 0.f ));
     mEditor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    mEditor.SetSizeModeFactor( TEXT_EDITOR_RELATIVE_SIZE );
+    mEditor.SetProperty( Actor::Property::SIZE_MODE_FACTOR, TEXT_EDITOR_RELATIVE_SIZE );
 
     mEditor.SetBackgroundColor( TEXT_EDITOR_BACKGROUND_COLOR );
 
-    const Size boundingBoxSize( stageSize * TEXT_EDITOR_RELATIVE_SIZE.GetVectorXY() );
+    const Size boundingBoxSize( windowSize * TEXT_EDITOR_RELATIVE_SIZE.GetVectorXY() );
     Rect<int> boundingBox( 0,
                            static_cast<int>( toolBarHeight ),
                            static_cast<int>( boundingBoxSize.width ),
@@ -190,12 +191,12 @@ public:
   {
     mButtonContainer = Toolkit::TableView::New( NUMBER_OF_COLORS, 1u );
     mButtonContainer.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
-    mButtonContainer.SetSizeModeFactor( Vector3( 1.0f, NUMBER_OF_COLORS, 1.0f ) );
+    mButtonContainer.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( 1.0f, NUMBER_OF_COLORS, 1.0f ) );
 
     // Place below color selection button.
-    mButtonContainer.SetParentOrigin( ParentOrigin::BOTTOM_CENTER  );
-    mButtonContainer.SetAnchorPoint( AnchorPoint::TOP_CENTER );
-    mButtonContainer.SetPosition( 0.0f, 2.f * TOOLBAR_PADDING, 0.f );
+    mButtonContainer.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER  );
+    mButtonContainer.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
+    mButtonContainer.SetProperty( Actor::Property::POSITION, Vector3( 0.0f, 2.f * TOOLBAR_PADDING, 0.f ));
     mColorContainer.Add( mButtonContainer );
 
     const Vector3 buttonPercentage( 1.f, 0.8f / static_cast<float>( NUMBER_OF_COLORS ), 1.f );
@@ -203,11 +204,11 @@ public:
     {
       Toolkit::PushButton button = Toolkit::PushButton::New();
       button.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
-      button.SetSizeModeFactor( buttonPercentage );
+      button.SetProperty( Actor::Property::SIZE_MODE_FACTOR, buttonPercentage );
 
       std::ostringstream s;
       s << "color" << index;
-      button.SetName( s.str() );
+      button.SetProperty( Dali::Actor::Property::NAME, s.str() );
 
       SetButtonColor( button, COLORS[index] );
 
@@ -236,14 +237,14 @@ public:
       CreateButtonContainer();
     }
 
-    mButtonContainer.SetVisible( true );
-    mButtonContainer.SetSensitive( true );
+    mButtonContainer.SetProperty( Actor::Property::VISIBLE, true );
+    mButtonContainer.SetProperty( Actor::Property::SENSITIVE, true );
     return true;
   }
 
   bool OnColorButtonClicked( Button button )
   {
-    const std::string& name = button.GetName();
+    const std::string& name = button.GetProperty< std::string >( Dali::Actor::Property::NAME );
 
     Vector4 color;
     if( "color" == name.substr( 0u, 5u ) )
@@ -255,8 +256,8 @@ public:
 
     SetButtonColor( mColorButtonOption, color  );
 
-    mButtonContainer.SetVisible( false );
-    mButtonContainer.SetSensitive( false );
+    mButtonContainer.SetProperty( Actor::Property::VISIBLE, false );
+    mButtonContainer.SetProperty( Actor::Property::SENSITIVE, false );
 
     return true;
   }