X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Ftext-field%2Ftext-field-example.cpp;h=307c0df504ae938fc20ee0f2bf1883b7079d8f6c;hb=6b9fe56ad6fd9e6851845870428e6a9842d15f65;hp=9b4a5f4dee3982cd24983105e0c3c68c3d02f724;hpb=1495292c061d41df315a0e38b3c3ae54c68e6e4b;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/text-field/text-field-example.cpp b/examples/text-field/text-field-example.cpp index 9b4a5f4..307c0df 100644 --- a/examples/text-field/text-field-example.cpp +++ b/examples/text-field/text-field-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 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. @@ -24,7 +24,6 @@ #include #include #include -#include // INTERNAL INCLUDES #include "shared/multi-language-strings.h" @@ -36,13 +35,10 @@ using namespace MultiLanguageStrings; namespace { +const char* const FOLDER_ICON_IMAGE = DEMO_IMAGE_DIR "folder_appicon_empty_bg.png"; +const char* const FOLDER_OPEN_ICON_IMAGE = DEMO_IMAGE_DIR "folder_appicon_empty_open_bg.png"; - const char* const FOLDER_ICON_IMAGE = DALI_IMAGE_DIR "folder_appicon_empty_bg.png"; - const char* const FOLDER_OPEN_ICON_IMAGE = DALI_IMAGE_DIR "folder_appicon_empty_open_bg.png"; - - const float BORDER_WIDTH = 4.0f; - - const Vector3 POPUP_SIZE_FACTOR_TO_PARENT = Vector3( 0.0, 0.25, 0.0 ); +const float BORDER_WIDTH = 4.0f; } // unnamed namespace @@ -52,12 +48,11 @@ namespace class TextFieldExample : public ConnectionTracker { public: - - TextFieldExample( Application& application ) - : mApplication( application ) + TextFieldExample(Application& application) + : mApplication(application) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &TextFieldExample::Create ); + mApplication.InitSignal().Connect(this, &TextFieldExample::Create); } ~TextFieldExample() @@ -68,75 +63,70 @@ public: /** * One-time setup in response to Application InitSignal. */ - void Create( Application& application ) + void Create(Application& application) { - Stage stage = Stage::GetCurrent(); + Window window = application.GetWindow(); - stage.SetBackgroundColor( Vector4( 0.04f, 0.345f, 0.392f, 1.0f ) ); - stage.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent); + window.SetBackgroundColor(Vector4(0.04f, 0.345f, 0.392f, 1.0f)); + window.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent); mButton = CreateFolderButton(); - mButton.ClickedSignal().Connect( this, &TextFieldExample::OnButtonClicked ); - stage.Add( mButton ); + mButton.ClickedSignal().Connect(this, &TextFieldExample::OnButtonClicked); + window.Add(mButton); } PushButton CreateFolderButton() { PushButton button = PushButton::New(); - button.SetUnselectedImage( FOLDER_ICON_IMAGE ); - button.SetSelectedImage( FOLDER_OPEN_ICON_IMAGE ); - button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - button.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - ResourceImage imageClosed = ResourceImage::New( FOLDER_ICON_IMAGE ); - button.SetSize( imageClosed.GetWidth(), imageClosed.GetHeight() ); - + button.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, FOLDER_ICON_IMAGE); + button.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, FOLDER_OPEN_ICON_IMAGE); + button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); return button; } - bool OnButtonClicked( Toolkit::Button button ) + bool OnButtonClicked(Toolkit::Button button) { - Stage stage = Stage::GetCurrent(); - Vector2 stageSize = stage.GetSize(); + Window window = mApplication.GetWindow(); + Vector2 windowSize = window.GetSize(); // Remove previously hidden pop-up UnparentAndReset(mPopup); // Launch a pop-up containing TextField - mField = CreateTextField( stageSize, mButtonLabel ); - mPopup = CreatePopup( stageSize.width * 0.8f ); - mPopup.Add( mField ); - mPopup.OutsideTouchedSignal().Connect( this, &TextFieldExample::OnPopupOutsideTouched ); - stage.Add( mPopup ); - mPopup.SetDisplayState( Popup::SHOWN ); + mField = CreateTextField(windowSize, mButtonLabel); + mPopup = CreatePopup(); + mPopup.Add(mField); + mPopup.OutsideTouchedSignal().Connect(this, &TextFieldExample::OnPopupOutsideTouched); + window.Add(mPopup); + mPopup.SetDisplayState(Popup::SHOWN); return true; } - TextField CreateTextField( const Vector2& stageSize, const std::string& text ) + TextField CreateTextField(const Vector2& windowSize, const std::string& text) { TextField field = TextField::New(); - field.SetName("text-field"); - field.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - field.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH ); - field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT ); - field.SetProperty( TextField::Property::TEXT, text ); - field.SetProperty( TextField::Property::TEXT_COLOR, Vector4( 0.0f, 1.0f, 1.0f, 1.0f ) ); // CYAN - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder" ); - field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name." ); - field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect( BORDER_WIDTH, BORDER_WIDTH, stageSize.width - BORDER_WIDTH*2, stageSize.height - BORDER_WIDTH*2 ) ); + field.SetProperty(Dali::Actor::Property::NAME, "textField"); + field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + field.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH); + field.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT); + field.SetProperty(TextField::Property::TEXT, text); + field.SetProperty(TextField::Property::TEXT_COLOR, Vector4(0.0f, 1.0f, 1.0f, 1.0f)); // CYAN + field.SetProperty(TextField::Property::PLACEHOLDER_TEXT, "Unnamed folder"); + field.SetProperty(TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter folder name."); + field.SetProperty(TextField::Property::DECORATION_BOUNDING_BOX, Rect(BORDER_WIDTH, BORDER_WIDTH, windowSize.width - BORDER_WIDTH * 2, windowSize.height - BORDER_WIDTH * 2)); return field; } - Popup CreatePopup( float width ) + Popup CreatePopup() { Popup popup = Popup::New(); - popup.SetParentOrigin( ParentOrigin::CENTER ); - popup.SetAnchorPoint( AnchorPoint::CENTER ); - popup.SetSize( width, 0.0f ); - popup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT ); - popup.SetSizeModeFactor( POPUP_SIZE_FACTOR_TO_PARENT ); - popup.TouchedSignal().Connect( this, &TextFieldExample::OnPopupTouched ); + popup.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + popup.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + popup.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH); + popup.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT); + popup.TouchedSignal().Connect(this, &TextFieldExample::OnPopupTouched); return popup; } @@ -144,37 +134,36 @@ public: void OnPopupOutsideTouched() { // Update the folder text - if( mButton && mField ) + if(mButton && mField) { - Property::Value text = mField.GetProperty( TextField::Property::TEXT ); - mButtonLabel = text.Get< std::string >(); - mButton.SetLabelText( mButtonLabel ); + Property::Value text = mField.GetProperty(TextField::Property::TEXT); + mButtonLabel = text.Get(); + mButton.SetProperty(Toolkit::Button::Property::LABEL, mButtonLabel); } // Hide & discard the pop-up - if( mPopup ) + if(mPopup) { - mPopup.SetDisplayState( Popup::HIDDEN ); + mPopup.SetDisplayState(Popup::HIDDEN); } mField.Reset(); } - bool OnPopupTouched( Actor actor, const TouchEvent& event ) + bool OnPopupTouched(Actor actor, const TouchEvent& event) { // End edit mode for TextField if parent Popup touched. - if(event.GetPointCount() > 0) + if((event.GetPointCount() > 0) && (mPopup == event.GetHitActor(0))) { - const TouchPoint& point = event.GetPoint(0); - switch(point.state) + switch(event.GetState(0)) { - case TouchPoint::Down: + case PointState::DOWN: { // Update the folder text and lose focus for Key events - if( mButton && mField ) + if(mButton && mField) { - Property::Value text = mField.GetProperty( TextField::Property::TEXT ); - mButtonLabel = text.Get< std::string >(); - mButton.SetLabelText( mButtonLabel ); + Property::Value text = mField.GetProperty(TextField::Property::TEXT); + mButtonLabel = text.Get(); + mButton.SetProperty(Toolkit::Button::Property::LABEL, mButtonLabel); mField.ClearKeyInputFocus(); } break; @@ -186,7 +175,7 @@ public: } // end switch } - return true; + return false; } /** @@ -194,9 +183,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(); } @@ -204,32 +193,22 @@ public: } private: - Application& mApplication; // This button launches a pop-up containing TextField - PushButton mButton; + PushButton mButton; std::string mButtonLabel; // Pop-up contents TextField mField; - Popup mPopup; + Popup mPopup; }; -void RunTest( Application& application ) -{ - TextFieldExample test( application ); - - application.MainLoop(); -} - -/** Entry point for Linux & Tizen applications */ -int 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 ); - - RunTest( application ); - + Application application = Application::New(&argc, &argv); + TextFieldExample test(application); + application.MainLoop(); return 0; }