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 simple-text-label-example.cpp
20 * @brief Basic usage of SimpleTextLabel control
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali/devel-api/text-abstraction/font-client.h>
27 #include <dali/devel-api/text-abstraction/bitmap-font.h>
28 #include <dali-toolkit/devel-api/text/bitmap-font.h>
31 using namespace Dali::Toolkit;
34 * @brief The main class of the demo.
36 class SimpleTextLabelExample : public ConnectionTracker
40 SimpleTextLabelExample( Application& application )
41 : mApplication( application )
43 // Connect to the Application's Init signal
44 mApplication.InitSignal().Connect( this, &SimpleTextLabelExample::Create );
47 ~SimpleTextLabelExample()
49 // Nothing to do here.
53 * One-time setup in response to Application InitSignal.
55 void Create( Application& application )
57 Stage stage = Stage::GetCurrent();
59 stage.KeyEventSignal().Connect(this, &SimpleTextLabelExample::OnKeyEvent);
61 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
63 DevelText::BitmapFontDescription fontDescription;
64 fontDescription.name = "Digits";
65 fontDescription.underlinePosition = 0.f;
66 fontDescription.underlineThickness = 0.f;
68 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0030.png", "0", 34.f, 0.f } );
69 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0031.png", "1", 34.f, 0.f } );
70 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0032.png", "2", 34.f, 0.f } );
71 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0033.png", "3", 34.f, 0.f } );
72 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0034.png", "4", 34.f, 0.f } );
73 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0035.png", "5", 34.f, 0.f } );
74 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0036.png", "6", 34.f, 0.f } );
75 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0037.png", "7", 34.f, 0.f } );
76 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0038.png", "8", 34.f, 0.f } );
77 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0039.png", "9", 34.f, 0.f } );
78 fontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u003a.png", ":", 34.f, 0.f } );
81 DevelText::BitmapFontDescription colorFontDescription;
82 colorFontDescription.name = "DigitsColor";
83 colorFontDescription.underlinePosition = 0.f;
84 colorFontDescription.underlineThickness = 0.f;
85 colorFontDescription.isColorFont = true;
87 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0030_color.png", "0", 34.f, 0.f } );
88 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0031_color.png", "1", 34.f, 0.f } );
89 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0032_color.png", "2", 34.f, 0.f } );
90 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0033_color.png", "3", 34.f, 0.f } );
91 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0034_color.png", "4", 34.f, 0.f } );
92 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0035_color.png", "5", 34.f, 0.f } );
93 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0036_color.png", "6", 34.f, 0.f } );
94 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0037_color.png", "7", 34.f, 0.f } );
95 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0038_color.png", "8", 34.f, 0.f } );
96 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u0039_color.png", "9", 34.f, 0.f } );
97 colorFontDescription.glyphs.push_back( { DEMO_IMAGE_DIR "u003a_color.png", ":", 34.f, 0.f } );
99 TextAbstraction::BitmapFont bitmapFont;
100 TextAbstraction::BitmapFont bitmapColorFont;
102 DevelText::CreateBitmapFont( fontDescription, bitmapFont );
103 DevelText::CreateBitmapFont( colorFontDescription, bitmapColorFont );
105 fontClient.GetFontId( bitmapFont );
106 fontClient.GetFontId( bitmapColorFont );
108 TextLabel label01 = TextLabel::New();
109 label01.SetAnchorPoint( AnchorPoint::CENTER );
110 label01.SetParentOrigin( ParentOrigin::CENTER );
111 label01.SetSize( 400.f, 50.f );
112 label01.SetPosition( 0.f, -100.f );
113 label01.SetProperty( TextLabel::Property::MULTI_LINE, true );
115 label01.SetProperty( TextLabel::Property::ENABLE_MARKUP, true );
116 label01.SetProperty( TextLabel::Property::TEXT, "012<color 'value'='green'>345</color>6789:" );
117 label01.SetProperty( TextLabel::Property::TEXT_COLOR, Color::RED );
118 label01.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" );
120 label01.SetBackgroundColor( Color::BLACK );
122 stage.Add( label01 );
125 TextLabel label02 = TextLabel::New();
126 label02.SetAnchorPoint( AnchorPoint::CENTER );
127 label02.SetParentOrigin( ParentOrigin::CENTER );
128 label02.SetSize( 400.f, 50.f );
129 label02.SetPosition( 0.f, -50.f );
130 label02.SetProperty( TextLabel::Property::MULTI_LINE, true );
132 label02.SetProperty( TextLabel::Property::TEXT, "0123456789:" );
133 label02.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE );
134 label02.SetProperty( TextLabel::Property::FONT_FAMILY, "DigitsColor" );
136 label02.SetBackgroundColor( Color::BLACK );
138 stage.Add( label02 );
140 TextLabel label03 = TextLabel::New();
141 label03.SetAnchorPoint( AnchorPoint::CENTER );
142 label03.SetParentOrigin( ParentOrigin::CENTER );
143 label03.SetSize( 400.f, 50.f );
144 label03.SetPosition( 0.f, 0.f );
145 label03.SetProperty( TextLabel::Property::MULTI_LINE, true );
147 label03.SetProperty( TextLabel::Property::TEXT, "0123456789:" );
148 label03.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" );
150 label03.SetBackgroundColor( Color::WHITE );
152 stage.Add( label03 );
154 TextLabel label04 = TextLabel::New();
155 label04.SetAnchorPoint( AnchorPoint::CENTER );
156 label04.SetParentOrigin( ParentOrigin::CENTER );
157 label04.SetSize( 400.f, 50.f );
158 label04.SetPosition( 0.f, 50.f );
159 label04.SetProperty( TextLabel::Property::MULTI_LINE, true );
161 label04.SetProperty( TextLabel::Property::TEXT, "0123456789:" );
162 label04.SetProperty( TextLabel::Property::FONT_FAMILY, "Digits" );
163 label04.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE );
165 label04.SetBackgroundColor( Color::BLACK );
167 stage.Add( label04 );
171 * Main key event handler
173 void OnKeyEvent(const KeyEvent& event)
175 if(event.state == KeyEvent::Down)
177 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
186 Application& mApplication;
189 void RunTest( Application& application )
191 SimpleTextLabelExample test( application );
193 application.MainLoop();
196 /** Entry point for Linux & Tizen applications */
197 int main( int argc, char **argv )
199 Application application = Application::New( &argc, &argv );
201 RunTest( application );