From: HyunJu Shin Date: Mon, 24 Jul 2017 02:51:07 +0000 (+0000) Subject: Merge "Line wrap mode property is added." into devel/master X-Git-Tag: dali_1.2.50~7 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=7cca1061ed3db08d2e7f511a8f6ef707e688703d;hp=6b496cacd2a596235a246c912a6b507a72d67ad4 Merge "Line wrap mode property is added." into devel/master --- diff --git a/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp b/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp index 74ac7b5..43fc5ac 100644 --- a/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp +++ b/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp @@ -281,7 +281,8 @@ void CreateTextModel( const std::string& text, charactersToGlyph.Begin(), glyphsPerCharacter.Begin(), numberOfGlyphs, - Layout::HORIZONTAL_ALIGN_BEGIN ); + Layout::HORIZONTAL_ALIGN_BEGIN, + Layout::LineWrap::WORD ); Vector& lines = visualModel->mLines; diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp index 5f08853..3f6a9a6 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp @@ -169,7 +169,8 @@ bool LayoutTextTest( const LayoutTextData& data ) visualModel->mCharactersToGlyph.Begin(), visualModel->mGlyphsPerCharacter.Begin(), totalNumberOfGlyphs, - Layout::HORIZONTAL_ALIGN_BEGIN ); + Layout::HORIZONTAL_ALIGN_BEGIN, + Layout::LineWrap::WORD ); layoutParameters.isLastNewParagraph = isLastNewParagraph; @@ -384,7 +385,8 @@ bool ReLayoutRightToLeftLinesTest( const ReLayoutRightToLeftLinesData& data ) visualModel->mCharactersToGlyph.Begin(), visualModel->mGlyphsPerCharacter.Begin(), visualModel->mGlyphs.Count(), - Layout::HORIZONTAL_ALIGN_BEGIN ); + Layout::HORIZONTAL_ALIGN_BEGIN, + Layout::LineWrap::WORD ); layoutParameters.numberOfBidirectionalInfoRuns = logicalModel->mBidirectionalLineInfo.Count(); layoutParameters.lineBidirectionalInfoRunsBuffer = logicalModel->mBidirectionalLineInfo.Begin(); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index d884271..a052525 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -2182,3 +2182,37 @@ int utcDaliTextEditorScrollStateChangedSignalTest(void) END_TEST; } +int UtcDaliToolkitTextEditorTextWarpMode(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextEditorTextWarpMode"); + + int lineCount =0 ; + + TextEditor editor = TextEditor::New(); + editor.SetSize( 150.0f, 300.f ); + editor.SetProperty( TextEditor::Property::TEXT, "Hello world Hello world" ); + + Stage::GetCurrent().Add( editor ); + + editor.SetProperty( DevelTextEditor::Property::LINE_WRAP_MODE, "WORD" ); + + application.SendNotification(); + application.Render(); + + lineCount = editor.GetProperty( DevelTextEditor::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 4, TEST_LOCATION ); + + + + editor.SetProperty( DevelTextEditor::Property::LINE_WRAP_MODE, "CHARACTER" ); + + application.SendNotification(); + application.Render(); + + + lineCount = editor.GetProperty( DevelTextEditor::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 3, TEST_LOCATION ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 4e1fd0f..6972fb1 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -920,3 +920,42 @@ int UtcDaliToolkitTextlabelEllipsis(void) END_TEST; } + +int UtcDaliToolkitTextlabelTextWarpMode(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextlabelTextWarpMode"); + + int lineCount =0 ; + + TextLabel label = TextLabel::New(); + label.SetSize( 300.0f, 300.f ); + label.SetProperty( TextLabel::Property::TEXT, "Hello world Hello world" ); + label.SetProperty( TextLabel::Property::MULTI_LINE, true ); + + + + //label.SetProperty( TextLabel::Property::POINT_SIZE, 18 ); + Stage::GetCurrent().Add( label ); + + label.SetProperty( DevelTextLabel::Property::LINE_WRAP_MODE, "WRAP_MODE_WORD" ); + + application.SendNotification(); + application.Render(); + + lineCount = label.GetProperty( DevelTextLabel::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 4, TEST_LOCATION ); + + + + label.SetProperty( DevelTextLabel::Property::LINE_WRAP_MODE, "WRAP_MODE_CHARACTER" ); + + application.SendNotification(); + application.Render(); + + + lineCount = label.GetProperty( DevelTextLabel::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 3, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h index b2dc43a..50f6af5 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -161,7 +161,13 @@ namespace Property * * @details name "placeholder", type MAP */ - PLACEHOLDER + PLACEHOLDER, + + /** + * @brief line wrap mode when the text lines over layout width. + * @details name "lineWrapMode", type string. + */ + LINE_WRAP_MODE }; } // namespace Property diff --git a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h index 2721dc1..2b53fc5 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-label-devel.h @@ -92,7 +92,13 @@ namespace Property * @details name "lineCount", type int * @node this property is read-only. */ - LINE_COUNT = OUTLINE + 5 + LINE_COUNT = OUTLINE + 5, + + /** + * @brief line wrap mode when the text lines over layout width. + * @details name "lineWrapMode", type string. + */ + LINE_WRAP_MODE = OUTLINE + 6 }; } // namespace Property diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index e763f2c..ccddda5 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -76,6 +76,14 @@ const Scripting::StringEnum HORIZONTAL_ALIGNMENT_STRING_TABLE[] = }; const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] ); + +const Scripting::StringEnum LINE_WRAP_MODE_STRING_TABLE[] = +{ + { "WORD", Toolkit::Text::Layout::LineWrap::WORD }, + { "CHARACTER", Toolkit::Text::Layout::LineWrap::CHARACTER } +}; +const unsigned int LINE_WRAP_MODE_STRING_TABLE_COUNT = sizeof( LINE_WRAP_MODE_STRING_TABLE ) / sizeof( LINE_WRAP_MODE_STRING_TABLE[0] ); + const char* const SCROLL_BAR_POSITION("sourcePosition"); const char* const SCROLL_BAR_POSITION_MIN("sourcePositionMin"); const char* const SCROLL_BAR_POSITION_MAX("sourcePositionMax"); @@ -141,6 +149,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderText", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableSelection", BOOLEAN, ENABLE_SELECTION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholder", MAP, PLACEHOLDER ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineWrapMode", STRING, LINE_WRAP_MODE ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -712,6 +721,21 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } break; } + case Toolkit::DevelTextEditor::Property::LINE_WRAP_MODE: + { + const std::string& wrapModeStr = value.Get< std::string >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p LINE_WRAP_MODE %s\n", impl.mController.Get(), wrapModeStr.c_str() ); + + Layout::LineWrap::Mode lineWrapMode( Layout::LineWrap::WORD ); + if( Scripting::GetEnumeration< Layout::LineWrap::Mode >( wrapModeStr.c_str(), + LINE_WRAP_MODE_STRING_TABLE, + LINE_WRAP_MODE_STRING_TABLE_COUNT, + lineWrapMode ) ) + { + impl.mController->SetLineWrapMode( lineWrapMode ); + } + break; + } } // switch } // texteditor } @@ -1088,6 +1112,13 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind value = map; break; } + case Toolkit::DevelTextEditor::Property::LINE_WRAP_MODE: + { + if( impl.mController ) + { + value = impl.mController->GetLineWrapMode(); + } + } } //switch } diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp index 784a5c8..f484bbf 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -81,6 +81,13 @@ const Scripting::StringEnum VERTICAL_ALIGNMENT_STRING_TABLE[] = }; const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] ); +const Scripting::StringEnum LINE_WRAP_MODE_STRING_TABLE[] = +{ + { "WRAP_MODE_WORD", Toolkit::Text::Layout::LineWrap::WORD }, + { "WRAP_MODE_CHARACTER", Toolkit::Text::Layout::LineWrap::CHARACTER } +}; +const unsigned int LINE_WRAP_MODE_STRING_TABLE_COUNT = sizeof( LINE_WRAP_MODE_STRING_TABLE ) / sizeof( LINE_WRAP_MODE_STRING_TABLE[0] ); + // Type registration BaseHandle Create() { @@ -119,6 +126,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", BOO DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE ) DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", STRING, LINE_WRAP_MODE ) DALI_TYPE_REGISTRATION_END() @@ -486,6 +494,21 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr } break; } + case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE: + { + const std::string& wrapModeStr = value.Get< std::string >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LINE_WRAP_MODE %s\n", impl.mController.Get(), wrapModeStr.c_str() ); + + Layout::LineWrap::Mode lineWrapMode( Layout::LineWrap::WORD ); + if( Scripting::GetEnumeration< Layout::LineWrap::Mode >( wrapModeStr.c_str(), + LINE_WRAP_MODE_STRING_TABLE, + LINE_WRAP_MODE_STRING_TABLE_COUNT, + lineWrapMode ) ) + { + impl.mController->SetLineWrapMode( lineWrapMode ); + } + break; + } } } } @@ -737,6 +760,14 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde } break; } + case Toolkit::DevelTextLabel::Property::LINE_WRAP_MODE: + { + if( impl.mController ) + { + value = impl.mController->GetLineWrapMode(); + } + break; + } case Toolkit::DevelTextLabel::Property::LINE_COUNT: { if( impl.mController ) diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index 17e9f58..12f20e4 100644 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -198,6 +198,7 @@ struct Engine::Impl LineLayout tmpLineLayout; const bool isMultiline = mLayout == MULTI_LINE_BOX; + const bool isWordLaidOut = parameters.lineWrapMode == Layout::LineWrap::WORD; // The last glyph to be laid-out. const GlyphIndex lastGlyphOfParagraphPlusOne = parameters.startGlyphIndex + parameters.numberOfGlyphs; @@ -447,7 +448,7 @@ struct Engine::Impl if( isMultiline && ( TextAbstraction::WORD_BREAK == wordBreakInfo ) ) { - oneWordLaidOut = true; + oneWordLaidOut = isWordLaidOut; DALI_LOG_INFO( gLogFilter, Debug::Verbose, " One word laid-out\n" ); // Current glyph is the last one of the current word. diff --git a/dali-toolkit/internal/text/layouts/layout-parameters.h b/dali-toolkit/internal/text/layouts/layout-parameters.h index f62191f..fa33087 100644 --- a/dali-toolkit/internal/text/layouts/layout-parameters.h +++ b/dali-toolkit/internal/text/layouts/layout-parameters.h @@ -23,6 +23,7 @@ // INTERNAL INCLUDES #include +#include namespace Dali { @@ -58,6 +59,7 @@ struct Parameters * @param[in] glyphsPerCharacterBuffer Vector with the number of glyphs shaped from the character. * @param[in] totalNumberOfGlyphs The number of glyphs. * @param[in] horizontalAlignment The horizontal alignment. + * @param[in] lineWrapMode The text wrap mode. */ Parameters( const Vector2& boundingBox, const Character* const textBuffer, @@ -70,7 +72,8 @@ struct Parameters const GlyphIndex* const charactersToGlyphsBuffer, const Length* const glyphsPerCharacterBuffer, Length totalNumberOfGlyphs, - HorizontalAlignment horizontalAlignment ) + HorizontalAlignment horizontalAlignment, + LineWrap::Mode lineWrapMode ) : boundingBox( boundingBox ), textBuffer( textBuffer ), lineBreakInfoBuffer( lineBreakInfoBuffer ), @@ -89,6 +92,7 @@ struct Parameters horizontalAlignment( horizontalAlignment ), startLineIndex( 0u ), estimatedNumberOfLines( 0u ), + lineWrapMode( lineWrapMode ), isLastNewParagraph( false ) {} @@ -110,6 +114,7 @@ struct Parameters HorizontalAlignment horizontalAlignment; ///< The horizontal alignment. LineIndex startLineIndex; ///< The line index where to insert the new lines. Length estimatedNumberOfLines; ///< The estimated number of lines. + LineWrap::Mode lineWrapMode; ///< The line wrap mode for moving to next line. bool isLastNewParagraph; ///< Whether the last character is a new paragraph character. }; diff --git a/dali-toolkit/internal/text/layouts/layout-wrap-mode.h b/dali-toolkit/internal/text/layouts/layout-wrap-mode.h new file mode 100644 index 0000000..1e313fd --- /dev/null +++ b/dali-toolkit/internal/text/layouts/layout-wrap-mode.h @@ -0,0 +1,68 @@ +#ifndef DALI_TOOLKIT_TEXT_LAYOUT_WRAPMODE_H +#define DALI_TOOLKIT_TEXT_LAYOUT_WRAPMODE_H + +/* + * Copyright (c) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace Dali +{ + +namespace Toolkit +{ + +namespace Text +{ + +namespace Layout +{ + +/** + * @brief Unit of wrapping for moving to next line + * + * If layout width too short to show full text, + * WRAP_MODE_WORD mode will move word to next line, + * +---------+ + * |HELLO | + * |WORLLD | + * +---------+ + * + * but WRAP_MODE_CHARACTER mode will move character by character to next line + * +---------+ + * |HELLO WOR| + * |LD | + * +---------+ + */ + +namespace LineWrap { + +enum Mode +{ + WORD, + CHARACTER +}; + +} // namespace LineWrap + +} // namespace Layout + +} // namespace Text + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_TEXT_LAYOUT_WRAPMODE_H diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index fbd26bf..feb620b 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -392,6 +392,34 @@ Layout::VerticalAlignment Controller::GetVerticalAlignment() const return mImpl->mModel->mVerticalAlignment; } +void Controller::SetLineWrapMode( Layout::LineWrap::Mode lineWrapMode ) +{ + if( lineWrapMode != mImpl->mModel->mLineWrapMode ) + { + // Set the text wrap mode. + mImpl->mModel->mLineWrapMode = lineWrapMode; + + + // Update Text layout for applying wrap mode + mImpl->mOperationsPending = static_cast( mImpl->mOperationsPending | + ALIGN | + LAYOUT | + UPDATE_LAYOUT_SIZE | + REORDER ); + mImpl->mTextUpdateInfo.mCharacterIndex = 0u; + mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters; + mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count(); + + // Request relayout + mImpl->RequestRelayout(); + } +} + +Layout::LineWrap::Mode Controller::GetLineWrapMode() const +{ + return mImpl->mModel->mLineWrapMode; +} + void Controller::SetTextElideEnabled( bool enabled ) { mImpl->mModel->mElideEnabled = enabled; @@ -3195,7 +3223,8 @@ bool Controller::DoRelayout( const Size& size, charactersToGlyphBuffer, glyphsPerCharacterBuffer, totalNumberOfGlyphs, - mImpl->mModel->mHorizontalAlignment ); + mImpl->mModel->mHorizontalAlignment, + mImpl->mModel->mLineWrapMode ); // Resize the vector of positions to have the same size than the vector of glyphs. Vector& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions; diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 3d7639d..aeee224 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -26,9 +26,11 @@ #include #include #include +#include #include #include + namespace Dali { @@ -343,6 +345,18 @@ public: // Configure the text controller. Layout::VerticalAlignment GetVerticalAlignment() const; /** + * @brief Sets the text's wrap mode + * @param[in] text wrap mode The unit of wrapping + */ + void SetLineWrapMode( Layout::LineWrap::Mode textWarpMode ); + + /** + * @brief Retrieve text wrap mode previously set. + * @return text wrap mode + */ + Layout::LineWrap::Mode GetLineWrapMode() const; + + /** * @brief Enable or disable the text elide. * * @param[in] enabled Whether to enable the text elide. diff --git a/dali-toolkit/internal/text/text-model.cpp b/dali-toolkit/internal/text/text-model.cpp index 7eae0e1..f158dae 100644 --- a/dali-toolkit/internal/text/text-model.cpp +++ b/dali-toolkit/internal/text/text-model.cpp @@ -109,6 +109,7 @@ Model::Model() mScrollPositionLast(), mHorizontalAlignment( Layout::HORIZONTAL_ALIGN_BEGIN ), mVerticalAlignment( Layout::VERTICAL_ALIGN_TOP ), + mLineWrapMode( Layout::LineWrap::WORD ), mAlignmentOffset( 0.0f ), mElideEnabled( false ) { diff --git a/dali-toolkit/internal/text/text-model.h b/dali-toolkit/internal/text/text-model.h index 26b9f08..418989a 100644 --- a/dali-toolkit/internal/text/text-model.h +++ b/dali-toolkit/internal/text/text-model.h @@ -23,6 +23,7 @@ // INTERNAL INCLUDES #include +#include #include #include #include @@ -159,6 +160,7 @@ public: Vector2 mScrollPositionLast; ///< The last offset value of mScrollPosition Layout::HorizontalAlignment mHorizontalAlignment; ///< The layout's horizontal alignment. Layout::VerticalAlignment mVerticalAlignment; ///< The layout's vertical alignment. + Layout::LineWrap::Mode mLineWrapMode; ///< The text wrap mode float mAlignmentOffset; ///< The alignment offset. bool mElideEnabled:1; ///< Whether the text's elide is enabled. };