Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-demo.git] / examples / text-label / text-label-example.cpp
1 /*
2  * Copyright (c) 2015 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 text-label-example.cpp
20  * @brief Basic usage of TextLabel control
21  */
22
23 // EXTERNAL INCLUDES
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali/public-api/text-abstraction/text-abstraction.h>
26
27 // INTERNAL INCLUDES
28 #include "center-layout.h"
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32
33 /**
34  * @brief The main class of the demo.
35  */
36 class TextLabelExample : public ConnectionTracker
37 {
38 public:
39
40   TextLabelExample( Application& application )
41   : mApplication( application )
42   {
43     // Connect to the Application's Init signal
44     mApplication.InitSignal().Connect( this, &TextLabelExample::Create );
45   }
46
47   ~TextLabelExample()
48   {
49     // Nothing to do here.
50   }
51
52   /**
53    * One-time setup in response to Application InitSignal.
54    */
55   void Create( Application& application )
56   {
57     Stage stage = Stage::GetCurrent();
58
59     stage.SetBackgroundColor( Color::BLUE );
60     stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
61     Vector2 stageSize = stage.GetSize();
62
63     CenterLayout centerLayout = CenterLayout::New();
64     centerLayout.SetParentOrigin( ParentOrigin::CENTER );
65     centerLayout.SetSize( stageSize.width*0.6f, stageSize.width*0.6f );
66     stage.Add( centerLayout );
67
68     TextLabel label = TextLabel::New();
69     label.SetBackgroundColor( Color::BLACK );
70     centerLayout.Add( label );
71
72     label.SetProperty( TextLabel::PROPERTY_MULTI_LINE, true );
73     label.SetProperty( TextLabel::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
74
75     // TODO
76     //Property::Value labelText = label.GetProperty( TextLabel::PROPERTY_TEXT );
77     //std::cout << "Got text from label: " << labelText.Get< std::string >() << std::endl;
78   }
79
80   /**
81    * Main key event handler
82    */
83   void OnKeyEvent(const KeyEvent& event)
84   {
85     if(event.state == KeyEvent::Down)
86     {
87       if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
88       {
89         mApplication.Quit();
90       }
91     }
92   }
93
94 private:
95
96   Application& mApplication;
97 };
98
99 void RunTest( Application& application )
100 {
101   TextLabelExample test( application );
102
103   application.MainLoop();
104 }
105
106 /** Entry point for Linux & Tizen applications */
107 int main( int argc, char **argv )
108 {
109   Application application = Application::New( &argc, &argv );
110
111   RunTest( application );
112
113   return 0;
114 }