X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fsimple-text-field%2Fsimple-text-field.cpp;h=601e6a5bd583840572d427bf917a73b51ff243ed;hb=2ad634fa738e36171a4116b09b94c19cd5c60a81;hp=ee9b3e75bec769fe4eec47609a51ecd9c1fe91ef;hpb=cc86309efaef5f77c85ece1199f95e08534e4a32;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/simple-text-field/simple-text-field.cpp b/examples/simple-text-field/simple-text-field.cpp index ee9b3e7..601e6a5 100644 --- a/examples/simple-text-field/simple-text-field.cpp +++ b/examples/simple-text-field/simple-text-field.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,24 +22,23 @@ // EXTERNAL INCLUDES #include +#include #include using namespace Dali; using namespace Dali::Toolkit; - /** * @brief The main class of the demo. */ class SimpleTextFieldExample : public ConnectionTracker { public: - - SimpleTextFieldExample( Application& application ) - : mApplication( application ) + SimpleTextFieldExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &SimpleTextFieldExample::Create ); + mApplication.InitSignal().Connect(this, &SimpleTextFieldExample::Create); } ~SimpleTextFieldExample() @@ -50,23 +49,62 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { - Stage stage = Stage::GetCurrent(); - stage.KeyEventSignal().Connect(this, &SimpleTextFieldExample::OnKeyEvent); - stage.SetBackgroundColor( Vector4( 0.04f, 0.345f, 0.392f, 1.0f ) ); + Window window = application.GetWindow(); + window.KeyEventSignal().Connect(this, &SimpleTextFieldExample::OnKeyEvent); + window.SetBackgroundColor(Vector4(0.04f, 0.345f, 0.392f, 1.0f)); + + mTextField = TextField::New(); + mTextField.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mTextField.SetProperty(Actor::Property::SIZE, Vector2(300.f, 60.f)); + mTextField.SetBackgroundColor(Color::WHITE); + mTextField.SetBackgroundColor(Vector4(1.f, 1.f, 1.f, 0.15f)); + + mTextField.SetProperty(TextField::Property::TEXT_COLOR, Color::BLACK); + mTextField.SetProperty(TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder"); + mTextField.SetProperty(TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name."); + + mButtonSelectionStart = PushButton::New(); + mButtonSelectionEnd = PushButton::New(); + + mButtonSelectionStart.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mButtonSelectionStart.SetProperty(Actor::Property::SIZE, Vector2(140.f, 50.f)); + mButtonSelectionStart.SetProperty(Actor::Property::POSITION, Vector2(0.f, 80.f)); + mButtonSelectionStart.SetBackgroundColor(Color::BLUE); + mButtonSelectionStart.SetProperty(Button::Property::LABEL, "select <--"); + mButtonSelectionStart.ClickedSignal().Connect(this, &SimpleTextFieldExample::OnButtonClicked); + + mButtonSelectionEnd.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + mButtonSelectionEnd.SetProperty(Actor::Property::SIZE, Vector2(140.f, 50.f)); + mButtonSelectionEnd.SetProperty(Actor::Property::POSITION, Vector2(0.f, 140.f)); + mButtonSelectionEnd.SetBackgroundColor(Color::BLUE); + mButtonSelectionEnd.SetProperty(Button::Property::LABEL, "select -->"); + mButtonSelectionEnd.ClickedSignal().Connect(this, &SimpleTextFieldExample::OnButtonClicked); + + window.Add(mTextField); + window.Add(mButtonSelectionStart); + window.Add(mButtonSelectionEnd); + } - TextField field = TextField::New(); - field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - field.SetSize( 300.f, 60.f ); - field.SetBackgroundColor( Color::WHITE ); - field.SetBackgroundColor( Vector4( 1.f, 1.f, 1.f, 0.15f ) ); - field.SetProperty( TextField::Property::TEXT_COLOR, Color::BLACK ); - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder" ); - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name." ); + bool OnButtonClicked(Button button) + { + if(button == mButtonSelectionStart) + { + int iStart = mTextField.GetProperty(DevelTextField::Property::SELECTED_TEXT_START).Get() - 1; + if (iStart < 0) + { + iStart = 0; + } + mTextField.SetProperty(DevelTextField::Property::SELECTED_TEXT_START, iStart); + } + else if(button == mButtonSelectionEnd) + { + mTextField.SetProperty(DevelTextField::Property::SELECTED_TEXT_END , mTextField.GetProperty(DevelTextField::Property::SELECTED_TEXT_END).Get() + 1); + } - stage.Add( field ); + return true; } /** @@ -74,9 +112,9 @@ public: */ void OnKeyEvent(const KeyEvent& event) { - if(event.state == KeyEvent::Down) + if(event.GetState() == KeyEvent::DOWN) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -84,24 +122,26 @@ public: } private: - Application& mApplication; + TextField mTextField; + PushButton mButtonSelectionStart; + PushButton mButtonSelectionEnd; }; -void RunTest( Application& application ) +void RunTest(Application& application) { - SimpleTextFieldExample test( application ); + SimpleTextFieldExample test(application); application.MainLoop(); } /** Entry point for Linux & Tizen applications */ -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { // DALI_DEMO_THEME_PATH not passed to Application so TextField example uses default Toolkit style sheet. - Application application = Application::New( &argc, &argv ); + Application application = Application::New(&argc, &argv); - RunTest( application ); + RunTest(application); return 0; }