Further Setter/Getter public API removal from Dali::Actor
[platform/core/uifw/dali-demo.git] / examples / simple-text-label / simple-text-label-example.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-label-example.cpp
20  * @brief Basic usage of SimpleTextLabel control
21  */
22
23 // EXTERNAL INCLUDES
24 #include <dali-toolkit/dali-toolkit.h>
25
26 using namespace Dali;
27 using namespace Dali::Toolkit;
28
29 /**
30  * @brief The main class of the demo.
31  */
32 class SimpleTextLabelExample : public ConnectionTracker
33 {
34 public:
35
36   SimpleTextLabelExample( Application& application )
37   : mApplication( application )
38   {
39     // Connect to the Application's Init signal
40     mApplication.InitSignal().Connect( this, &SimpleTextLabelExample::Create );
41   }
42
43   ~SimpleTextLabelExample()
44   {
45     // Nothing to do here.
46   }
47
48   /**
49    * One-time setup in response to Application InitSignal.
50    */
51   void Create( Application& application )
52   {
53     Stage stage = Stage::GetCurrent();
54
55     stage.KeyEventSignal().Connect(this, &SimpleTextLabelExample::OnKeyEvent);
56
57     mLabel = TextLabel::New( "A Quick Brown Fox Jumps Over The Lazy Dog" );
58     mLabel.SetProperty( Dali::Actor::Property::NAME, "SimpleTextLabel" );
59     mLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
60     mLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
61     mLabel.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 400.f ) );
62     mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
63     mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLACK );
64     mLabel.SetBackgroundColor( Color::WHITE );
65
66     stage.Add( mLabel );
67   }
68
69   /**
70    * Main key event handler
71    */
72   void OnKeyEvent(const KeyEvent& event)
73   {
74     if(event.state == KeyEvent::Down)
75     {
76       if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
77       {
78         mApplication.Quit();
79       }
80     }
81   }
82
83 private:
84
85   Application& mApplication;
86
87   TextLabel mLabel;
88 };
89
90 void RunTest( Application& application )
91 {
92   SimpleTextLabelExample test( application );
93
94   application.MainLoop();
95 }
96
97 /** Entry point for Linux & Tizen applications */
98 int DALI_EXPORT_API main( int argc, char **argv )
99 {
100   Application application = Application::New( &argc, &argv );
101
102   RunTest( application );
103
104   return 0;
105 }