Add GetLineCount to TextLabel 17/321217/1
authorBowon Ryu <bowon.ryu@samsung.com>
Mon, 17 Mar 2025 09:45:53 +0000 (18:45 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Mon, 17 Mar 2025 09:45:53 +0000 (18:45 +0900)
The LINE_COUNT Property of the label had a dependency on SIZE_WIDTH.
GetLineCount can calculate the line count for multiple cases by taking width as an argument.

In the case of Async,
the same case can be covered through RequestAsyncHeightForWidth and AsyncLineCount.

Change-Id: Id4176f9cb5c564829b494816bea75e91669eee75
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp
dali-toolkit/devel-api/controls/text-controls/text-label-devel.cpp
dali-toolkit/devel-api/controls/text-controls/text-label-devel.h
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/controls/text-controls/text-label-impl.h

index 152f9fd991439ed962817ccefe09b5da3d6f79fc..a86a790e1105bd07c8095a715e05b7ad37166862 100644 (file)
@@ -2851,6 +2851,7 @@ int UtcDaliTextLabelHyphenWrapMode(void)
   tet_infoline(" UtcDaliTextLabelHyphenWrapMode ");
 
   int       lineCount = 0;
+  int       getLineCount = 0;
   TextLabel label     = TextLabel::New();
   label.SetProperty(Actor::Property::SIZE, Vector2(150.0f, 300.f));
   label.SetProperty(TextLabel::Property::POINT_SIZE, 12.f);
@@ -2876,6 +2877,9 @@ int UtcDaliTextLabelHyphenWrapMode(void)
   */
   DALI_TEST_EQUALS(lineCount, 2, TEST_LOCATION);
 
+  getLineCount = DevelTextLabel::GetLineCount(label, 150.0f);
+  DALI_TEST_EQUALS(getLineCount, 2, TEST_LOCATION);
+
   label.SetProperty(TextLabel::Property::TEXT, "Hi Experimen");
   label.SetProperty(TextLabel::Property::LINE_WRAP_MODE, DevelText::LineWrap::MIXED);
   DALI_TEST_EQUALS(label.GetProperty<int>(TextLabel::Property::LINE_WRAP_MODE), static_cast<int>(DevelText::LineWrap::MIXED), TEST_LOCATION);
@@ -2892,6 +2896,9 @@ int UtcDaliTextLabelHyphenWrapMode(void)
   */
   DALI_TEST_EQUALS(lineCount, 3, TEST_LOCATION);
 
+  getLineCount = DevelTextLabel::GetLineCount(label, 150.0f);
+  DALI_TEST_EQUALS(getLineCount, 3, TEST_LOCATION);
+
   END_TEST;
 }
 
index 12c16afb0ab34678dbcf1add3ff1bcd2aaaf5728..4cbc390630cb96d9a6ce0a570f3e4c20fd78719a 100644 (file)
@@ -125,6 +125,11 @@ void RequestAsyncHeightForWidth(TextLabel textLabel, float width)
   GetImpl(textLabel).RequestAsyncHeightForWidth(width);
 }
 
+int GetLineCount(TextLabel textLabel, float width)
+{
+  return GetImpl(textLabel).GetLineCount(width);
+}
+
 } // namespace DevelTextLabel
 
 } // namespace Toolkit
index 02e4f0170d258a25aeb53acfdd66236bb61ad4f1..c817095bd402b3af1743fbf856827351c9f5b463 100644 (file)
@@ -460,6 +460,14 @@ DALI_TOOLKIT_API void RequestAsyncNaturalSize(TextLabel textLabel);
  */
 DALI_TOOLKIT_API void RequestAsyncHeightForWidth(TextLabel textLabel, float width);
 
+/**
+ * @brief Retrieves the text's number of lines for a given width.
+ * @param[in] textLabel The instance of TextLabel.
+ * @param[in] width The width of the text's area.
+ * @return The number of lines.
+ */
+DALI_TOOLKIT_API int GetLineCount(TextLabel textLabel, float width);
+
 /**
  * @brief Anchor clicked signal type.
  *
index cb87f80bf2c870658d4d4f6d8d47e0908dce1db5..f1a5a014fe2001632a9dc6c2238f9f69f66e3771 100644 (file)
@@ -1953,6 +1953,11 @@ void TextLabel::EnableControlBackground(const bool enable)
   }
 }
 
+int TextLabel::GetLineCount(float width)
+{
+  return mController->GetLineCount(width);
+}
+
 void TextLabel::RequestAsyncNaturalSize()
 {
   Actor                       self = Self();
index 8b74d39e2b7cc93aa2fee24a88de7a1824f9cdd3..57835637b44bdeb44e6c2c66371b12ea1164f75f 100644 (file)
@@ -286,6 +286,13 @@ public:
    */
   void RequestAsyncNaturalSize();
 
+  /**
+   * @brief Retrieves the text's number of lines for a given width.
+   * @param[in] width The width of the text's area.
+   * @return The number of lines.
+   */
+  int GetLineCount(float width);
+
   /**
    * @brief Requests asynchronous computation of the height of the text based on the given width.
    * @param[in] width The width of text to compute.