From 7c96cf0cba486c3167af95f787e35d51a2ce94e6 Mon Sep 17 00:00:00 2001 From: Joogab Yun Date: Wed, 16 Jun 2021 14:19:35 +0900 Subject: [PATCH] Makes the LTR/RTL alignment of text follow the system language by default. The MATCH_SYSTEM_LANGUAGE_DIRECTION property defaults to true. When the layout direction of TextLabel, TextField, or TextEditor is changed, LTR/RTL alignment of text follows the layout direction of each control. If you set MATCH_SYSTEM_LANGUAGE_DIRECTION to false As before, LTR/RTL is determined according to the language of the text. Change-Id: Ie97654a2309ffd4c30bec2c1b95d6337d8f4c674 --- .../dali-toolkit-test-utils/toolkit-text-utils.cpp | 7 +++--- .../dali-toolkit-internal/utc-Dali-Text-Layout.cpp | 1 - .../controls/text-controls/text-editor-devel.h | 2 +- .../controls/text-controls/text-field-devel.h | 2 +- .../controls/text-controls/text-label-devel.h | 7 +++--- .../devel-api/text/text-enumerations-devel.h | 12 ++++++++++ dali-toolkit/devel-api/text/text-utils-devel.cpp | 5 ++-- .../controls/text-controls/text-editor-impl.cpp | 23 +++++++++--------- .../controls/text-controls/text-editor-impl.h | 7 ++++++ .../controls/text-controls/text-field-impl.cpp | 23 +++++++++--------- .../controls/text-controls/text-field-impl.h | 7 ++++++ .../controls/text-controls/text-label-impl.cpp | 27 +++++++++++---------- .../controls/text-controls/text-label-impl.h | 7 ++++++ .../internal/text/bidirectional-support.cpp | 4 ++-- dali-toolkit/internal/text/bidirectional-support.h | 8 +++---- .../internal/text/layouts/layout-engine.cpp | 12 +++++----- dali-toolkit/internal/text/layouts/layout-engine.h | 6 ++--- .../internal/text/text-controller-impl.cpp | 4 ++-- dali-toolkit/internal/text/text-controller-impl.h | 14 ++++++----- .../internal/text/text-controller-relayouter.cpp | 5 ++-- dali-toolkit/internal/text/text-controller.cpp | 28 ++++++++++++++++++---- dali-toolkit/internal/text/text-controller.h | 28 +++++++++++++++------- dali-toolkit/internal/text/text-model.cpp | 9 ++++--- dali-toolkit/internal/text/text-model.h | 20 ++++++++-------- dali-toolkit/internal/visuals/text/text-visual.cpp | 11 +-------- 25 files changed, 169 insertions(+), 110 deletions(-) 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 6028e02..b2a6f5a 100755 --- 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 @@ -323,7 +323,6 @@ void CreateTextModel( const std::string& text, // Set the layout parameters. textModel->mHorizontalAlignment = Text::HorizontalAlignment::BEGIN; textModel->mIgnoreSpacesAfterText = true; - textModel->mMatchSystemLanguageDirection = false; Layout::Parameters layoutParameters( textArea, textModel ); @@ -385,7 +384,7 @@ void ConfigureTextLabel( ControllerPtr controller ) controller->SetTextElideEnabled( true ); // Disable match system language direction - controller->SetMatchSystemLanguageDirection(false); + controller->SetMatchLayoutDirection(DevelText::MatchLayoutDirection::CONTENTS); } void ConfigureTextField( ControllerPtr controller ) @@ -417,7 +416,7 @@ void ConfigureTextField( ControllerPtr controller ) controller->SetTextElideEnabled( false ); // Disable match system language direction - controller->SetMatchSystemLanguageDirection(false); + controller->SetMatchLayoutDirection(DevelText::MatchLayoutDirection::CONTENTS); } void ConfigureTextEditor( ControllerPtr controller ) @@ -449,7 +448,7 @@ void ConfigureTextEditor( ControllerPtr controller ) controller->SetTextElideEnabled( false ); // Disable match system language direction - controller->SetMatchSystemLanguageDirection(false); + controller->SetMatchLayoutDirection(DevelText::MatchLayoutDirection::CONTENTS); } } // namespace Text 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 8bdecaa..ed8d620 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp @@ -162,7 +162,6 @@ bool LayoutTextTest( const LayoutTextData& data ) textModel->mHorizontalAlignment = Text::HorizontalAlignment::BEGIN; textModel->mLineWrapMode = LineWrap::WORD; textModel->mIgnoreSpacesAfterText = true; - textModel->mMatchSystemLanguageDirection = false; Layout::Parameters layoutParameters( data.textArea, textModel ); 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 baa872f..fb96330 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 @@ -112,7 +112,7 @@ enum Type /** * @brief Modifies the default text alignment to match the direction of the system language. * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write - * @note The default value is false + * @note The default value is true */ MATCH_SYSTEM_LANGUAGE_DIRECTION, diff --git a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h index e1c18f0..f9f13dd 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h @@ -100,7 +100,7 @@ enum /** * @brief Modifies the default text alignment to match the direction of the system language. * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write - * @note The default value is false + * @note The default value is true */ MATCH_SYSTEM_LANGUAGE_DIRECTION = ELLIPSIS + 3, 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 efdad10..eed77fd 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 @@ -95,7 +95,7 @@ enum Type /** * @brief Modifies the default text alignment to match the direction of the system language. * @details Name "matchSystemLanguageDirection", type (Property::BOLEAN), Read/Write - * @note The default value is false + * @note The default value is true * * If MATCH_SYSTEM_LANGUAGE_DIRECTION property set true, the default text alignment to match the direction of the system language. * @@ -105,10 +105,10 @@ enum Type * * | TextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION | * |----------------------------------------------------------------------- - * | false (default) | true | + * | false | true (default) | * |-----------------------------------|----------------------------------| * | Hello world | Hello world | - * | ﻡﺮﺤﺑﺍ. | ﻡﺮﺤﺑﺍ. | + * | ﻡﺮﺤﺑﺍ. | ﻡﺮﺤﺑﺍ. | * */ MATCH_SYSTEM_LANGUAGE_DIRECTION, @@ -154,6 +154,7 @@ enum Type * - fontSize: 10pt, fontSizeScale: 1.5 */ FONT_SIZE_SCALE, + }; } // namespace Property diff --git a/dali-toolkit/devel-api/text/text-enumerations-devel.h b/dali-toolkit/devel-api/text/text-enumerations-devel.h index a74af43..9eb668f 100644 --- a/dali-toolkit/devel-api/text/text-enumerations-devel.h +++ b/dali-toolkit/devel-api/text/text-enumerations-devel.h @@ -56,6 +56,18 @@ enum Mode } // namespace LineWrap +/** + * A enum for defining text layout directions. + * It can also be inherited (from a parent) or deduced from the default language script of a locale. + * And it can be the direction of the text ifself. + */ +enum class MatchLayoutDirection +{ + INHERIT, // The text layout direction is inherited. If you change the layout direction, it will be aligned with the changed layout direction. + LOCALE, // The text layout direction is determined by the locale of the system language. + CONTENTS // The text layout direction is determined by the text itself. +}; + } // namespace DevelText } // namespace Toolkit diff --git a/dali-toolkit/devel-api/text/text-utils-devel.cpp b/dali-toolkit/devel-api/text/text-utils-devel.cpp index 99ff139..046d014 100644 --- a/dali-toolkit/devel-api/text/text-utils-devel.cpp +++ b/dali-toolkit/devel-api/text/text-utils-devel.cpp @@ -1031,9 +1031,8 @@ Size LayoutText(const RendererParameters& textParameters, TextAbstraction::TextR // Resize the vector of positions to have the same size than the vector of glyphs. rendererParameters.positions.Resize(numberOfGlyphs); - textModel->mLineWrapMode = Text::LineWrap::WORD; - textModel->mIgnoreSpacesAfterText = false; - textModel->mMatchSystemLanguageDirection = false; + textModel->mLineWrapMode = Text::LineWrap::WORD; + textModel->mIgnoreSpacesAfterText = false; Text::Layout::Parameters layoutParameters(internalDataModel.textLayoutArea, textModel); 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 af27bd1..220e63e 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -20,7 +20,6 @@ // EXTERNAL INCLUDES #include -#include #include #include #include @@ -698,7 +697,7 @@ void TextEditor::SetProperty(BaseObject* object, Property::Index index, const Pr } case Toolkit::DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: { - impl.mController->SetMatchSystemLanguageDirection(value.Get()); + impl.mController->SetMatchLayoutDirection(value.Get() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS); break; } case Toolkit::DevelTextEditor::Property::MAX_LENGTH: @@ -1119,7 +1118,7 @@ Property::Value TextEditor::GetProperty(BaseObject* object, Property::Index inde } case Toolkit::DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: { - value = impl.mController->IsMatchSystemLanguageDirection(); + value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS; break; } case Toolkit::DevelTextEditor::Property::MAX_LENGTH: @@ -1376,6 +1375,8 @@ void TextEditor::OnInitialize() Dali::LayoutDirection::Type layoutDirection = static_cast(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); mController->SetLayoutDirection(layoutDirection); + self.LayoutDirectionChangedSignal().Connect(this, &TextEditor::OnLayoutDirectionChanged); + // Forward input events to controller EnableGestureDetection(static_cast(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS)); GetTapGestureDetector().SetMaximumTapsRequired(2); @@ -1501,15 +1502,8 @@ void TextEditor::OnRelayout(const Vector2& size, RelayoutContainer& container) Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom)); // Support Right-To-Left of padding - Dali::LayoutDirection::Type layoutDirection; - if(mController->IsMatchSystemLanguageDirection()) - { - layoutDirection = static_cast(DevelWindow::Get(self).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); - } - else - { - layoutDirection = static_cast(self.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); - } + Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self); + if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection) { std::swap(padding.start, padding.end); @@ -2172,6 +2166,11 @@ void TextEditor::SetEditable(bool editable) } } +void TextEditor::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type) +{ + mController->ChangedLayoutDirection(); +} + TextEditor::TextEditor() : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), mAnimationPeriod(0.0f, 0.0f), diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h index 9a034a1..a39ccfa 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -377,6 +377,13 @@ private: // Implementation void OnScrollIndicatorAnimationFinished(Animation& animation); /** + * @brief Callback function for when the layout is changed. + * @param[in] actor The actor whose layoutDirection is changed. + * @param[in] type The layoutDirection. + */ + void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type); + + /** * Construct a new TextEditor. */ TextEditor(); 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 27eae92..e466063 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -21,7 +21,6 @@ // EXTERNAL INCLUDES #include #include -#include #include #include #include @@ -696,7 +695,7 @@ void TextField::SetProperty(BaseObject* object, Property::Index index, const Pro } case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: { - impl.mController->SetMatchSystemLanguageDirection(value.Get()); + impl.mController->SetMatchLayoutDirection(value.Get() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS); break; } case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP: @@ -1081,7 +1080,7 @@ Property::Value TextField::GetProperty(BaseObject* object, Property::Index index } case Toolkit::DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: { - value = impl.mController->IsMatchSystemLanguageDirection(); + value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS; break; } case Toolkit::DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP: @@ -1301,6 +1300,8 @@ void TextField::OnInitialize() Dali::LayoutDirection::Type layoutDirection = static_cast(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); mController->SetLayoutDirection(layoutDirection); + self.LayoutDirectionChangedSignal().Connect(this, &TextField::OnLayoutDirectionChanged); + // Forward input events to controller EnableGestureDetection(static_cast(GestureType::TAP | GestureType::PAN | GestureType::LONG_PRESS)); GetTapGestureDetector().SetMaximumTapsRequired(2); @@ -1413,15 +1414,8 @@ void TextField::OnRelayout(const Vector2& size, RelayoutContainer& container) Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom)); // Support Right-To-Left of padding - Dali::LayoutDirection::Type layoutDirection; - if(mController->IsMatchSystemLanguageDirection()) - { - layoutDirection = static_cast(DevelWindow::Get(self).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); - } - else - { - layoutDirection = static_cast(self.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); - } + Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self); + if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection) { std::swap(padding.start, padding.end); @@ -1956,6 +1950,11 @@ bool TextField::OnTouched(Actor actor, const TouchEvent& touch) return false; } +void TextField::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type) +{ + mController->ChangedLayoutDirection(); +} + void TextField::OnIdleSignal() { // Emits the change of input style signals. diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index ae73c30..7eb5852 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -333,6 +333,13 @@ private: // Implementation void EmitTextChangedSignal(); /** + * @brief Callback function for when the layout is changed. + * @param[in] actor The actor whose layoutDirection is changed. + * @param[in] type The layoutDirection. + */ + void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type); + + /** * Construct a new TextField. */ TextField(); 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 52f9c29..af0f85e 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.cpp @@ -21,7 +21,6 @@ // EXTERNAL INCLUDES #include #include -#include #include #include #include @@ -457,7 +456,7 @@ void TextLabel::SetProperty(BaseObject* object, Property::Index index, const Pro } case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: { - impl.mController->SetMatchSystemLanguageDirection(value.Get()); + impl.mController->SetMatchLayoutDirection(value.Get() ? DevelText::MatchLayoutDirection::LOCALE : DevelText::MatchLayoutDirection::CONTENTS); break; } case Toolkit::DevelTextLabel::Property::TEXT_FIT: @@ -688,7 +687,7 @@ Property::Value TextLabel::GetProperty(BaseObject* object, Property::Index index } case Toolkit::DevelTextLabel::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION: { - value = impl.mController->IsMatchSystemLanguageDirection(); + value = impl.mController->GetMatchLayoutDirection() != DevelText::MatchLayoutDirection::CONTENTS; break; } case Toolkit::DevelTextLabel::Property::TEXT_FIT: @@ -786,6 +785,8 @@ void TextLabel::OnInitialize() Dali::LayoutDirection::Type layoutDirection = static_cast(stage.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); mController->SetLayoutDirection(layoutDirection); + self.LayoutDirectionChangedSignal().Connect(this, &TextLabel::OnLayoutDirectionChanged); + // Forward input events to controller EnableGestureDetection(static_cast(GestureType::TAP)); GetTapGestureDetector().SetMaximumTapsRequired(1); @@ -899,8 +900,10 @@ void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container) { DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::OnRelayout\n"); + Actor self = Self(); + Extents padding; - padding = Self().GetProperty(Toolkit::Control::Property::PADDING); + padding = self.GetProperty(Toolkit::Control::Property::PADDING); Vector2 contentSize(size.x - (padding.start + padding.end), size.y - (padding.top + padding.bottom)); @@ -911,15 +914,8 @@ void TextLabel::OnRelayout(const Vector2& size, RelayoutContainer& container) } // Support Right-To-Left - Dali::LayoutDirection::Type layoutDirection; - if(mController->IsMatchSystemLanguageDirection()) - { - layoutDirection = static_cast(DevelWindow::Get(Self()).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); - } - else - { - layoutDirection = static_cast(Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); - } + Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self); + const Text::Controller::UpdateTextType updateTextType = mController->Relayout(contentSize, layoutDirection); if((Text::Controller::NONE_UPDATED != (Text::Controller::MODEL_UPDATED & updateTextType)) || mTextUpdateNeeded) @@ -1048,6 +1044,11 @@ void TextLabel::ScrollingFinished() RequestTextRelayout(); } +void TextLabel::OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type) +{ + mController->ChangedLayoutDirection(); +} + TextLabel::TextLabel() : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), mRenderingBackend(DEFAULT_RENDERING_BACKEND), diff --git a/dali-toolkit/internal/controls/text-controls/text-label-impl.h b/dali-toolkit/internal/controls/text-controls/text-label-impl.h index a204be6..2606011 100644 --- a/dali-toolkit/internal/controls/text-controls/text-label-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-label-impl.h @@ -177,6 +177,13 @@ private: return mTextScroller; } + /** + * @brief Callback function for when the layout is changed. + * @param[in] actor The actor whose layoutDirection is changed. + * @param[in] type The layoutDirection. + */ + void OnLayoutDirectionChanged(Actor actor, LayoutDirection::Type type); + private: // Data Text::ControllerPtr mController; Text::TextScrollerPtr mTextScroller; diff --git a/dali-toolkit/internal/text/bidirectional-support.cpp b/dali-toolkit/internal/text/bidirectional-support.cpp index da8f961..90e8caf 100644 --- a/dali-toolkit/internal/text/bidirectional-support.cpp +++ b/dali-toolkit/internal/text/bidirectional-support.cpp @@ -34,7 +34,7 @@ void SetBidirectionalInfo(const Vector& text, CharacterIndex startIndex, Length numberOfCharacters, Vector& bidirectionalInfo, - bool matchSystemLanguageDirection, + bool matchLayoutDirection, Dali::LayoutDirection::Type layoutDirection) { // Find where to insert the new paragraphs. @@ -113,7 +113,7 @@ void SetBidirectionalInfo(const Vector& text, // Create the bidirectional info for the whole paragraph and store the index to the table with this info in the run. bidirectionalRun.bidirectionalInfoIndex = bidirectionalSupport.CreateInfo(textBuffer + bidirectionalRun.characterRun.characterIndex, bidirectionalRun.characterRun.numberOfCharacters, - matchSystemLanguageDirection, + matchLayoutDirection, layoutDirection); bidirectionalRun.direction = bidirectionalSupport.GetParagraphDirection(bidirectionalRun.bidirectionalInfoIndex); diff --git a/dali-toolkit/internal/text/bidirectional-support.h b/dali-toolkit/internal/text/bidirectional-support.h index 46c368e..864f6a3 100644 --- a/dali-toolkit/internal/text/bidirectional-support.h +++ b/dali-toolkit/internal/text/bidirectional-support.h @@ -43,8 +43,8 @@ namespace Text * @param[in] startIndex The character from where the bidirectional info is set. * @param[in] numberOfCharacters The number of characters. * @param[out] bidirectionalInfo Vector with the bidirectional infor for each paragraph. - * @param[in] matchSystemLanguageDirection Whether match for system language direction or not. - * @param[in] layoutDirection The direction of the system language. + * @param[in] matchLayoutDirection Whether match for layout direction or not. + * @param[in] layoutDirection The direction of the layout. */ void SetBidirectionalInfo(const Vector& text, const Vector& scripts, @@ -52,8 +52,8 @@ void SetBidirectionalInfo(const Vector& text, CharacterIndex startIndex, Length numberOfCharacters, Vector& bidirectionalInfo, - bool matchSystemLanguageDirection = false, - Dali::LayoutDirection::Type layoutDirection = LayoutDirection::LEFT_TO_RIGHT); + bool matchLayoutDirection = false, + Dali::LayoutDirection::Type layoutDirection = LayoutDirection::LEFT_TO_RIGHT); /** * @brief Sets the visual to logical map table for a given line. diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index 25f83d1..6baed98 100644 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -1474,7 +1474,7 @@ struct Engine::Impl Vector& lines, float& alignmentOffset, Dali::LayoutDirection::Type layoutDirection, - bool matchSystemLanguageDirection) + bool matchLayoutDirection) { const CharacterIndex lastCharacterPlusOne = startIndex + numberOfCharacters; @@ -1510,7 +1510,7 @@ struct Engine::Impl horizontalAlignment, line, layoutDirection, - matchSystemLanguageDirection); + matchLayoutDirection); // Updates the alignment offset. alignmentOffset = std::min(alignmentOffset, line.alignmentOffset); @@ -1521,7 +1521,7 @@ struct Engine::Impl HorizontalAlignment::Type horizontalAlignment, LineRun& line, Dali::LayoutDirection::Type layoutDirection, - bool matchSystemLanguageDirection) + bool matchLayoutDirection) { line.alignmentOffset = 0.f; const bool isLineRTL = RTL == line.direction; @@ -1532,7 +1532,7 @@ struct Engine::Impl float lineLength = line.width; // match align for system language direction - if(matchSystemLanguageDirection) + if(matchLayoutDirection) { // Swap the alignment type if the line is right to left. isLayoutRTL = layoutDirection == LayoutDirection::RIGHT_TO_LEFT; @@ -1680,7 +1680,7 @@ void Engine::Align(const Size& size, Vector& lines, float& alignmentOffset, Dali::LayoutDirection::Type layoutDirection, - bool matchSystemLanguageDirection) + bool matchLayoutDirection) { mImpl->Align(size, startIndex, @@ -1689,7 +1689,7 @@ void Engine::Align(const Size& size, lines, alignmentOffset, layoutDirection, - matchSystemLanguageDirection); + matchLayoutDirection); } void Engine::SetDefaultLineSpacing(float lineSpacing) diff --git a/dali-toolkit/internal/text/layouts/layout-engine.h b/dali-toolkit/internal/text/layouts/layout-engine.h index 28e987c..46cc972 100644 --- a/dali-toolkit/internal/text/layouts/layout-engine.h +++ b/dali-toolkit/internal/text/layouts/layout-engine.h @@ -121,8 +121,8 @@ public: * @param[in] horizontalAlignment The horizontal alignment. * @param[in,out] lines The laid-out lines. * @param[out] alignmentOffset The alignment offset. - * @param[in] layoutDirection The direction of the system language. - * @param[in] matchSystemLanguageDirection Whether match align for system language direction or not. + * @param[in] layoutDirection The direction of the layout. + * @param[in] matchLayoutDirection Whether match align for layout direction or not. */ void Align(const Size& size, CharacterIndex startIndex, @@ -131,7 +131,7 @@ public: Vector& lines, float& alignmentOffset, Dali::LayoutDirection::Type layoutDirection, - bool matchSystemLanguageDirection); + bool matchLayoutDirection); /** * @brief Sets the default line spacing. diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 12cdae7..80b8756 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -797,7 +797,7 @@ bool Controller::Impl::UpdateModel(OperationsMask operationsRequired) startIndex, requestedNumberOfCharacters, bidirectionalInfo, - mModel->mMatchSystemLanguageDirection, + (mModel->mMatchLayoutDirection != DevelText::MatchLayoutDirection::CONTENTS), mLayoutDirection); if(0u != bidirectionalInfo.Count()) @@ -1737,7 +1737,7 @@ void Controller::Impl::GetCursorPosition(CharacterIndex logical, cursorInfo.primaryCursorHeight = cursorInfo.lineHeight; bool isRTL = false; - if(mModel->mMatchSystemLanguageDirection) + if(mModel->mMatchLayoutDirection != DevelText::MatchLayoutDirection::CONTENTS) { isRTL = mLayoutDirection == LayoutDirection::RIGHT_TO_LEFT; } diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 55184ef..f6681bd 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -355,7 +355,8 @@ struct Controller::Impl mTextFitMaxSize(DEFAULT_TEXTFIT_MAX), mTextFitStepSize(DEFAULT_TEXTFIT_STEP), mTextFitEnabled(false), - mFontSizeScale(DEFAULT_FONT_SIZE_SCALE) + mFontSizeScale(DEFAULT_FONT_SIZE_SCALE), + mIsLayoutDirectionChanged(false) { mModel = Model::New(); @@ -834,11 +835,12 @@ public: Shader mShaderBackground; ///< The shader for text background. - float mTextFitMinSize; ///< Minimum Font Size for text fit. Default 10 - float mTextFitMaxSize; ///< Maximum Font Size for text fit. Default 100 - float mTextFitStepSize; ///< Step Size for font intervalse. Default 1 - bool mTextFitEnabled : 1; ///< Whether the text's fit is enabled. - float mFontSizeScale; ///< Scale value for Font Size. Default 1.0 + float mTextFitMinSize; ///< Minimum Font Size for text fit. Default 10 + float mTextFitMaxSize; ///< Maximum Font Size for text fit. Default 100 + float mTextFitStepSize; ///< Step Size for font intervalse. Default 1 + bool mTextFitEnabled : 1; ///< Whether the text's fit is enabled. + float mFontSizeScale; ///< Scale value for Font Size. Default 1.0 + bool mIsLayoutDirectionChanged : 1; ///< Whether the layout has changed. private: friend ControllerImplEventHandler; diff --git a/dali-toolkit/internal/text/text-controller-relayouter.cpp b/dali-toolkit/internal/text/text-controller-relayouter.cpp index 062153d..decbfc1 100644 --- a/dali-toolkit/internal/text/text-controller-relayouter.cpp +++ b/dali-toolkit/internal/text/text-controller-relayouter.cpp @@ -384,7 +384,7 @@ Controller::UpdateTextType Controller::Relayouter::Relayout(Controller& controll textUpdateInfo.mCharacterIndex = 0u; } - if(model->mMatchSystemLanguageDirection && impl.mLayoutDirection != layoutDirection) + if(impl.mLayoutDirection != layoutDirection) { // Clear the update info. This info will be set the next time the text is updated. textUpdateInfo.mClearAll = true; @@ -394,6 +394,7 @@ Controller::UpdateTextType Controller::Relayouter::Relayout(Controller& controll GET_GLYPH_METRICS | SHAPE_TEXT | UPDATE_DIRECTION | + ALIGN | LAYOUT | BIDI_INFO | REORDER); @@ -622,7 +623,7 @@ bool Controller::Relayouter::DoRelayout(Controller& controller, const Size& size lines, impl.mModel->mAlignmentOffset, impl.mLayoutDirection, - impl.mModel->mMatchSystemLanguageDirection); + (impl.mModel->mMatchLayoutDirection != DevelText::MatchLayoutDirection::CONTENTS)); viewUpdated = true; } diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index b2b6550..d78f275 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -19,6 +19,8 @@ #include // EXTERNAL INCLUDES +#include +#include #include #include #include @@ -382,14 +384,19 @@ void Controller::SetIgnoreSpacesAfterText(bool ignore) mImpl->mModel->mIgnoreSpacesAfterText = ignore; } -bool Controller::IsMatchSystemLanguageDirection() const +void Controller::ChangedLayoutDirection() { - return mImpl->mModel->mMatchSystemLanguageDirection; + mImpl->mIsLayoutDirectionChanged = true; } -void Controller::SetMatchSystemLanguageDirection(bool match) +void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type) { - mImpl->mModel->mMatchSystemLanguageDirection = match; + mImpl->mModel->mMatchLayoutDirection = type; +} + +DevelText::MatchLayoutDirection Controller::GetMatchLayoutDirection() const +{ + return mImpl->mModel->mMatchLayoutDirection; } void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection) @@ -397,6 +404,19 @@ void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection) mImpl->mLayoutDirection = layoutDirection; } +Dali::LayoutDirection::Type Controller::GetLayoutDirection(Dali::Actor& actor) const +{ + if(mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::LOCALE || + (mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::INHERIT && !mImpl->mIsLayoutDirectionChanged)) + { + return static_cast(DevelWindow::Get(actor).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); + } + else + { + return static_cast(actor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); + } +} + bool Controller::IsShowingRealText() const { return mImpl->IsShowingRealText(); diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 0802a77..5c1c9e2 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -1441,24 +1441,36 @@ public: // Queries & retrieves. void SetIgnoreSpacesAfterText(bool ignore); /** - * @brief Retrieves matchSystemLanguageDirection value from model - * @return The value of matchSystemLanguageDirection + * @brief Sets SetMatchLayoutDirection value to model + * @param[in] match The value of matchLayoutDirection for the text */ - bool IsMatchSystemLanguageDirection() const; + void SetMatchLayoutDirection(DevelText::MatchLayoutDirection type); /** - * @brief Sets matchSystemLanguageDirection value to model - * @param[in] match The value of matchSystemLanguageDirection for the text + * @brief Retrieves matchLayoutDirection value from model + * @return The value of matchLayoutDirection */ - void SetMatchSystemLanguageDirection(bool match); + DevelText::MatchLayoutDirection GetMatchLayoutDirection() const; /** - * @brief Sets layoutDirection value - * @param[in] layoutDirection The value of system language direction + * @brief Sets layoutDirection type value. + * @param[in] layoutDirection The value of the layout direction type. */ void SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection); /** + * @brief Gets layoutDirection type value. + * @param[in] actor The actor which will get the layout direction type. + * @return The value of the layout direction type. + */ + Dali::LayoutDirection::Type GetLayoutDirection(Dali::Actor& actor) const; + + /** + * @brief Sets the layout direction changed. + */ + void ChangedLayoutDirection(); + + /** * @brief Retrieves if showing real text or not. * @return The value of showing real text. */ diff --git a/dali-toolkit/internal/text/text-model.cpp b/dali-toolkit/internal/text/text-model.cpp index 3868979..62ee89a 100644 --- a/dali-toolkit/internal/text/text-model.cpp +++ b/dali-toolkit/internal/text/text-model.cpp @@ -229,14 +229,17 @@ Model::Model() mAlignmentOffset(0.0f), mElideEnabled(false), mIgnoreSpacesAfterText(true), - mMatchSystemLanguageDirection(true) + mMatchLayoutDirection(DevelText::MatchLayoutDirection::INHERIT) { mLogicalModel = LogicalModel::New(); mVisualModel = VisualModel::New(); // Check environment variable for DALI_MATCH_SYSTEM_LANGUAGE_DIRECTION - auto match = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION); - mMatchSystemLanguageDirection = match ? (std::atoi(match) == 0 ? false : true) : mMatchSystemLanguageDirection; + auto match = Dali::EnvironmentVariable::GetEnvironmentVariable(DALI_ENV_MATCH_SYSTEM_LANGUAGE_DIRECTION); + if(match && (std::atoi(match) == 0)) + { + mMatchLayoutDirection = DevelText::MatchLayoutDirection::CONTENTS; + } } Model::~Model() diff --git a/dali-toolkit/internal/text/text-model.h b/dali-toolkit/internal/text/text-model.h index 751f230..139b8a3 100644 --- a/dali-toolkit/internal/text/text-model.h +++ b/dali-toolkit/internal/text/text-model.h @@ -257,16 +257,16 @@ public: * 0,0 means that the top-left corner of the layout matches the top-left corner of the UI control. * Typically this will have a negative value with scrolling occurs. */ - Vector2 mScrollPosition; ///< The text is offset by this position when scrolling. - Vector2 mScrollPositionLast; ///< The last offset value of mScrollPosition - HorizontalAlignment::Type mHorizontalAlignment; ///< The layout's horizontal alignment. - VerticalAlignment::Type mVerticalAlignment; ///< The layout's vertical alignment. - DevelText::VerticalLineAlignment::Type mVerticalLineAlignment; ///< The layout's vertical line alignment. - Text::LineWrap::Mode mLineWrapMode; ///< The text wrap mode - float mAlignmentOffset; ///< The alignment offset. - bool mElideEnabled : 1; ///< Whether the text's elide is enabled. - bool mIgnoreSpacesAfterText : 1; ///< Whether ignoring spaces after text or not. Default is true. - bool mMatchSystemLanguageDirection : 1; ///< Whether match align for system language direction or not. Default is false. + Vector2 mScrollPosition; ///< The text is offset by this position when scrolling. + Vector2 mScrollPositionLast; ///< The last offset value of mScrollPosition + HorizontalAlignment::Type mHorizontalAlignment; ///< The layout's horizontal alignment. + VerticalAlignment::Type mVerticalAlignment; ///< The layout's vertical alignment. + DevelText::VerticalLineAlignment::Type mVerticalLineAlignment; ///< The layout's vertical line alignment. + Text::LineWrap::Mode mLineWrapMode; ///< The text wrap mode + float mAlignmentOffset; ///< The alignment offset. + bool mElideEnabled : 1; ///< Whether the text's elide is enabled. + bool mIgnoreSpacesAfterText : 1; ///< Whether ignoring spaces after text or not. Default is true. + DevelText::MatchLayoutDirection mMatchLayoutDirection; ///< Whether to match text alignment with layout direction or not. }; } // namespace Text diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index 870ac09..19ecb5c 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -20,7 +20,6 @@ // EXTERNAL INCLUDES #include -#include #include #include #include @@ -474,15 +473,7 @@ void TextVisual::UpdateRenderer() return; } - Dali::LayoutDirection::Type layoutDirection; - if(mController->IsMatchSystemLanguageDirection()) - { - layoutDirection = static_cast(DevelWindow::Get(control).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); - } - else - { - layoutDirection = static_cast(control.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); - } + Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(control); const Text::Controller::UpdateTextType updateTextType = mController->Relayout(relayoutSize, layoutDirection); -- 2.7.4