X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Ftext-field%2Ftext-field-example.cpp;h=84153e622589b78a68e9eb0c9cd01220f68a263f;hb=0efc4e729b2c12240d9d68f5df1929494685fb7f;hp=a9ea8cbbc84e35bff93614f304b27f7d1d0cf0f1;hpb=8a61f04a9bf4241761bda7742918967f34de2891;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 a9ea8cb..84153e6 100644 --- a/examples/text-field/text-field-example.cpp +++ b/examples/text-field/text-field-example.cpp @@ -22,18 +22,25 @@ // EXTERNAL INCLUDES #include -#include +#include +#include +#include // INTERNAL INCLUDES -#include "edit-layout.h" +#include "shared/multi-language-strings.h" +#include "shared/view.h" using namespace Dali; using namespace Dali::Toolkit; +using namespace MultiLanguageStrings; namespace { -const float BORDER_WIDTH = 4.0f; + 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; } // unnamed namespace @@ -63,26 +70,122 @@ public: { Stage stage = Stage::GetCurrent(); + stage.SetBackgroundColor( Vector4( 0.04f, 0.345f, 0.392f, 1.0f ) ); stage.KeyEventSignal().Connect(this, &TextFieldExample::OnKeyEvent); + // Hide the indicator bar + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); + + 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 ); + ImageDimensions imageSize = ResourceImage::GetImageSize( FOLDER_ICON_IMAGE ); + button.SetSize( imageSize.GetWidth(), imageSize.GetHeight() ); + + return button; + } + + bool OnButtonClicked( Toolkit::Button button ) + { + Stage stage = Stage::GetCurrent(); Vector2 stageSize = stage.GetSize(); - EditLayout layout = EditLayout::New(); - layout.SetParentOrigin( ParentOrigin::CENTER ); - layout.SetAnchorPoint( AnchorPoint::CENTER ); - layout.SetSize( stageSize.width - BORDER_WIDTH*2.0f, stageSize.height*0.2f ); - stage.Add( layout ); + // Remove previously hidden pop-up + UnparentAndReset(mPopup); + + // Launch a pop-up containing TextField + mField = CreateTextField( stageSize, mButtonLabel ); + mPopup = CreatePopup(); + 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.SetParentOrigin( ParentOrigin::CENTER ); - field.SetBackgroundColor( Color::BLACK ); - layout.SetTopPanel( field ); + 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 ) ); + + return field; + } - field.SetProperty( TextField::PROPERTY_TEXT, "A Quick Brown Fox Jumps Over The Lazy Dog" ); + Popup CreatePopup() + { + Popup popup = Popup::New(); + popup.SetParentOrigin( ParentOrigin::CENTER ); + popup.SetAnchorPoint( AnchorPoint::CENTER ); + popup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::WIDTH ); + popup.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT ); + popup.TouchSignal().Connect( this, &TextFieldExample::OnPopupTouched ); + + return popup; + } - // TODO - //Property::Value fieldText = field.GetProperty( TextField::PROPERTY_TEXT ); - //std::cout << "Got text from field: " << fieldText.Get< std::string >() << std::endl; + 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 ); + } + + // Hide & discard the pop-up + if( mPopup ) + { + mPopup.SetDisplayState( Popup::HIDDEN ); + } + mField.Reset(); + } + + bool OnPopupTouched( Actor actor, const TouchData& event ) + { + // End edit mode for TextField if parent Popup touched. + if(event.GetPointCount() > 0) + { + switch( event.GetState( 0 ) ) + { + case PointState::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; } /** @@ -102,6 +205,14 @@ public: private: Application& mApplication; + + // This button launches a pop-up containing TextField + PushButton mButton; + std::string mButtonLabel; + + // Pop-up contents + TextField mField; + Popup mPopup; }; void RunTest( Application& application ) @@ -112,8 +223,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 );