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 text-fonts-example.cpp
20 * @brief Example of various TextLabel each with different font set ups,
21 * enables Testing of Font when the system font changes.
22 The first label is free, with no font family set, it could use the default system font and change as it changes.
23 The second label has it's font family set via the demo json file. It should not change when the system font changes.
24 The third label has it's font family set in code via SetProperty. It also should not change when the system font changes.
25 The forth label is not shown until the button along the bottom is pressed, it has no font set so the newly created label should use the system font,
26 Pressing the button again resets and unparents that button and then re-adds it.
30 #include <dali-toolkit/dali-toolkit.h>
34 #include "shared/multi-language-strings.h"
35 #include "shared/view.h"
38 using namespace Dali::Toolkit;
39 using namespace MultiLanguageStrings;
43 const char* const LABEL_TEXT = "A Quick Fox";
44 const char* const LABEL_TEXT_MIXED = "Fox 구미호";
45 const char* const LABEL_TEXT_KOREAN = "구미호";
49 * @brief The main class of the demo.
51 class TextFontsExample : public ConnectionTracker
54 TextFontsExample(Application& application)
55 : mApplication(application),
58 // Connect to the Application's Init signal
59 mApplication.InitSignal().Connect(this, &TextFontsExample::Create);
64 // Nothing to do here.
67 void CreateTextLabel(TextLabel& textLabel, std::string textString, const Vector4& color, bool infoLabel = false)
69 textLabel = TextLabel::New(textString);
70 textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
71 textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
72 textLabel.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT);
73 textLabel.SetProperty(TextLabel::Property::MULTI_LINE, true);
76 textLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE);
77 textLabel.SetProperty(TextLabel::Property::POINT_SIZE, 12.0f);
78 textLabel.SetProperty(TextLabel::Property::FONT_FAMILY, "SamsungOneUI");
82 Property::Map shadowMap;
83 shadowMap.Insert("color", Color::BLACK);
84 shadowMap.Insert("offset", Vector2(0.3f, 0.3f));
85 textLabel.SetProperty(TextLabel::Property::SHADOW, shadowMap);
86 textLabel.SetProperty(TextLabel::Property::TEXT_COLOR, Color::BLUE);
88 textLabel.SetBackgroundColor(color);
91 void CreateContainer(Control& container, const Vector2 size)
93 container = Control::New();
94 container.SetProperty(Actor::Property::SIZE, size);
95 container.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
96 container.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
99 void CreateFolderButton(PushButton& button)
101 button = PushButton::New();
102 button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER);
103 button.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
104 button.SetProperty(Actor::Property::SIZE, Vector2(50.0f, 50.0f));
107 bool OnButtonClicked(Toolkit::Button button)
111 UnparentAndReset(mLabel4);
116 CreateContainer(mContainer4, mLayoutSize);
117 Window window = mApplication.GetWindow();
118 Vector2 windowSize = window.GetSize();
119 mContainer4.SetProperty(Actor::Property::POSITION, Vector2(0, windowSize.height * 0.25f * 3));
120 window.Add(mContainer4);
122 CreateContainer(mContainer4Info, mLayoutSize);
123 mContainer4Info.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
124 mContainer4.Add(mContainer4Info);
125 CreateTextLabel(mLabel4Info, "system free", Color::BLACK, true);
126 mContainer4Info.Add(mLabel4Info);
131 CreateTextLabel(mLabel4, LABEL_TEXT_KOREAN, Color::WHITE);
136 CreateTextLabel(mLabel4, LABEL_TEXT_MIXED, Color::WHITE);
140 mContainer4.Add(mLabel4);
146 * One-time setup in response to Application InitSignal.
148 void Create(Application& application)
150 Window window = application.GetWindow();
151 Vector2 windowSize = window.GetSize();
153 window.KeyEventSignal().Connect(this, &TextFontsExample::OnKeyEvent);
155 CreateFolderButton(mButton);
156 mButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_CENTER);
157 mButton.ClickedSignal().Connect(this, &TextFontsExample::OnButtonClicked);
160 mLayoutSize = Vector2(windowSize.width * 0.5f, windowSize.height * 0.10f);
161 CreateContainer(mContainer, mLayoutSize);
162 CreateContainer(mContainer2, mLayoutSize);
163 CreateContainer(mContainer3, mLayoutSize);
165 // Info about Text Label and if font should be fixed or free to change with system
166 CreateContainer(mContainerInfo, mLayoutSize);
167 CreateContainer(mContainer2Info, mLayoutSize);
168 CreateContainer(mContainer3Info, mLayoutSize);
169 mContainerInfo.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
170 mContainer2Info.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
171 mContainer3Info.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_RIGHT);
172 mContainer.Add(mContainerInfo);
173 mContainer2.Add(mContainer2Info);
174 mContainer3.Add(mContainer3Info);
175 CreateTextLabel(mLabelInfo, "system free", Color::BLACK, true);
176 CreateTextLabel(mLabel2Info, "json fixed", Color::BLACK, true);
177 CreateTextLabel(mLabel3Info, "SetProp fixed", Color::BLACK, true);
178 mContainerInfo.Add(mLabelInfo);
179 mContainer2Info.Add(mLabel2Info);
180 mContainer3Info.Add(mLabel3Info);
182 window.Add(mContainer);
183 window.Add(mContainer2);
184 window.Add(mContainer3);
186 CreateTextLabel(mLabel, LABEL_TEXT, Color::WHITE);
188 CreateTextLabel(mLabel2, LABEL_TEXT, Color::WHITE);
189 mLabel2.SetStyleName("TextLabelRosemary");
191 CreateTextLabel(mLabel3, LABEL_TEXT, Color::WHITE);
192 mLabel3.SetProperty(TextLabel::Property::FONT_FAMILY, "SamsungOneUI");
194 mContainer.SetProperty(Actor::Property::POSITION, Vector2(0, 0));
195 mContainer2.SetProperty(Actor::Property::POSITION, Vector2(0, windowSize.height * 0.25f));
196 mContainer3.SetProperty(Actor::Property::POSITION, Vector2(0, windowSize.height * 0.25f * 2));
198 mContainer.Add(mLabel);
199 mContainer2.Add(mLabel2);
200 mContainer3.Add(mLabel3);
204 * Main key event handler
206 void OnKeyEvent(const KeyEvent& event)
208 if(event.GetState() == KeyEvent::DOWN)
210 if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK))
218 Application& mApplication;
233 Control mContainerInfo;
234 Control mContainer2Info;
235 Control mContainer3Info;
236 Control mContainer4Info;
238 TextLabel mLabelInfo;
239 TextLabel mLabel2Info;
240 TextLabel mLabel3Info;
241 TextLabel mLabel4Info;
248 int DALI_EXPORT_API main(int argc, char** argv)
250 Application application = Application::New(&argc, &argv, DEMO_THEME_PATH);
251 TextFontsExample test(application);
252 application.MainLoop();