Revert "Revert "Renamed KeyEvent enum values to comply with coding standards.""
[platform/core/uifw/dali-demo.git] / examples / simple-text-visual / simple-text-visual-example.cpp
1 /*
2  * Copyright (c) 2020 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-visual-example.cpp
20  * @brief Basic usage of Text Visual.
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 TextVisualExample : public ConnectionTracker
33 {
34 public:
35
36   TextVisualExample( Application& application )
37   : mApplication( application )
38   {
39     // Connect to the Application's Init signal
40     mApplication.InitSignal().Connect( this, &TextVisualExample::Create );
41   }
42
43   ~TextVisualExample()
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     Window window = application.GetWindow();
54
55     window.KeyEventSignal().Connect(this, &TextVisualExample::OnKeyEvent);
56     window.SetBackgroundColor( Color::WHITE );
57
58     Dali::Toolkit::Control control = Dali::Toolkit::ImageView::New();
59     control.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
60
61     const std::string markupText( "<color value='blue'><font size='50'>H</font></color>ello <color value='blue'><font size='50'>w</font></color>orld" );
62
63     Dali::Property::Map map;
64     map.Add( Dali::Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::TEXT ).
65       Add( Dali::Toolkit::TextVisual::Property::ENABLE_MARKUP, true ).
66       Add( Dali::Toolkit::TextVisual::Property::TEXT, markupText ).
67       Add( Dali::Toolkit::TextVisual::Property::TEXT_COLOR, Dali::Vector4( 0.25f, 0.25f, 0.5f, 1.f ) ).
68       Add( Dali::Toolkit::TextVisual::Property::FONT_FAMILY, "TizenSansRegular" ).
69       Add( Dali::Toolkit::TextVisual::Property::POINT_SIZE, 30.f ).
70       Add( Dali::Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, "END" ).
71       Add( Dali::Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, "CENTER" );
72
73     control.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map );
74
75     window.Add( control );
76   }
77
78   /**
79    * Main key event handler
80    */
81   void OnKeyEvent(const KeyEvent& event)
82   {
83     if(event.GetState() == KeyEvent::DOWN)
84     {
85       if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
86       {
87         mApplication.Quit();
88       }
89     }
90   }
91
92 private:
93
94   Application& mApplication;
95
96   TextLabel mLabel;
97 };
98
99 void RunTest( Application& application )
100 {
101   TextVisualExample test( application );
102
103   application.MainLoop();
104 }
105
106 /** Entry point for Linux & Tizen applications */
107 int DALI_EXPORT_API main( int argc, char **argv )
108 {
109   Application application = Application::New( &argc, &argv );
110
111   RunTest( application );
112
113   return 0;
114 }