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::TOP_CENTER );
76 label.SetAnchorPoint( AnchorPoint::TOP_CENTER );
78 label.SetProperty( TextLabel::Property::MULTI_LINE, true );
80 const std::string text = language.languageName + " " + language.languageRomanName + " " + language.text;
82 label.SetProperty( TextLabel::Property::TEXT, text );
83 mLayout.AddLabel( label );
85 mLayout.TouchedSignal().Connect( this, &TextLabelMultiLanguageExample::OnTouchEvent );
88 const Vector2& size = Stage::GetCurrent().GetSize();
89 const float height = mLayout.GetHeightForWidth( size.width );
90 mLayout.SetSize( Size( size.width, height ) );
93 bool OnTouchEvent( Actor actor, const TouchEvent& event )
95 if( 1u == event.GetPointCount() )
97 const TouchPoint::State state = event.GetPoint(0u).state;
99 // Clamp to integer values; this is to reduce flicking due to pixel misalignment
100 const float localPoint = static_cast<float>( static_cast<int>( event.GetPoint( 0 ).local.y ) );
102 if( TouchPoint::Down == state )
104 mLastPoint = localPoint;
105 mAnimation = Animation::New( 0.25f );
107 else if( TouchPoint::Motion == state )
111 mAnimation.MoveBy( mLayout, Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear );
113 mLastPoint = localPoint;
122 * Main key event handler
124 void OnKeyEvent(const KeyEvent& event)
126 if(event.state == KeyEvent::Down)
128 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
137 Application& mApplication;
138 VerticalLayout mLayout;
139 Animation mAnimation;
143 void RunTest( Application& application )
145 TextLabelMultiLanguageExample test( application );
147 application.MainLoop();
150 /** Entry point for Linux & Tizen applications */
151 int main( int argc, char **argv )
153 Application application = Application::New( &argc, &argv );
155 RunTest( application );