2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file simple-text-label-example.cpp
20 * @brief Basic usage of SimpleTextLabel control
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit/devel-api/text/bitmap-font.h>
27 #include <dali/devel-api/text-abstraction/bitmap-font.h>
28 #include <dali/devel-api/text-abstraction/font-client.h>
31 using namespace Dali::Toolkit;
34 * @brief The main class of the demo.
36 class SimpleTextLabelExample : public ConnectionTracker
39 SimpleTextLabelExample(Application& application)
40 : mApplication(application)
42 // Connect to the Application's Init signal
43 mApplication.InitSignal().Connect(this, &SimpleTextLabelExample::Create);
46 ~SimpleTextLabelExample()
48 // Nothing to do here.
52 * One-time setup in response to Application InitSignal.
54 void Create(Application& application)
56 Window window = application.GetWindow();
58 window.KeyEventSignal().Connect(this, &SimpleTextLabelExample::OnKeyEvent);
60 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
62 DevelText::BitmapFontDescription fontDescription;
63 fontDescription.name = "Digits";
64 fontDescription.underlinePosition = 0.f;
65 fontDescription.underlineThickness = 0.f;
67 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0030.png", "0", 34.f, 0.f});
68 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0031.png", "1", 34.f, 0.f});
69 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0032.png", "2", 34.f, 0.f});
70 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0033.png", "3", 34.f, 0.f});
71 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0034.png", "4", 34.f, 0.f});
72 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0035.png", "5", 34.f, 0.f});
73 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0036.png", "6", 34.f, 0.f});
74 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0037.png", "7", 34.f, 0.f});
75 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0038.png", "8", 34.f, 0.f});
76 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0039.png", "9", 34.f, 0.f});
77 fontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u003a.png", ":", 34.f, 0.f});
79 DevelText::BitmapFontDescription colorFontDescription;
80 colorFontDescription.name = "DigitsColor";
81 colorFontDescription.underlinePosition = 0.f;
82 colorFontDescription.underlineThickness = 0.f;
83 colorFontDescription.isColorFont = true;
85 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0030_color.png", "0", 34.f, 0.f});
86 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0031_color.png", "1", 34.f, 0.f});
87 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0032_color.png", "2", 34.f, 0.f});
88 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0033_color.png", "3", 34.f, 0.f});
89 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0034_color.png", "4", 34.f, 0.f});
90 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0035_color.png", "5", 34.f, 0.f});
91 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0036_color.png", "6", 34.f, 0.f});
92 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0037_color.png", "7", 34.f, 0.f});
93 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0038_color.png", "8", 34.f, 0.f});
94 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u0039_color.png", "9", 34.f, 0.f});
95 colorFontDescription.glyphs.push_back({DEMO_IMAGE_DIR "u003a_color.png", ":", 34.f, 0.f});
97 TextAbstraction::BitmapFont bitmapFont;
98 TextAbstraction::BitmapFont bitmapColorFont;
100 DevelText::CreateBitmapFont(fontDescription, bitmapFont);
101 DevelText::CreateBitmapFont(colorFontDescription, bitmapColorFont);
103 fontClient.GetFontId(bitmapFont);
104 fontClient.GetFontId(bitmapColorFont);
106 TextLabel label01 = TextLabel::New();
107 label01.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
108 label01.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
109 label01.SetProperty(Actor::Property::SIZE, Vector2(400.f, 50.f));
110 label01.SetProperty(Actor::Property::POSITION, Vector2(0.f, -100.f));
111 label01.SetProperty(TextLabel::Property::MULTI_LINE, true);
113 label01.SetProperty(TextLabel::Property::ENABLE_MARKUP, true);
114 label01.SetProperty(TextLabel::Property::TEXT, "012<color 'value'='green'>345</color>6789:");
115 label01.SetProperty(TextLabel::Property::TEXT_COLOR, Color::RED);
116 label01.SetProperty(TextLabel::Property::FONT_FAMILY, "Digits");
118 label01.SetBackgroundColor(Color::BLACK);
122 TextLabel label02 = TextLabel::New();
123 label02.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
124 label02.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
125 label02.SetProperty(Actor::Property::SIZE, Vector2(400.f, 50.f));
126 label02.SetProperty(Actor::Property::POSITION, Vector2(0.f, -50.f));
127 label02.SetProperty(TextLabel::Property::MULTI_LINE, true);
129 label02.SetProperty(TextLabel::Property::TEXT, "0123456789:");
130 label02.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE);
131 label02.SetProperty(TextLabel::Property::FONT_FAMILY, "DigitsColor");
133 label02.SetBackgroundColor(Color::BLACK);
137 TextLabel label03 = TextLabel::New();
138 label03.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
139 label03.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
140 label03.SetProperty(Actor::Property::SIZE, Vector2(400.f, 50.f));
141 label03.SetProperty(Actor::Property::POSITION, Vector2(0.f, 0.f));
142 label03.SetProperty(TextLabel::Property::MULTI_LINE, true);
144 label03.SetProperty(TextLabel::Property::TEXT, "0123456789:");
145 label03.SetProperty(TextLabel::Property::FONT_FAMILY, "Digits");
147 label03.SetBackgroundColor(Color::WHITE);
151 TextLabel label04 = TextLabel::New();
152 label04.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
153 label04.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
154 label04.SetProperty(Actor::Property::SIZE, Vector2(400.f, 50.f));
155 label04.SetProperty(Actor::Property::POSITION, Vector2(0.f, 50.f));
156 label04.SetProperty(TextLabel::Property::MULTI_LINE, true);
158 label04.SetProperty(TextLabel::Property::TEXT, "0123456789:");
159 label04.SetProperty(TextLabel::Property::FONT_FAMILY, "Digits");
160 label04.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE);
162 label04.SetBackgroundColor(Color::BLACK);
168 * Main key event handler
170 void OnKeyEvent(const KeyEvent& event)
172 if(event.GetState() == KeyEvent::DOWN)
174 if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK))
182 Application& mApplication;
185 void RunTest(Application& application)
187 SimpleTextLabelExample test(application);
189 application.MainLoop();
192 /** Entry point for Linux & Tizen applications */
193 int DALI_EXPORT_API main(int argc, char** argv)
195 Application application = Application::New(&argc, &argv);
197 RunTest(application);