Updated demos to use DALi clang-format
[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   TextVisualExample(Application& application)
36   : mApplication(application)
37   {
38     // Connect to the Application's Init signal
39     mApplication.InitSignal().Connect(this, &TextVisualExample::Create);
40   }
41
42   ~TextVisualExample()
43   {
44     // Nothing to do here.
45   }
46
47   /**
48    * One-time setup in response to Application InitSignal.
49    */
50   void Create(Application& application)
51   {
52     Window window = application.GetWindow();
53
54     window.KeyEventSignal().Connect(this, &TextVisualExample::OnKeyEvent);
55     window.SetBackgroundColor(Color::WHITE);
56
57     Dali::Toolkit::Control control = Dali::Toolkit::ImageView::New();
58     control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
59
60     const std::string markupText("<color value='blue'><font size='50'>H</font></color>ello <color value='blue'><font size='50'>w</font></color>orld");
61
62     Dali::Property::Map map;
63     map.Add(Dali::Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::TEXT).Add(Dali::Toolkit::TextVisual::Property::ENABLE_MARKUP, true).Add(Dali::Toolkit::TextVisual::Property::TEXT, markupText).Add(Dali::Toolkit::TextVisual::Property::TEXT_COLOR, Dali::Vector4(0.25f, 0.25f, 0.5f, 1.f)).Add(Dali::Toolkit::TextVisual::Property::FONT_FAMILY, "TizenSansRegular").Add(Dali::Toolkit::TextVisual::Property::POINT_SIZE, 30.f).Add(Dali::Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, "END").Add(Dali::Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, "CENTER");
64
65     control.SetProperty(Dali::Toolkit::Control::Property::BACKGROUND, map);
66
67     window.Add(control);
68   }
69
70   /**
71    * Main key event handler
72    */
73   void OnKeyEvent(const KeyEvent& event)
74   {
75     if(event.GetState() == KeyEvent::DOWN)
76     {
77       if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK))
78       {
79         mApplication.Quit();
80       }
81     }
82   }
83
84 private:
85   Application& mApplication;
86
87   TextLabel mLabel;
88 };
89
90 void RunTest(Application& application)
91 {
92   TextVisualExample 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 }