X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Ftext-field%2Ftext-field-example.cpp;h=8b611b2916a5ec6e1e9aab0db7f34fe02c1fd934;hb=7374f93dc7855f4cc263601215c84aea8f7d276b;hp=dfcd06a1187b8b31692afddc7d825722bb24a237;hpb=3616ba1d6b9a38906fd15cf1512d457f2989af42;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 dfcd06a..8b611b2 100644 --- a/examples/text-field/text-field-example.cpp +++ b/examples/text-field/text-field-example.cpp @@ -22,20 +22,27 @@ // EXTERNAL INCLUDES #include -#include +#include +#include +#include // INTERNAL INCLUDES +#include "shared/multi-language-strings.h" #include "shared/view.h" using namespace Dali; using namespace Dali::Toolkit; +using namespace MultiLanguageStrings; namespace { -const char* const BACKGROUND_IMAGE = DALI_IMAGE_DIR "button-up.9.png"; + 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 float BORDER_WIDTH = 4.0f; + const float BORDER_WIDTH = 4.0f; + + const Vector3 POPUP_SIZE_FACTOR_TO_PARENT = Vector3( 0.0, 0.25, 0.0 ); } // unnamed namespace @@ -63,35 +70,123 @@ public: */ void Create( Application& application ) { - DemoHelper::RequestThemeChange(); - Stage stage = Stage::GetCurrent(); + stage.SetBackgroundColor( Vector4( 0.04f, 0.345f, 0.392f, 1.0f ) ); stage.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent); + mButton = CreateFolderButton(); + mButton.ClickedSignal().Connect( this, &TextFieldExample::OnButtonClicked ); + stage.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() ); + + return button; + } + + bool OnButtonClicked( Toolkit::Button button ) + { + Stage stage = Stage::GetCurrent(); Vector2 stageSize = stage.GetSize(); - mContainer = Control::New(); - mContainer.SetName( "Container" ); - mContainer.SetParentOrigin( ParentOrigin::CENTER ); - mContainer.SetSize( Vector2(stageSize.width*0.6f, stageSize.width*0.6f) ); - mContainer.SetBackgroundImage( ResourceImage::New( BACKGROUND_IMAGE ) ); - mContainer.GetChildAt(0).SetZ(-1.0f); - stage.Add( mContainer ); + // 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 ); + + return true; + } + TextField CreateTextField( const Vector2& stageSize, const std::string& text ) + { TextField field = TextField::New(); + field.SetName("textField"); 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 ) ); - mContainer.Add( field ); + return field; + } - field.SetProperty( TextField::Property::TEXT, "Hello" ); - field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect( BORDER_WIDTH, BORDER_WIDTH, stageSize.width - BORDER_WIDTH*2, stageSize.height - BORDER_WIDTH*2 ) ); + Popup CreatePopup( float width ) + { + 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 ); + + return popup; + } - Property::Value fieldText = field.GetProperty( TextField::Property::TEXT ); + void OnPopupOutsideTouched() + { + // Update the folder text + if( mButton && mField ) + { + Property::Value text = mField.GetProperty( TextField::Property::TEXT ); + mButtonLabel = text.Get< std::string >(); + mButton.SetLabelText( mButtonLabel ); + } - std::cout << "Displaying text: " << fieldText.Get< std::string >() << std::endl; + // Hide & discard the pop-up + if( mPopup ) + { + mPopup.SetDisplayState( Popup::HIDDEN ); + } + mField.Reset(); + } + + bool OnPopupTouched( Actor actor, const TouchEvent& event ) + { + // End edit mode for TextField if parent Popup touched. + if(event.GetPointCount() > 0) + { + const TouchPoint& point = event.GetPoint(0); + switch(point.state) + { + case TouchPoint::Down: + { + // Update the folder text and lose focus for Key events + if( mButton && mField ) + { + Property::Value text = mField.GetProperty( TextField::Property::TEXT ); + mButtonLabel = text.Get< std::string >(); + mButton.SetLabelText( mButtonLabel ); + mField.ClearKeyInputFocus(); + } + break; + } + default: + { + break; + } + } // end switch + } + + return true; } /** @@ -112,7 +207,13 @@ private: Application& mApplication; - Control mContainer; + // This button launches a pop-up containing TextField + PushButton mButton; + std::string mButtonLabel; + + // Pop-up contents + TextField mField; + Popup mPopup; }; void RunTest( Application& application ) @@ -123,8 +224,9 @@ void RunTest( Application& application ) } /** 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 );