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_M = 58;
40 const unsigned int KEY_L = 46;
44 * @brief The main class of the demo.
46 class TextLabelExample : public ConnectionTracker
50 TextLabelExample( Application& application )
51 : mApplication( application ),
54 // Connect to the Application's Init signal
55 mApplication.InitSignal().Connect( this, &TextLabelExample::Create );
60 // Nothing to do here.
64 * One-time setup in response to Application InitSignal.
66 void Create( Application& application )
68 Stage stage = Stage::GetCurrent();
70 stage.SetBackgroundColor( Color::BLUE );
71 stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
72 Vector2 stageSize = stage.GetSize();
74 CenterLayout centerLayout = CenterLayout::New();
75 centerLayout.SetParentOrigin( ParentOrigin::CENTER );
76 centerLayout.SetSize( stageSize.width*0.6f, stageSize.width*0.6f );
77 stage.Add( centerLayout );
79 mLabel = TextLabel::New();
80 mLabel.SetBackgroundColor( Color::BLACK );
81 centerLayout.Add( mLabel );
83 mLabel.SetProperty( TextLabel::PROPERTY_MULTI_LINE, true );
84 mLabel.SetProperty( TextLabel::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" );
86 Property::Value labelText = mLabel.GetProperty( TextLabel::PROPERTY_TEXT );
87 std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
91 * Main key event handler
93 void OnKeyEvent(const KeyEvent& event)
95 if(event.state == KeyEvent::Down)
97 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
101 else if( event.IsCtrlModifier() )
103 switch( event.keyCode )
105 case KEY_ZERO: // fall through
108 mLabel.SetProperty( TextLabel::PROPERTY_RENDERING_BACKEND, event.keyCode - 10 );
113 bool multiLine = mLabel.GetProperty<bool>( TextLabel::PROPERTY_MULTI_LINE );
114 mLabel.SetProperty( TextLabel::PROPERTY_MULTI_LINE, !multiLine );
119 const Language& language = LANGUAGES[ mLanguageId ];
121 mLabel.SetProperty( TextLabel::PROPERTY_TEXT, language.text );
123 if( ++mLanguageId >= NUMBER_OF_LANGUAGES )
135 Application& mApplication;
139 unsigned int mLanguageId;
142 void RunTest( Application& application )
144 TextLabelExample test( application );
146 application.MainLoop();
149 /** Entry point for Linux & Tizen applications */
150 int main( int argc, char **argv )
152 Application application = Application::New( &argc, &argv );
154 RunTest( application );