Merge "DALi Version 2.1.17" into devel/master
authorDavid Steele <david.steele@samsung.com>
Fri, 8 Apr 2022 12:01:40 +0000 (12:01 +0000)
committerGerrit Code Review <gerrit@review>
Fri, 8 Apr 2022 12:01:40 +0000 (12:01 +0000)
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-editor-property-handler.cpp
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-relayouter.cpp
dali-toolkit/internal/text/text-controller-relayouter.h

index 9db4289..476da78 100644 (file)
@@ -691,6 +691,14 @@ int UtcDaliTextEditorSetPropertyP(void)
   editor.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, "END");
   DALI_TEST_EQUALS(editor.GetProperty<std::string>(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<std::string>(DevelTextEditor::Property::VERTICAL_ALIGNMENT), "BOTTOM", TEST_LOCATION);
+  editor.SetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT, "CENTER");
+  DALI_TEST_EQUALS(editor.GetProperty<std::string>(DevelTextEditor::Property::VERTICAL_ALIGNMENT), "CENTER", TEST_LOCATION);
+  editor.SetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT, "TOP");
+  DALI_TEST_EQUALS(editor.GetProperty<std::string>(DevelTextEditor::Property::VERTICAL_ALIGNMENT), "TOP", TEST_LOCATION);
+
   // Check scroll properties.
   editor.SetProperty(TextEditor::Property::SCROLL_THRESHOLD, 1.f);
   DALI_TEST_EQUALS(editor.GetProperty<float>(TextEditor::Property::SCROLL_THRESHOLD), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
index b990dc7..4645576 100644 (file)
@@ -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
index 42153dc..b44029c 100644 (file)
@@ -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    )
index 5ea2cf1..361607a 100644 (file)
@@ -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<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);
+        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<float>();
@@ -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();
index c24a5cf..46d83dd 100644 (file)
@@ -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<Controller::OperationsMask>(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<OperationsMask>(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<OperationsMask>(mOperationsPending | ALIGN);
+    UpdateCursorPositionForAlignment(*this, false);
     RequestRelayout();
   }
 }
index 6f4763e..ebab609 100644 (file)
@@ -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();
index c0ab806..a98ed53 100644 (file)
@@ -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