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-visual-example.cpp
20 * @brief Basic usage of Text Visual.
24 #include <dali-toolkit/dali-toolkit.h>
27 using namespace Dali::Toolkit;
30 * @brief The main class of the demo.
32 class TextVisualExample : public ConnectionTracker
35 TextVisualExample(Application& application)
36 : mApplication(application)
38 // Connect to the Application's Init signal
39 mApplication.InitSignal().Connect(this, &TextVisualExample::Create);
44 // Nothing to do here.
48 * One-time setup in response to Application InitSignal.
50 void Create(Application& application)
52 Window window = application.GetWindow();
54 window.KeyEventSignal().Connect(this, &TextVisualExample::OnKeyEvent);
55 window.SetBackgroundColor(Color::WHITE);
57 Dali::Toolkit::Control control = Dali::Toolkit::ImageView::New();
58 control.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
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");
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");
65 control.SetProperty(Dali::Toolkit::Control::Property::BACKGROUND, map);
71 * Main key event handler
73 void OnKeyEvent(const KeyEvent& event)
75 if(event.GetState() == KeyEvent::DOWN)
77 if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK))
85 Application& mApplication;
90 void RunTest(Application& application)
92 TextVisualExample test(application);
94 application.MainLoop();
97 /** Entry point for Linux & Tizen applications */
98 int DALI_EXPORT_API main(int argc, char** argv)
100 Application application = Application::New(&argc, &argv);
102 RunTest(application);