2 * Copyright (c) 2015 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-label-example.cpp
20 * @brief Basic usage of TextLabel control
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali/public-api/text-abstraction/text-abstraction.h>
28 #include "center-layout.h"
29 #include "shared/multi-language-strings.h"
32 using namespace Dali::Toolkit;
33 using namespace MultiLanguageStrings;
37 const unsigned int KEY_ZERO = 10;
38 const unsigned int KEY_ONE = 11;
39 const unsigned int KEY_A = 38;
40 const unsigned int KEY_M = 58;
41 const unsigned int KEY_L = 46;
43 const char* ALIGNMENT_STRING_TABLE[] =
50 const unsigned int ALIGNMENT_STRING_COUNT = sizeof( ALIGNMENT_STRING_TABLE ) / sizeof( ALIGNMENT_STRING_TABLE[0u] );
54 * @brief The main class of the demo.
56 class TextLabelExample : public ConnectionTracker
60 TextLabelExample( Application& application )
61 : mApplication( application ),
65 // Connect to the Application's Init signal
66 mApplication.InitSignal().Connect( this, &TextLabelExample::Create );
71 // Nothing to do here.
75 * One-time setup in response to Application InitSignal.
77 void Create( Application& application )
79 Stage stage = Stage::GetCurrent();
81 stage.SetBackgroundColor( Color::BLUE );
82 stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
83 Vector2 stageSize = stage.GetSize();
85 CenterLayout centerLayout = CenterLayout::New();
86 centerLayout.SetParentOrigin( ParentOrigin::CENTER );
87 centerLayout.SetSize( stageSize.width*0.6f, stageSize.width*0.6f );
88 stage.Add( centerLayout );
90 mLabel = TextLabel::New();
91 mLabel.SetBackgroundColor( Color::BLACK );
92 centerLayout.Add( mLabel );
94 mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
95 mLabel.SetProperty( TextLabel::Property::TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
97 Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT );
98 std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
102 * Main key event handler
104 void OnKeyEvent(const KeyEvent& event)
106 if(event.state == KeyEvent::Down)
108 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
112 else if( event.IsCtrlModifier() )
114 switch( event.keyCode )
116 case KEY_ZERO: // fall through
119 mLabel.SetProperty( TextLabel::Property::RENDERING_BACKEND, event.keyCode - 10 );
124 if( ++mAlignment >= ALIGNMENT_STRING_COUNT )
129 mLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, ALIGNMENT_STRING_TABLE[ mAlignment ] );
134 bool multiLine = mLabel.GetProperty<bool>( TextLabel::Property::MULTI_LINE );
135 mLabel.SetProperty( TextLabel::Property::MULTI_LINE, !multiLine );
140 const Language& language = LANGUAGES[ mLanguageId ];
142 mLabel.SetProperty( TextLabel::Property::TEXT, language.text );
144 if( ++mLanguageId >= NUMBER_OF_LANGUAGES )
157 Application& mApplication;
161 unsigned int mLanguageId;
162 unsigned int mAlignment;
165 void RunTest( Application& application )
167 TextLabelExample test( application );
169 application.MainLoop();
172 /** Entry point for Linux & Tizen applications */
173 int main( int argc, char **argv )
175 Application application = Application::New( &argc, &argv );
177 RunTest( application );