From b020756d745758d3f23f3ed6354888364c0960a3 Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Wed, 30 Mar 2022 12:07:15 +0900 Subject: [PATCH] Add vertical alignment for text editor - Support VerticalAlignment for TextEditor - If the layout size is bigger than control size, there is no meaning in calculating the vertical offset. - But when the text is empty, the cursor position should be updated according to the vertical alignment. Change-Id: I219abf970ff4cb3ce0540244a3f6fd4ed41d24e8 Signed-off-by: Bowon Ryu --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 8 ++++ .../controls/text-controls/text-editor-devel.h | 8 ++++ .../controls/text-controls/text-editor-impl.cpp | 1 + .../text-controls/text-editor-property-handler.cpp | 20 ++++++++++ .../internal/text/text-controller-impl.cpp | 44 +++++++++++++--------- .../internal/text/text-controller-relayouter.cpp | 17 +++++++-- .../internal/text/text-controller-relayouter.h | 4 +- 7 files changed, 80 insertions(+), 22 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 9db4289..476da78 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -691,6 +691,14 @@ int UtcDaliTextEditorSetPropertyP(void) editor.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, "END"); DALI_TEST_EQUALS(editor.GetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT), "END", TEST_LOCATION); + // Check that the Alignment properties can be correctly set + editor.SetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT, "BOTTOM"); + DALI_TEST_EQUALS(editor.GetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT), "BOTTOM", TEST_LOCATION); + editor.SetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT, "CENTER"); + DALI_TEST_EQUALS(editor.GetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT), "CENTER", TEST_LOCATION); + editor.SetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT, "TOP"); + DALI_TEST_EQUALS(editor.GetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT), "TOP", TEST_LOCATION); + // Check scroll properties. editor.SetProperty(TextEditor::Property::SCROLL_THRESHOLD, 1.f); DALI_TEST_EQUALS(editor.GetProperty(TextEditor::Property::SCROLL_THRESHOLD), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION); 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 b990dc7..4645576 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 @@ -310,6 +310,14 @@ enum Type * @note If the value is less than 1, the lines could to be overlapped. */ RELATIVE_LINE_SIZE, + + /** + * @brief The line vertical alignment. + * @details Name "verticalAlignment", type Property::STRING or type VerticalAlignment::Type (Property::INTEGER). + * Values "TOP", "CENTER", "BOTTOM", default TOP. + * @note Return type is Property::STRING + */ + VERTICAL_ALIGNMENT, }; } // 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 42153dc..b44029c 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -159,6 +159,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "strikethrough", DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "inputStrikethrough", MAP, INPUT_STRIKETHROUGH ) DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "characterSpacing", FLOAT, CHARACTER_SPACING ) DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "relativeLineSize", FLOAT, RELATIVE_LINE_SIZE ) +DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit, TextEditor, "verticalAlignment", STRING, VERTICAL_ALIGNMENT ) DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-property-handler.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-property-handler.cpp index 5ea2cf1..361607a 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-property-handler.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-property-handler.cpp @@ -126,6 +126,16 @@ void TextEditor::PropertyHandler::SetProperty(Toolkit::TextEditor textEditor, Pr } break; } + case Toolkit::DevelTextEditor::Property::VERTICAL_ALIGNMENT: + { + Toolkit::Text::VerticalAlignment::Type alignment(static_cast(-1)); // Set to invalid value to ensure a valid mode does get set + if(Text::GetVerticalAlignmentEnumeration(value, alignment)) + { + impl.mController->SetVerticalAlignment(alignment); + DALI_LOG_INFO(gTextEditorLogFilter, Debug::General, "TextEditor %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment); + } + break; + } case Toolkit::TextEditor::Property::SCROLL_THRESHOLD: { const float threshold = value.Get(); @@ -786,6 +796,16 @@ Property::Value TextEditor::PropertyHandler::GetProperty(Toolkit::TextEditor tex } break; } + case Toolkit::DevelTextEditor::Property::VERTICAL_ALIGNMENT: + { + const char* name = Text::GetVerticalAlignmentString(impl.mController->GetVerticalAlignment()); + + if(name) + { + value = std::string(name); + } + break; + } case Toolkit::TextEditor::Property::SCROLL_THRESHOLD: { value = impl.mDecorator->GetScrollThreshold(); diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index c24a5cf..46d83dd 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -362,6 +362,27 @@ void ChangeTextControllerState(Controller::Impl& impl, EventData::State newState } } +void UpdateCursorPositionForAlignment(Controller::Impl& impl, bool needFullAlignment) +{ + EventData* eventData = impl.mEventData; + + // Set the flag to redo the alignment operation + impl.mOperationsPending = static_cast(impl.mOperationsPending | Controller::OperationsMask::ALIGN); + + if(eventData) + { + // Note: mUpdateAlignment is currently only needed for horizontal alignment + eventData->mUpdateAlignment = needFullAlignment; + + // Update the cursor if it's in editing mode + if(EventData::IsEditingState(eventData->mState)) + { + impl.ChangeState(EventData::EDITING); + eventData->mUpdateCursorPosition = true; + } + } +} + } // unnamed Namespace EventData::EventData(DecoratorPtr decorator, InputMethodContext& inputMethodContext) @@ -1440,6 +1461,10 @@ void Controller::Impl::ScrollToMakePositionVisible(const Vector2& position, floa { mModel->mScrollPosition.y = mModel->mVisualModel->mControlSize.height - positionEndY; } + else if(mModel->mLogicalModel->mText.Count() == 0u) + { + Relayouter::CalculateVerticalOffset(*this, mModel->mVisualModel->mControlSize); + } } } @@ -1802,22 +1827,7 @@ void Controller::Impl::SetHorizontalAlignment(Text::HorizontalAlignment::Type al { // Set the alignment. mModel->mHorizontalAlignment = alignment; - - // Set the flag to redo the alignment operation. - mOperationsPending = static_cast(mOperationsPending | ALIGN); - - if(mEventData) - { - mEventData->mUpdateAlignment = true; - - // Update the cursor if it's in editing mode - if(EventData::IsEditingState(mEventData->mState)) - { - ChangeState(EventData::EDITING); - mEventData->mUpdateCursorPosition = true; - } - } - + UpdateCursorPositionForAlignment(*this, true); RequestRelayout(); } } @@ -1828,7 +1838,7 @@ void Controller::Impl::SetVerticalAlignment(VerticalAlignment::Type alignment) { // Set the alignment. mModel->mVerticalAlignment = alignment; - mOperationsPending = static_cast(mOperationsPending | ALIGN); + UpdateCursorPositionForAlignment(*this, false); RequestRelayout(); } } diff --git a/dali-toolkit/internal/text/text-controller-relayouter.cpp b/dali-toolkit/internal/text/text-controller-relayouter.cpp index 6f4763e..ebab609 100644 --- a/dali-toolkit/internal/text/text-controller-relayouter.cpp +++ b/dali-toolkit/internal/text/text-controller-relayouter.cpp @@ -447,7 +447,19 @@ Controller::UpdateTextType Controller::Relayouter::Relayout(Controller& controll if(!isEditable || !controller.IsMultiLineEnabled()) { // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated. - CalculateVerticalOffset(controller, size); + CalculateVerticalOffset(impl, size); + } + else // TextEditor + { + // If layoutSize is bigger than size, vertical align has no meaning. + if(layoutSize.y < size.y) + { + CalculateVerticalOffset(impl, size); + if(impl.mEventData) + { + impl.mEventData->mScrollAfterDelete = false; + } + } } if(isEditable) @@ -769,9 +781,8 @@ void Controller::Relayouter::DoRelayoutHorizontalAlignment(Controller::Impl& } } -void Controller::Relayouter::CalculateVerticalOffset(Controller& controller, const Size& controlSize) +void Controller::Relayouter::CalculateVerticalOffset(Controller::Impl& impl, const Size& controlSize) { - Controller::Impl& impl = *controller.mImpl; ModelPtr& model = impl.mModel; VisualModelPtr& visualModel = model->mVisualModel; Size layoutSize = model->mVisualModel->GetLayoutSize(); diff --git a/dali-toolkit/internal/text/text-controller-relayouter.h b/dali-toolkit/internal/text/text-controller-relayouter.h index c0ab806..a98ed53 100644 --- a/dali-toolkit/internal/text/text-controller-relayouter.h +++ b/dali-toolkit/internal/text/text-controller-relayouter.h @@ -97,10 +97,10 @@ struct Controller::Relayouter /** * @brief Called by the Controller to calculate the veritcal offset give the control size. * - * @param[in] controller A reference to the controller class + * @param[in] impl A reference to the controller impl class * @param[in] controlSize The control size */ - static void CalculateVerticalOffset(Controller& controller, const Size& controlSize); + static void CalculateVerticalOffset(Controller::Impl& impl, const Size& controlSize); /** * @brief Calculates the layout size of control according to @p requestedControllerSize and @p requestedOperationsMask -- 2.7.4