[dali_1.4.15] Merge branch 'devel/master'
[platform/core/uifw/dali-demo.git] / examples / simple-text-field / simple-text-field.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 /**
19  * @file simple-text-field-example.cpp
20  * @brief Very basic usage of TextField control
21  */
22
23 // EXTERNAL INCLUDES
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <iostream>
26
27 using namespace Dali;
28 using namespace Dali::Toolkit;
29
30
31 /**
32  * @brief The main class of the demo.
33  */
34 class SimpleTextFieldExample : public ConnectionTracker
35 {
36 public:
37
38   SimpleTextFieldExample( Application& application )
39   : mApplication( application )
40   {
41     // Connect to the Application's Init signal
42     mApplication.InitSignal().Connect( this, &SimpleTextFieldExample::Create );
43   }
44
45   ~SimpleTextFieldExample()
46   {
47     // Nothing to do here.
48   }
49
50   /**
51    * One-time setup in response to Application InitSignal.
52    */
53   void Create( Application& application )
54   {
55     Stage stage = Stage::GetCurrent();
56     stage.SetBackgroundColor( Vector4( 0.04f, 0.345f, 0.392f, 1.0f ) );
57
58     TextField field = TextField::New();
59     field.SetParentOrigin( ParentOrigin::CENTER );
60     field.SetSize( 300.f, 60.f );
61     field.SetBackgroundColor( Color::WHITE );
62     field.SetBackgroundColor( Vector4( 1.f, 1.f, 1.f, 0.15f ) );
63
64     field.SetProperty( TextField::Property::TEXT_COLOR, Color::BLACK );
65     field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder" );
66     field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name." );
67
68     stage.Add( field );
69   }
70
71 private:
72
73   Application& mApplication;
74 };
75
76 void RunTest( Application& application )
77 {
78   SimpleTextFieldExample test( application );
79
80   application.MainLoop();
81 }
82
83 /** Entry point for Linux & Tizen applications */
84 int main( int argc, char **argv )
85 {
86   // DALI_DEMO_THEME_PATH not passed to Application so TextField example uses default Toolkit style sheet.
87   Application application = Application::New( &argc, &argv );
88
89   RunTest( application );
90
91   return 0;
92 }