From f2a6a134e4b939815b40f417f5aca61a6fccf92e Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Fri, 6 Oct 2017 11:16:20 +0100 Subject: [PATCH] Added enumerations for LineWrap::Mode Change-Id: I96cb55032a73beabf195e2ec2730be801f7a74d8 --- .../dali-toolkit-test-utils/toolkit-text-utils.cpp | 4 +- .../dali-toolkit-internal/utc-Dali-Text-Layout.cpp | 6 +- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 22 ++++- .../src/dali-toolkit/utc-Dali-TextLabel.cpp | 24 ++++- .../controls/text-controls/text-editor-impl.cpp | 34 +++---- .../controls/text-controls/text-field-impl.cpp | 24 ++--- .../controls/text-controls/text-label-impl.cpp | 44 ++++----- .../internal/text/layouts/layout-engine.cpp | 4 +- .../internal/text/layouts/layout-parameters.h | 7 +- .../internal/text/layouts/layout-wrap-mode.h | 68 ------------- dali-toolkit/internal/text/text-controller.cpp | 4 +- dali-toolkit/internal/text/text-controller.h | 5 +- .../internal/text/text-enumerations-impl.cpp | 27 ++++-- .../internal/text/text-enumerations-impl.h | 21 +++-- dali-toolkit/internal/text/text-model.cpp | 6 +- dali-toolkit/internal/text/text-model.h | 3 +- dali-toolkit/internal/visuals/text/text-visual.cpp | 24 +++-- .../controls/text-controls/text-editor.h | 7 +- .../public-api/controls/text-controls/text-label.h | 5 +- dali-toolkit/public-api/text/text-enumerations.h | 105 +++++++++++++++------ 20 files changed, 231 insertions(+), 213 deletions(-) delete mode 100644 dali-toolkit/internal/text/layouts/layout-wrap-mode.h 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 3758b47..1c844c5 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * 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. @@ -282,7 +282,7 @@ void CreateTextModel( const std::string& text, glyphsPerCharacter.Begin(), numberOfGlyphs, Text::HorizontalAlignment::BEGIN, - Layout::LineWrap::WORD ); + Text::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 50090ee..f6c58db 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * 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. @@ -170,7 +170,7 @@ bool LayoutTextTest( const LayoutTextData& data ) visualModel->mGlyphsPerCharacter.Begin(), totalNumberOfGlyphs, Text::HorizontalAlignment::BEGIN, - Layout::LineWrap::WORD ); + Text::LineWrap::WORD ); layoutParameters.isLastNewParagraph = isLastNewParagraph; @@ -386,7 +386,7 @@ bool ReLayoutRightToLeftLinesTest( const ReLayoutRightToLeftLinesData& data ) visualModel->mGlyphsPerCharacter.Begin(), visualModel->mGlyphs.Count(), Text::HorizontalAlignment::BEGIN, - Layout::LineWrap::WORD ); + Text::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 9b2b6f7..d93a39e 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -2215,7 +2215,8 @@ int utcDaliTextEditorScrollStateChangedSignalTest(void) END_TEST; } -int UtcDaliToolkitTextEditorTextWarpMode(void) + +int UtcDaliToolkitTextEditorTextWrapMode(void) { ToolkitTestApplication application; tet_infoline(" UtcDaliToolkitTextEditorTextWarpMode"); @@ -2229,6 +2230,7 @@ int UtcDaliToolkitTextEditorTextWarpMode(void) Stage::GetCurrent().Add( editor ); editor.SetProperty( TextEditor::Property::LINE_WRAP_MODE, "WORD" ); + DALI_TEST_EQUALS( editor.GetProperty< int >( TextEditor::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::WORD ), TEST_LOCATION ); application.SendNotification(); application.Render(); @@ -2236,13 +2238,29 @@ int UtcDaliToolkitTextEditorTextWarpMode(void) lineCount = editor.GetProperty( TextEditor::Property::LINE_COUNT ); DALI_TEST_EQUALS( lineCount, 4, TEST_LOCATION ); + editor.SetProperty( TextEditor::Property::LINE_WRAP_MODE, "CHARACTER" ); + DALI_TEST_EQUALS( editor.GetProperty< int >( TextEditor::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::CHARACTER ), TEST_LOCATION ); + application.SendNotification(); + application.Render(); - editor.SetProperty( TextEditor::Property::LINE_WRAP_MODE, "CHARACTER" ); + lineCount = editor.GetProperty( TextEditor::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 3, TEST_LOCATION ); + + editor.SetProperty( TextEditor::Property::LINE_WRAP_MODE, Text::LineWrap::WORD ); + DALI_TEST_EQUALS( editor.GetProperty< int >( TextEditor::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::WORD ), TEST_LOCATION ); application.SendNotification(); application.Render(); + lineCount = editor.GetProperty( TextEditor::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 4, TEST_LOCATION ); + + editor.SetProperty( TextEditor::Property::LINE_WRAP_MODE, Text::LineWrap::CHARACTER ); + DALI_TEST_EQUALS( editor.GetProperty< int >( TextEditor::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::CHARACTER ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); lineCount = editor.GetProperty( TextEditor::Property::LINE_COUNT ); DALI_TEST_EQUALS( lineCount, 3, TEST_LOCATION ); diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 846446b..5471c95 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -954,7 +954,7 @@ int UtcDaliToolkitTextlabelEllipsis(void) END_TEST; } -int UtcDaliToolkitTextlabelTextWarpMode(void) +int UtcDaliToolkitTextlabelTextWrapMode(void) { ToolkitTestApplication application; tet_infoline(" UtcDaliToolkitTextlabelTextWarpMode"); @@ -971,7 +971,8 @@ int UtcDaliToolkitTextlabelTextWarpMode(void) //label.SetProperty( TextLabel::Property::POINT_SIZE, 18 ); Stage::GetCurrent().Add( label ); - label.SetProperty( TextLabel::Property::LINE_WRAP_MODE, "WRAP_MODE_WORD" ); + label.SetProperty( TextLabel::Property::LINE_WRAP_MODE, "WORD" ); + DALI_TEST_EQUALS( label.GetProperty< int >( TextLabel::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::WORD ), TEST_LOCATION ); application.SendNotification(); application.Render(); @@ -979,17 +980,34 @@ int UtcDaliToolkitTextlabelTextWarpMode(void) lineCount = label.GetProperty( TextLabel::Property::LINE_COUNT ); DALI_TEST_EQUALS( lineCount, 4, TEST_LOCATION ); + label.SetProperty( TextLabel::Property::LINE_WRAP_MODE, "CHARACTER" ); + DALI_TEST_EQUALS( label.GetProperty< int >( TextLabel::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::CHARACTER ), TEST_LOCATION ); + application.SendNotification(); + application.Render(); - label.SetProperty( TextLabel::Property::LINE_WRAP_MODE, "WRAP_MODE_CHARACTER" ); + label.SetProperty( TextLabel::Property::LINE_WRAP_MODE, Text::LineWrap::WORD ); + DALI_TEST_EQUALS( label.GetProperty< int >( TextLabel::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::WORD ), TEST_LOCATION ); application.SendNotification(); application.Render(); + lineCount = label.GetProperty( TextLabel::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 4, TEST_LOCATION ); + + label.SetProperty( TextLabel::Property::LINE_WRAP_MODE, Text::LineWrap::CHARACTER ); + DALI_TEST_EQUALS( label.GetProperty< int >( TextLabel::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::CHARACTER ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); lineCount = label.GetProperty( TextLabel::Property::LINE_COUNT ); DALI_TEST_EQUALS( lineCount, 3, TEST_LOCATION ); + tet_infoline( "Ensure invalid string does not change wrapping mode" ); + label.SetProperty( TextLabel::Property::LINE_WRAP_MODE, "InvalidWrapMode" ); + DALI_TEST_EQUALS( label.GetProperty< int >( TextLabel::Property::LINE_WRAP_MODE ), static_cast< int >( Text::LineWrap::CHARACTER ), TEST_LOCATION ); + END_TEST; } 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 c719798..638cf37 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -69,13 +69,6 @@ const float DEFAULT_SCROLL_SPEED = 1200.f; ///< The default scroll speed for the namespace { -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"); @@ -139,7 +132,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "pixelSize", DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "lineCount", INTEGER, LINE_COUNT ) DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableSelection", BOOLEAN, ENABLE_SELECTION ) DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholder", MAP, PLACEHOLDER ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineWrapMode", STRING, LINE_WRAP_MODE ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextEditor, "lineWrapMode", INTEGER, LINE_WRAP_MODE ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderText", STRING, PLACEHOLDER_TEXT ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "placeholderTextColor", VECTOR4, PLACEHOLDER_TEXT_COLOR ) @@ -251,13 +244,10 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P { if( impl.mController ) { - const std::string& alignStr = value.Get< std::string >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() ); - - Text::HorizontalAlignment::Type alignment( Text::HorizontalAlignment::BEGIN ); - - Text::GetHorizontalAlignmentEnum( value, alignment ); + Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) ) { + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment ); impl.mController->SetHorizontalAlignment( alignment ); } } @@ -713,16 +703,14 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } case Toolkit::TextEditor::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 ) ) + if( impl.mController ) { - impl.mController->SetLineWrapMode( lineWrapMode ); + Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( GetLineWrapModeEnumeration( value, lineWrapMode ) ) + { + DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode ); + impl.mController->SetLineWrapMode( lineWrapMode ); + } } break; } diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 73a733c..0961fa1 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -281,12 +281,12 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr { if( impl.mController ) { - const std::string& alignStr = value.Get< std::string >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() ); - - Text::HorizontalAlignment::Type alignment( Text::HorizontalAlignment::BEGIN ); - GetHorizontalAlignmentEnum( value, alignment ); - impl.mController->SetHorizontalAlignment( alignment ); + Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( GetHorizontalAlignmentEnumeration( value, alignment ) ) + { + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p HORIZONTAL_ALIGNMENT %d\n", impl.mController.Get(), alignment ); + impl.mController->SetHorizontalAlignment( alignment ); + } } break; } @@ -294,12 +294,12 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr { if( impl.mController ) { - const std::string& alignStr = value.Get< std::string >(); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %s\n", impl.mController.Get(), alignStr.c_str() ); - - Text::VerticalAlignment::Type alignment( Text::VerticalAlignment::BOTTOM ); - GetVerticalAlignmentEnum( value, alignment ); - impl.mController->SetVerticalAlignment( alignment ); + Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( GetVerticalAlignmentEnumeration( value, alignment ) ) + { + impl.mController->SetVerticalAlignment( alignment ); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment ); + } } break; } 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 75518d1..5a958d4 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -73,13 +73,6 @@ const Scripting::StringEnum AUTO_SCROLL_STOP_MODE_TABLE[] = }; const unsigned int AUTO_SCROLL_STOP_MODE_TABLE_COUNT = sizeof( AUTO_SCROLL_STOP_MODE_TABLE ) / sizeof( AUTO_SCROLL_STOP_MODE_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() { @@ -118,7 +111,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "ellipsis", DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLOAT, AUTO_SCROLL_LOOP_DELAY ) DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode", STRING, AUTO_SCROLL_STOP_MODE ) DALI_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT ) -DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", STRING, LINE_WRAP_MODE ) +DALI_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode", INTEGER, LINE_WRAP_MODE ) DALI_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColor", Color::BLACK, TEXT_COLOR ) DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorRed", TEXT_COLOR_RED, TEXT_COLOR, 0 ) DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, TextLabel, "textColorGreen", TEXT_COLOR_GREEN, TEXT_COLOR, 1 ) @@ -227,11 +220,11 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr { if( impl.mController ) { - Toolkit::Text::HorizontalAlignment::Type alignment( Toolkit::Text::HorizontalAlignment::BEGIN ); - Text::GetHorizontalAlignmentEnum( value, alignment ); - - impl.mController->SetHorizontalAlignment( alignment ); - + Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( Text::GetHorizontalAlignmentEnumeration( value, alignment ) ) + { + impl.mController->SetHorizontalAlignment( alignment ); + } } break; } @@ -239,10 +232,11 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr { if( impl.mController ) { - Toolkit::Text::VerticalAlignment::Type alignment( Toolkit::Text::VerticalAlignment::BOTTOM ); - Text::GetVerticalAlignmentEnum( value, alignment ); - - impl.mController->SetVerticalAlignment( alignment ); + Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( Text::GetVerticalAlignmentEnumeration( value, alignment ) ) + { + impl.mController->SetVerticalAlignment( alignment ); + } } break; } @@ -480,16 +474,14 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr } case Toolkit::TextLabel::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 ) ) + if( impl.mController ) { - impl.mController->SetLineWrapMode( lineWrapMode ); + Text::LineWrap::Mode lineWrapMode( static_cast< Text::LineWrap::Mode >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( GetLineWrapModeEnumeration( value, lineWrapMode ) ) + { + DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel %p LineWrap::MODE %d\n", impl.mController.Get(), lineWrapMode ); + impl.mController->SetLineWrapMode( lineWrapMode ); + } } break; } diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index 704c9ed..3e633ba 100644 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * 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. @@ -198,7 +198,7 @@ struct Engine::Impl LineLayout tmpLineLayout; const bool isMultiline = mLayout == MULTI_LINE_BOX; - const bool isWordLaidOut = parameters.lineWrapMode == Layout::LineWrap::WORD; + const bool isWordLaidOut = parameters.lineWrapMode == Text::LineWrap::WORD; // The last glyph to be laid-out. const GlyphIndex lastGlyphOfParagraphPlusOne = parameters.startGlyphIndex + parameters.numberOfGlyphs; diff --git a/dali-toolkit/internal/text/layouts/layout-parameters.h b/dali-toolkit/internal/text/layouts/layout-parameters.h index 5deb666..47aed0e 100644 --- a/dali-toolkit/internal/text/layouts/layout-parameters.h +++ b/dali-toolkit/internal/text/layouts/layout-parameters.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_TEXT_LAYOUT_PARAMETERS_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * 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. @@ -24,7 +24,6 @@ // INTERNAL INCLUDES #include #include -#include namespace Dali { @@ -74,7 +73,7 @@ struct Parameters const Length* const glyphsPerCharacterBuffer, Length totalNumberOfGlyphs, Text::HorizontalAlignment::Type horizontalAlignment, - LineWrap::Mode lineWrapMode ) + Text::LineWrap::Mode lineWrapMode ) : boundingBox( boundingBox ), textBuffer( textBuffer ), lineBreakInfoBuffer( lineBreakInfoBuffer ), @@ -115,7 +114,7 @@ struct Parameters HorizontalAlignment::Type 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. + Text::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 deleted file mode 100644 index 1e313fd..0000000 --- a/dali-toolkit/internal/text/layouts/layout-wrap-mode.h +++ /dev/null @@ -1,68 +0,0 @@ -#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 df15cad..99e031a 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -393,7 +393,7 @@ VerticalAlignment::Type Controller::GetVerticalAlignment() const return mImpl->mModel->mVerticalAlignment; } -void Controller::SetLineWrapMode( Layout::LineWrap::Mode lineWrapMode ) +void Controller::SetLineWrapMode( Text::LineWrap::Mode lineWrapMode ) { if( lineWrapMode != mImpl->mModel->mLineWrapMode ) { @@ -416,7 +416,7 @@ void Controller::SetLineWrapMode( Layout::LineWrap::Mode lineWrapMode ) } } -Layout::LineWrap::Mode Controller::GetLineWrapMode() const +Text::LineWrap::Mode Controller::GetLineWrapMode() const { return mImpl->mModel->mLineWrapMode; } diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 6b7505d..e2baa22 100755 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -348,13 +347,13 @@ public: // Configure the text controller. * @brief Sets the text's wrap mode * @param[in] text wrap mode The unit of wrapping */ - void SetLineWrapMode( Layout::LineWrap::Mode textWarpMode ); + void SetLineWrapMode( Text::LineWrap::Mode textWarpMode ); /** * @brief Retrieve text wrap mode previously set. * @return text wrap mode */ - Layout::LineWrap::Mode GetLineWrapMode() const; + Text::LineWrap::Mode GetLineWrapMode() const; /** * @brief Enable or disable the text elide. diff --git a/dali-toolkit/internal/text/text-enumerations-impl.cpp b/dali-toolkit/internal/text/text-enumerations-impl.cpp index 8dc3eb8..ce1c503 100644 --- a/dali-toolkit/internal/text/text-enumerations-impl.cpp +++ b/dali-toolkit/internal/text/text-enumerations-impl.cpp @@ -36,35 +36,43 @@ namespace Text namespace { DALI_ENUM_TO_STRING_TABLE_BEGIN( HORIZONTAL_ALIGNMENT_TYPE ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::HorizontalAlignment::Type, BEGIN ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::HorizontalAlignment::Type, CENTER ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::HorizontalAlignment::Type, END ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::HorizontalAlignment, BEGIN ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::HorizontalAlignment, CENTER ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::HorizontalAlignment, END ) DALI_ENUM_TO_STRING_TABLE_END( HORIZONTAL_ALIGNMENT_TYPE ) DALI_ENUM_TO_STRING_TABLE_BEGIN( VERTICAL_ALIGNMENT_TYPE ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::VerticalAlignment::Type, TOP ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::VerticalAlignment::Type, CENTER ) -DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::VerticalAlignment::Type, BOTTOM ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::VerticalAlignment, TOP ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::VerticalAlignment, CENTER ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::VerticalAlignment, BOTTOM ) DALI_ENUM_TO_STRING_TABLE_END( VERTICAL_ALIGNMENT_TYPE ) +DALI_ENUM_TO_STRING_TABLE_BEGIN( LINE_WRAP_MODE ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::LineWrap, WORD ) +DALI_ENUM_TO_STRING_WITH_SCOPE( Toolkit::Text::LineWrap, CHARACTER ) +DALI_ENUM_TO_STRING_TABLE_END( LINE_WRAP_MODE ) } // namespace -bool GetHorizontalAlignmentEnum( const Property::Value& propertyValue, Toolkit::Text::HorizontalAlignment::Type& alignment ) +bool GetHorizontalAlignmentEnumeration( const Property::Value& propertyValue, Toolkit::Text::HorizontalAlignment::Type& alignment ) { return Scripting::GetEnumerationProperty( propertyValue, HORIZONTAL_ALIGNMENT_TYPE_TABLE, HORIZONTAL_ALIGNMENT_TYPE_TABLE_COUNT, alignment ); } -bool GetVerticalAlignmentEnum( const Property::Value& propertyValue, Toolkit::Text::VerticalAlignment::Type& alignment ) +bool GetVerticalAlignmentEnumeration( const Property::Value& propertyValue, Toolkit::Text::VerticalAlignment::Type& alignment ) { return Scripting::GetEnumerationProperty( propertyValue, VERTICAL_ALIGNMENT_TYPE_TABLE, VERTICAL_ALIGNMENT_TYPE_TABLE_COUNT, alignment ); } +bool GetLineWrapModeEnumeration( const Property::Value& propertyValue, Toolkit::Text::LineWrap::Mode& lineWrapMode ) +{ + return Scripting::GetEnumerationProperty( propertyValue, LINE_WRAP_MODE_TABLE, LINE_WRAP_MODE_TABLE_COUNT, lineWrapMode ); +} + const char* GetHorizontalAlignmentString( const Toolkit::Text::HorizontalAlignment::Type& alignment ) { return Scripting::GetLinearEnumerationName< Toolkit::Text::HorizontalAlignment::Type >( alignment, HORIZONTAL_ALIGNMENT_TYPE_TABLE, HORIZONTAL_ALIGNMENT_TYPE_TABLE_COUNT ); - } const char* GetVerticalAlignmentString( const Toolkit::Text::VerticalAlignment::Type& alignment ) @@ -74,7 +82,6 @@ const char* GetVerticalAlignmentString( const Toolkit::Text::VerticalAlignment:: VERTICAL_ALIGNMENT_TYPE_TABLE_COUNT ); } - } // namespace Text } // namespace Toolkit diff --git a/dali-toolkit/internal/text/text-enumerations-impl.h b/dali-toolkit/internal/text/text-enumerations-impl.h index 2462bc7..53e4fc1 100644 --- a/dali-toolkit/internal/text/text-enumerations-impl.h +++ b/dali-toolkit/internal/text/text-enumerations-impl.h @@ -35,19 +35,27 @@ namespace Text /** * @brief Get the alignment from the provided property value. - * @param[in] propertyValue the source value - * @param[out] alignment the resulting alignment from the given source + * @param[in] propertyValue The source value (which can be a Property::INTEGER or Property::STRING type) + * @param[out] alignment The resulting alignment from the given source * @return true if the resulting alignment has been updated */ -bool GetHorizontalAlignmentEnum( const Property::Value& propertyValue, Toolkit::Text::HorizontalAlignment::Type& alignment ); +bool GetHorizontalAlignmentEnumeration( const Property::Value& propertyValue, Toolkit::Text::HorizontalAlignment::Type& alignment ); /** * @brief Get the alignment from the provided property value. - * @param[in] propertyValue the source value - * @param[out] alignment the resulting alignment from the given source + * @param[in] propertyValue The source value (which can be a Property::INTEGER or Property::STRING type) + * @param[out] alignment The resulting alignment from the given source * @return true if the resulting alignment has been updated */ -bool GetVerticalAlignmentEnum( const Property::Value& propertyValue, Toolkit::Text::VerticalAlignment::Type& alignment ); +bool GetVerticalAlignmentEnumeration( const Property::Value& propertyValue, Toolkit::Text::VerticalAlignment::Type& alignment ); + +/** + * @brief Get the line-wrap-mode from the provided property value. + * @param[in] propertyValue The source value (which can be a Property::INTEGER or Property::STRING type) + * @param[out] alignment The resulting lineWrapMode from the given source + * @return true if the resulting lineWrapMode has been updated + */ +bool GetLineWrapModeEnumeration( const Property::Value& propertyValue, Toolkit::Text::LineWrap::Mode& lineWrapMode ); /** * @brief Get the alignment string from the provided alignment string. @@ -63,7 +71,6 @@ const char* GetHorizontalAlignmentString( const Toolkit::Text::HorizontalAlignme */ const char* GetVerticalAlignmentString( const Toolkit::Text::VerticalAlignment::Type& alignment ); - } // namespace Text } // namespace Toolkit diff --git a/dali-toolkit/internal/text/text-model.cpp b/dali-toolkit/internal/text/text-model.cpp index b31810a..e133e81 100755 --- a/dali-toolkit/internal/text/text-model.cpp +++ b/dali-toolkit/internal/text/text-model.cpp @@ -162,9 +162,9 @@ Model::Model() mVisualModel(), mScrollPosition(), mScrollPositionLast(), - mHorizontalAlignment( HorizontalAlignment::BEGIN ), - mVerticalAlignment( VerticalAlignment::TOP ), - mLineWrapMode( Layout::LineWrap::WORD ), + mHorizontalAlignment( Text::HorizontalAlignment::BEGIN ), + mVerticalAlignment( Text::VerticalAlignment::TOP ), + mLineWrapMode( Text::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 d4da2bc..0812b46 100755 --- a/dali-toolkit/internal/text/text-model.h +++ b/dali-toolkit/internal/text/text-model.h @@ -23,7 +23,6 @@ // INTERNAL INCLUDES #include -#include #include #include #include @@ -215,7 +214,7 @@ public: Vector2 mScrollPositionLast; ///< The last offset value of mScrollPosition HorizontalAlignment::Type mHorizontalAlignment; ///< The layout's horizontal alignment. VerticalAlignment::Type mVerticalAlignment; ///< The layout's vertical alignment. - Layout::LineWrap::Mode mLineWrapMode; ///< The text wrap mode + Text::LineWrap::Mode mLineWrapMode; ///< The text wrap mode float mAlignmentOffset; ///< The alignment offset. bool mElideEnabled:1; ///< Whether the text's elide is enabled. }; diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index 360b9c1..e8c97f6 100755 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -513,18 +513,26 @@ void TextVisual::DoSetProperty( Dali::Property::Index index, const Dali::Propert } case Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT: { - Text::HorizontalAlignment::Type alignment( Toolkit::Text::HorizontalAlignment::BEGIN ); - Toolkit::Text::GetHorizontalAlignmentEnum( propertyValue, alignment ); - - mController->SetHorizontalAlignment( alignment ); + if( mController ) + { + Text::HorizontalAlignment::Type alignment( static_cast< Text::HorizontalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( Toolkit::Text::GetHorizontalAlignmentEnumeration( propertyValue, alignment ) ) + { + mController->SetHorizontalAlignment( alignment ); + } + } break; } case Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT: { - Text::VerticalAlignment::Type alignment( Toolkit::Text::VerticalAlignment::BOTTOM ); - Toolkit::Text::GetVerticalAlignmentEnum( propertyValue, alignment); - - mController->SetVerticalAlignment( alignment ); + if( mController ) + { + Toolkit::Text::VerticalAlignment::Type alignment( static_cast< Text::VerticalAlignment::Type >( -1 ) ); // Set to invalid value to ensure a valid mode does get set + if( Toolkit::Text::GetVerticalAlignmentEnumeration( propertyValue, alignment) ) + { + mController->SetVerticalAlignment( alignment ); + } + } break; } case Toolkit::TextVisual::Property::TEXT_COLOR: diff --git a/dali-toolkit/public-api/controls/text-controls/text-editor.h b/dali-toolkit/public-api/controls/text-controls/text-editor.h index 0d20794..fdda010 100644 --- a/dali-toolkit/public-api/controls/text-controls/text-editor.h +++ b/dali-toolkit/public-api/controls/text-controls/text-editor.h @@ -441,9 +441,12 @@ public: PLACEHOLDER, /** - * @brief line wrap mode when the text lines over layout width. - * @details Name "lineWrapMode", type Property::STRING. + * @brief Line wrap mode when text lines are greater than the layout width. + * @details Name "lineWrapMode", type Text::LineWrap::Mode (Text::Property::INTEGER) or Property::STRING. * @SINCE_1_2.60 + * @note Default is Text::LineWrap::WORD. + * @note Return type is Text::LineWrap::Mode (Text::Property::INTEGER). + * @see Text::LineWrap */ LINE_WRAP_MODE, }; diff --git a/dali-toolkit/public-api/controls/text-controls/text-label.h b/dali-toolkit/public-api/controls/text-controls/text-label.h index 7aa8634..6536746 100644 --- a/dali-toolkit/public-api/controls/text-controls/text-label.h +++ b/dali-toolkit/public-api/controls/text-controls/text-label.h @@ -320,8 +320,11 @@ public: /** * @brief Line wrap mode when text lines are greater than the layout width. - * @details Name "lineWrapMode", type Property::STRING. + * @details Name "lineWrapMode", type Text::LineWrap::Mode (Text::Property::INTEGER) or Property::STRING. * @SINCE_1_2.60 + * @note Default is Text::LineWrap::WORD. + * @note Return type is Text::LineWrap::Mode (Text::Property::INTEGER). + * @see Text::LineWrap */ LINE_WRAP_MODE, diff --git a/dali-toolkit/public-api/text/text-enumerations.h b/dali-toolkit/public-api/text/text-enumerations.h index 9d9dff2..d9f23be 100644 --- a/dali-toolkit/public-api/text/text-enumerations.h +++ b/dali-toolkit/public-api/text/text-enumerations.h @@ -33,51 +33,96 @@ namespace Text { /** - * @brief The available Horizontal alignments for text + * @brief The available Horizontal alignments for text. + * * @SINCE_1_2.60 */ namespace HorizontalAlignment { - /** - * @brief Enumerations for Horizontal alignment - * - * @SINCE_1_2.60 - */ - enum Type - { - BEGIN, ///< @SINCE_1_2.60 - CENTER, ///< @SINCE_1_2.60 - END ///< @SINCE_1_2.60 - }; -} /** - * @brief The available Vertical alignments for text + * @brief Enumerations for Horizontal alignment. + * + * @SINCE_1_2.60 + */ +enum Type +{ + BEGIN, ///< @SINCE_1_2.60 + CENTER, ///< @SINCE_1_2.60 + END ///< @SINCE_1_2.60 +}; + +} // namespace HorizontalAlignment + +/** + * @brief The available Vertical alignments for text. + * * @SINCE_1_2.60 */ namespace VerticalAlignment { - /** - * @brief Enumerations for Vertical alignment - * - * @SINCE_1_2.60 - */ - enum Type - { - TOP, ///< @SINCE_1_2.60 - CENTER, ///< @SINCE_1_2.60 - BOTTOM ///< @SINCE_1_2.60 - }; -} - -} // Text + +/** + * @brief Enumerations for Vertical alignment. + * + * @SINCE_1_2.60 + */ +enum Type +{ + TOP, ///< @SINCE_1_2.60 + CENTER, ///< @SINCE_1_2.60 + BOTTOM ///< @SINCE_1_2.60 +}; + +} // namespace VerticalAlignment + +/** + * @brief Contains modes which specify how lines are wrapped. + * + * If the layout width is too short to show the full text, then a wrapping mode can be specified. + * + * LineWrap::WORD mode will move an entire word to the next line: + * @code + * +---------+ + * |HELLO | + * |WORLD | + * +---------+ + * @endcode + * + * LineWrap::CHARACTER mode will move character by character to the next line: + * @code + * +---------+ + * |HELLO WOR| + * |LD | + * +---------+ + * @endcode + * + * @SINCE_1_2.60 + */ +namespace LineWrap +{ + +/** + * @brief Enumerations specifying how a line is wrapped. + * @SINCE_1_2.60 + * @see LineWrap + */ +enum Mode +{ + WORD, ///< @SINCE_1_2.60 + CHARACTER ///< @SINCE_1_2.60 +}; + +} // namespace LineWrap + +} // namespace Text /** * @} */ -} // Toolkit +} // namespace Toolkit -} // Dali +} // namespace Dali #endif //DALI_TOOLKIT_TEXT_ENUMERATIONS_H -- 2.7.4