2 * Copyright (c) 2017 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>
27 #include "shared/multi-language-strings.h"
28 #include "shared/view.h"
31 using namespace Dali::Toolkit;
32 using namespace MultiLanguageStrings;
35 * @brief The main class of the demo.
37 class TextLabelMultiLanguageExample : public ConnectionTracker
41 TextLabelMultiLanguageExample( Application& application )
42 : mApplication( application ),
45 // Connect to the Application's Init signal
46 mApplication.InitSignal().Connect( this, &TextLabelMultiLanguageExample::Create );
49 ~TextLabelMultiLanguageExample()
51 // Nothing to do here.
55 * One-time setup in response to Application InitSignal.
57 void Create( Application& application )
59 Stage stage = Stage::GetCurrent();
61 stage.KeyEventSignal().Connect(this, &TextLabelMultiLanguageExample::OnKeyEvent);
62 stage.SetBackgroundColor( Color::WHITE );
64 mTableView = Toolkit::TableView::New( NUMBER_OF_LANGUAGES, 1 );
65 mTableView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
66 mTableView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
67 mTableView.SetParentOrigin( ParentOrigin::TOP_LEFT );
68 mTableView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
69 mTableView.TouchSignal().Connect( this, &TextLabelMultiLanguageExample::OnTouch );
70 stage.Add( mTableView );
72 for( unsigned int index = 0u; index < NUMBER_OF_LANGUAGES; ++index )
74 const Language& language = LANGUAGES[index];
76 TextLabel label = TextLabel::New();
77 label.SetProperty( TextLabel::Property::MULTI_LINE, true );
79 const std::string text = language.languageName + " " + language.languageRomanName + " " + language.text;
80 label.SetProperty( TextLabel::Property::TEXT, text );
82 mTableView.SetFitHeight( index );
83 mTableView.AddChild( label, Toolkit::TableView::CellPosition( index, 0 ) );
87 bool OnTouch( Actor actor, const TouchData& event )
89 if( 1u == event.GetPointCount() )
91 const PointState::Type state = event.GetState( 0 );
93 // Clamp to integer values; this is to reduce flicking due to pixel misalignment
94 const float localPoint = static_cast<float>( static_cast<int>( event.GetLocalPosition( 0 ).y ) );
96 if( PointState::DOWN == state )
98 mLastPoint = localPoint;
99 mAnimation = Animation::New( 0.25f );
101 else if( PointState::MOTION == state )
105 mAnimation.AnimateBy( Property(mTableView, Actor::Property::POSITION), Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunction::LINEAR );
107 mLastPoint = localPoint;
116 * Main key event handler
118 void OnKeyEvent(const KeyEvent& event)
120 if(event.state == KeyEvent::Down)
122 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
131 Application& mApplication;
132 TableView mTableView;
133 Animation mAnimation;
137 int DALI_EXPORT_API main( int argc, char **argv )
139 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
140 TextLabelMultiLanguageExample test( application );
141 application.MainLoop();