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-field-example.cpp
20 * @brief Basic usage of TextField control
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali/public-api/text-abstraction/text-abstraction.h>
28 using namespace Dali::Toolkit;
33 const char* const BACKGROUND_IMAGE = DALI_IMAGE_DIR "button-up.9.png";
35 const float BORDER_WIDTH = 4.0f;
37 } // unnamed namespace
40 * @brief The main class of the demo.
42 class TextFieldExample : public ConnectionTracker
46 TextFieldExample( Application& application )
47 : mApplication( application )
49 // Connect to the Application's Init signal
50 mApplication.InitSignal().Connect( this, &TextFieldExample::Create );
55 // Nothing to do here.
59 * One-time setup in response to Application InitSignal.
61 void Create( Application& application )
63 Stage stage = Stage::GetCurrent();
65 stage.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent);
67 Vector2 stageSize = stage.GetSize();
69 mContainer = Control::New();
70 mContainer.SetName( "Container" );
71 mContainer.SetParentOrigin( ParentOrigin::CENTER );
72 mContainer.SetResizePolicy( FIXED, ALL_DIMENSIONS );
73 mContainer.SetPreferredSize( Vector2(stageSize.width*0.6f, stageSize.width*0.6f) );
74 mContainer.SetBackgroundImage( ResourceImage::New( BACKGROUND_IMAGE ) );
75 mContainer.GetChildAt(0).SetZ(-1.0f);
76 stage.Add( mContainer );
78 TextField field = TextField::New();
79 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
80 field.SetDimensionDependency( HEIGHT, WIDTH );
81 field.SetResizePolicy( FILL_TO_PARENT, WIDTH );
83 mContainer.Add( field );
85 field.SetProperty( TextField::Property::TEXT, "Hello" );
87 Property::Value fieldText = field.GetProperty( TextField::Property::TEXT );
88 std::cout << "Displaying text: " << fieldText.Get< std::string >() << std::endl;
92 * Main key event handler
94 void OnKeyEvent(const KeyEvent& event)
96 if(event.state == KeyEvent::Down)
98 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
107 Application& mApplication;
112 void RunTest( Application& application )
114 TextFieldExample test( application );
116 application.MainLoop();
119 /** Entry point for Linux & Tizen applications */
120 int main( int argc, char **argv )
122 Application application = Application::New( &argc, &argv );
124 RunTest( application );