Add RequestAsyncRenderWithFixedSize to async text
authorBowon Ryu <bowon.ryu@samsung.com>
Tue, 9 Jul 2024 06:51:58 +0000 (15:51 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Tue, 9 Jul 2024 06:51:58 +0000 (15:51 +0900)
Requests asynchronous rendering of text with a fixed size.

Change-Id: Ibae12de7ff3052b8826c0c8a7076347099842ffe
Signed-off-by: Bowon Ryu <bowon.ryu@samsung.com>
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
dali-toolkit/internal/text/async-text/async-text-interface.h
dali-toolkit/internal/text/async-text/async-text-loader-impl.cpp
dali-toolkit/internal/text/async-text/async-text-loader.h
dali-toolkit/internal/visuals/text/text-visual.cpp

index 48a4567..7db74f9 100644 (file)
@@ -85,6 +85,11 @@ bool IsRemoveBackInset(TextLabel textLabel)
   return GetImpl(textLabel).IsRemoveBackInset();
 }
 
+void RequestAsyncRenderWithFixedSize(TextLabel textLabel, float width, float height)
+{
+  GetImpl(textLabel).RequestAsyncRenderWithFixedSize(width, height);
+}
+
 } // namespace DevelTextLabel
 
 } // namespace Toolkit
index 162962f..2eebd35 100644 (file)
@@ -382,6 +382,15 @@ DALI_TOOLKIT_API void SetRemoveBackInset(TextLabel textLabel, const bool remove)
 DALI_TOOLKIT_API bool IsRemoveBackInset(TextLabel textLabel);
 
 /**
+ * @brief A method that requests asynchronous rendering of text with a fixed size.
+ *
+ * @param[in] textLabel The instance of TextLabel.
+ * @param[in] width The width of text to render.
+ * @param[in] height The height of text to render.
+ */
+DALI_TOOLKIT_API void RequestAsyncRenderWithFixedSize(TextLabel textLabel, float width, float height);
+
+/**
  * @brief Anchor clicked signal type.
  *
  * @note Signal
index 32a6b16..6260fad 100644 (file)
@@ -1573,10 +1573,10 @@ void TextLabel::AsyncTextFitChanged(float pointSize)
   }
 }
 
-void TextLabel::AsyncLoadComplete()
+void TextLabel::AsyncLoadComplete(Text::AsyncTextRenderInfo renderInfo)
 {
   // Pure Virtual from AsyncTextInterface
-  DALI_LOG_INFO(gLogFilter, Debug::General, "TextLabel::AsyncLoadComplete\n");
+  DALI_LOG_RELEASE_INFO("Rendered size : %f, %f\n", renderInfo.renderedSize.width, renderInfo.renderedSize.height);
 
   // To avoid flickering issues, enable/disable the background visual when async load is completed.
   EnableControlBackground(!mController->IsTextCutout());
@@ -1713,6 +1713,39 @@ void TextLabel::EnableControlBackground(const bool enable)
   }
 }
 
+void TextLabel::RequestAsyncRenderWithFixedSize(float width, float height)
+{
+  if(mController->IsAsyncTextLoadEnabled())
+  {
+    DALI_LOG_RELEASE_INFO("Request size : %f, %f\n", width, height);
+
+    Actor self = Self();
+
+    Extents padding;
+    padding = self.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
+
+    Vector2 contentSize(width - (padding.start + padding.end), height - (padding.top + padding.bottom));
+
+    // Support Right-To-Left
+    Dali::LayoutDirection::Type layoutDirection = mController->GetLayoutDirection(self);
+
+    // Support Right-To-Left of padding
+    if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
+    {
+      std::swap(padding.start, padding.end);
+    }
+
+    AsyncTextParameters parameters = GetAsyncTextParameters(contentSize, padding, layoutDirection);
+    TextVisual::UpdateAsyncRenderer(mVisual, parameters);
+    mTextUpdateNeeded = false;
+    mIsPropertyUpdated = false;
+  }
+  else
+  {
+    DALI_LOG_WARNING("IsAsyncTextLoadEnabled is false\n");
+  }
+}
+
 std::string TextLabel::TextLabelAccessible::GetNameRaw() const
 {
   return GetWholeText();
index ccda7d1..a6b11ae 100644 (file)
@@ -234,6 +234,15 @@ public:
    */
   void EnableControlBackground(const bool enable);
 
+  /**
+   * @brief A method that requests asynchronous rendering of text with a fixed size.
+   *
+   * @param[in] width The width of text to render.
+   * @param[in] height The height of text to render.
+   */
+  void RequestAsyncRenderWithFixedSize(float width, float height);
+
+
 private: // From Control
   /**
    * @copydoc Control::OnInitialize()
@@ -319,7 +328,7 @@ private: // from AsyncTextInterface
   /**
    * @copydoc Text::AsyncTextInterface::AsyncLoadComplete()
    */
-  void AsyncLoadComplete();
+  void AsyncLoadComplete(Text::AsyncTextRenderInfo renderInfo);
 
 private: // Implementation
   /**
index 7f406fc..0deaf8d 100644 (file)
@@ -57,7 +57,7 @@ public:
   /**
    * @brief Called when the async load complete.
    */
-  virtual void AsyncLoadComplete() = 0;
+  virtual void AsyncLoadComplete(Text::AsyncTextRenderInfo renderInfo) = 0;
 };
 
 } // namespace Text
index 8fa3e71..0090d1b 100644 (file)
@@ -1053,6 +1053,11 @@ AsyncTextRenderInfo AsyncTextLoader::Render(AsyncTextParameters& parameters)
   renderInfo.styleEnabled          = styleEnabled;
   renderInfo.isOverlayStyle        = isOverlayStyle;
 
+  if(parameters.isFixedSize)
+  {
+    renderInfo.renderedSize = Size(static_cast<float>(parameters.textWidth), static_cast<float>(parameters.textHeight));
+  }
+
   return renderInfo;
 }
 
@@ -1152,6 +1157,7 @@ AsyncTextRenderInfo AsyncTextLoader::RenderAutoScroll(AsyncTextParameters& param
   // Store the control size and calculated wrap gap in render info.
   renderInfo.controlSize       = controlSize;
   renderInfo.autoScrollWrapGap = wrapGap;
+  renderInfo.renderedSize      = controlSize;
 
   return renderInfo;
 }
index 49435c8..578fca5 100644 (file)
@@ -46,7 +46,8 @@ class AsyncTextLoader;
 struct AsyncTextParameters
 {
   AsyncTextParameters()
-  : maxTextureSize{0},
+  : isFixedSize{true},
+    maxTextureSize{0},
     text{},
     fontSize{0.f},
     textColor{Color::BLACK},
@@ -113,6 +114,8 @@ struct AsyncTextParameters
   {
   }
 
+  bool isFixedSize;
+
   int maxTextureSize;     ///< The maximum size of texture.
 
   std::string text;       ///< The text to be rendered encoded in utf8.
@@ -201,6 +204,7 @@ struct AsyncTextRenderInfo
     width(0u),
     height(0u),
     controlSize(),
+    renderedSize(),
     autoScrollWrapGap(0.f),
     hasMultipleTextColors(false),
     containsColorGlyph(false),
@@ -223,6 +227,7 @@ struct AsyncTextRenderInfo
   uint32_t      width;
   uint32_t      height;
   Size          controlSize;
+  Size          renderedSize;
   float         autoScrollWrapGap;
   bool          hasMultipleTextColors;
   bool          containsColorGlyph;
index 2182dc8..dc29820 100644 (file)
@@ -943,7 +943,7 @@ void TextVisual::LoadComplete(bool loadingSuccess, TextInformation textInformati
 
     if(mAsyncTextInterface)
     {
-      mAsyncTextInterface->AsyncLoadComplete();
+      mAsyncTextInterface->AsyncLoadComplete(renderInfo);
     }
   }
   else