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 "shared/multi-language-strings.h"
29 #include "shared/view.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 DemoHelper::RequestThemeChange();
62 Stage stage = Stage::GetCurrent();
64 stage.KeyEventSignal().Connect(this, &TextLabelMultiLanguageExample::OnKeyEvent);
66 mTableView = Toolkit::TableView::New( NUMBER_OF_LANGUAGES, 1 );
67 mTableView.SetResizePolicy( FILL_TO_PARENT, WIDTH );
68 mTableView.SetResizePolicy( USE_NATURAL_SIZE, HEIGHT );
69 mTableView.SetParentOrigin( ParentOrigin::TOP_LEFT );
70 mTableView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
71 mTableView.TouchedSignal().Connect( this, &TextLabelMultiLanguageExample::OnTouchEvent );
72 stage.Add( mTableView );
74 for( unsigned int index = 0u; index < NUMBER_OF_LANGUAGES; ++index )
76 const Language& language = LANGUAGES[index];
78 TextLabel label = TextLabel::New();
79 label.SetProperty( TextLabel::Property::MULTI_LINE, true );
81 const std::string text = language.languageName + " " + language.languageRomanName + " " + language.text;
82 label.SetProperty( TextLabel::Property::TEXT, text );
84 mTableView.SetFitHeight( index );
85 mTableView.AddChild( label, Toolkit::TableView::CellPosition( index, 0 ) );
89 bool OnTouchEvent( Actor actor, const TouchEvent& event )
91 if( 1u == event.GetPointCount() )
93 const TouchPoint::State state = event.GetPoint(0u).state;
95 // Clamp to integer values; this is to reduce flicking due to pixel misalignment
96 const float localPoint = static_cast<float>( static_cast<int>( event.GetPoint( 0 ).local.y ) );
98 if( TouchPoint::Down == state )
100 mLastPoint = localPoint;
101 mAnimation = Animation::New( 0.25f );
103 else if( TouchPoint::Motion == state )
107 mAnimation.AnimateBy( Property(mTableView, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear );
109 mLastPoint = localPoint;
118 * Main key event handler
120 void OnKeyEvent(const KeyEvent& event)
122 if(event.state == KeyEvent::Down)
124 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
133 Application& mApplication;
134 TableView mTableView;
135 Animation mAnimation;
139 void RunTest( Application& application )
141 TextLabelMultiLanguageExample test( application );
143 application.MainLoop();
146 /** Entry point for Linux & Tizen applications */
147 int main( int argc, char **argv )
149 Application application = Application::New( &argc, &argv );
151 RunTest( application );