2 * Copyright (c) 2019 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
36 TextVisualExample( Application& application )
37 : mApplication( application )
39 // Connect to the Application's Init signal
40 mApplication.InitSignal().Connect( this, &TextVisualExample::Create );
45 // Nothing to do here.
49 * One-time setup in response to Application InitSignal.
51 void Create( Application& application )
53 Stage stage = Stage::GetCurrent();
55 stage.KeyEventSignal().Connect(this, &TextVisualExample::OnKeyEvent);
56 stage.SetBackgroundColor( Color::WHITE );
58 Dali::Toolkit::Control control = Dali::Toolkit::ImageView::New();
59 control.SetParentOrigin( ParentOrigin::CENTER );
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" );
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" );
73 control.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map );
79 * Main key event handler
81 void OnKeyEvent(const KeyEvent& event)
83 if(event.state == KeyEvent::Down)
85 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
94 Application& mApplication;
99 void RunTest( Application& application )
101 TextVisualExample test( application );
103 application.MainLoop();
106 /** Entry point for Linux & Tizen applications */
107 int DALI_EXPORT_API main( int argc, char **argv )
109 Application application = Application::New( &argc, &argv );
111 RunTest( application );