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 "vertical-layout.h"
25 #include "shared/multi-language-strings.h"
28 #include <dali-toolkit/dali-toolkit.h>
29 #include <dali/public-api/text-abstraction/text-abstraction.h>
32 using namespace Dali::Toolkit;
33 using namespace MultiLanguageStrings;
36 * @brief The main class of the demo.
38 class TextLabelMultiLanguageExample : public ConnectionTracker
42 TextLabelMultiLanguageExample( Application& application )
43 : mApplication( application ),
46 // Connect to the Application's Init signal
47 mApplication.InitSignal().Connect( this, &TextLabelMultiLanguageExample::Create );
50 ~TextLabelMultiLanguageExample()
52 // Nothing to do here.
56 * One-time setup in response to Application InitSignal.
58 void Create( Application& application )
60 Stage stage = Stage::GetCurrent();
62 stage.KeyEventSignal().Connect(this, &TextLabelMultiLanguageExample::OnKeyEvent);
64 mLayout = VerticalLayout::New();
65 mLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
66 mLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
70 for( unsigned int index = 0u; index < NUMBER_OF_LANGUAGES; ++index )
72 const Language& language = LANGUAGES[index];
74 TextLabel label = TextLabel::New();
75 label.SetParentOrigin( ParentOrigin::CENTER );
77 label.SetProperty( TextLabel::Property::MULTI_LINE, true );
79 const std::string text = language.languageName + " " + language.languageRomanName + " " + language.text;
81 label.SetProperty( TextLabel::Property::TEXT, text );
82 mLayout.AddLabel( label );
84 mLayout.TouchedSignal().Connect( this, &TextLabelMultiLanguageExample::OnTouchEvent );
87 const Vector2& size = Stage::GetCurrent().GetSize();
88 const float height = mLayout.GetHeightForWidth( size.width );
89 mLayout.SetSize( Size( size.width, height ) );
92 bool OnTouchEvent( Actor actor, const TouchEvent& event )
94 if( 1u == event.GetPointCount() )
96 const TouchPoint::State state = event.GetPoint(0u).state;
98 // Clamp to integer values; this is to reduce flicking due to pixel misalignment
99 const float localPoint = static_cast<float>( static_cast<int>( event.GetPoint( 0 ).local.y ) );
101 if( TouchPoint::Down == state )
103 mLastPoint = localPoint;
104 mAnimation = Animation::New( 0.25f );
106 else if( TouchPoint::Motion == state )
110 mAnimation.MoveBy( mLayout, Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear );
112 mLastPoint = localPoint;
121 * Main key event handler
123 void OnKeyEvent(const KeyEvent& event)
125 if(event.state == KeyEvent::Down)
127 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
136 Application& mApplication;
137 VerticalLayout mLayout;
138 Animation mAnimation;
142 void RunTest( Application& application )
144 TextLabelMultiLanguageExample 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 );