Fix TextLabel's padding was not applied during Cutout. 03/312603/5
authorANZ1217 <chihun.jeong@samsung.com>
Wed, 12 Jun 2024 06:24:13 +0000 (15:24 +0900)
committerANZ1217 <chihun.jeong@samsung.com>
Thu, 13 Jun 2024 06:18:19 +0000 (15:18 +0900)
Change-Id: I8aa0f35d2214aeb748efa874c9b524a365925f72

dali-toolkit/internal/text/controller/text-controller.cpp
dali-toolkit/internal/text/controller/text-controller.h
dali-toolkit/internal/text/rendering/text-typesetter.cpp
dali-toolkit/internal/text/rendering/view-model.cpp
dali-toolkit/internal/text/rendering/view-model.h
dali-toolkit/internal/text/text-model-interface.h
dali-toolkit/internal/text/text-model.cpp
dali-toolkit/internal/text/text-model.h
dali-toolkit/internal/text/visual-model-impl.cpp
dali-toolkit/internal/text/visual-model-impl.h
dali-toolkit/internal/visuals/text/text-visual.cpp

index ca2c5f2..7b87c2f 100644 (file)
@@ -1568,6 +1568,11 @@ const Vector4 Controller::GetBackgroundColorWithCutout() const
   return mImpl->mModel->mVisualModel->GetBackgroundColorWithCutout();
 }
 
+void Controller::SetOffsetWithCutout(const Vector2& offset)
+{
+  mImpl->mModel->mVisualModel->SetOffsetWithCutout(offset);
+}
+
 Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
 {
   return Relayouter::Relayout(*this, size, layoutDirection);
index 20ad0f0..c9ab3c0 100644 (file)
@@ -1704,6 +1704,13 @@ public: // Default style & Input style
    */
   const Vector4 GetBackgroundColorWithCutout() const;
 
+  /**
+   * @brief Sets offset with cutout.
+   *
+   * @param[in] offset The offset.
+   */
+  void SetOffsetWithCutout(const Vector2& offset);
+
 public: // Queries & retrieves.
   /**
    * @brief Return the layout engine.
index ec6dce2..ef8b7ca 100644 (file)
@@ -1011,6 +1011,14 @@ Devel::PixelBuffer Typesetter::RenderWithPixelBuffer(const Vector2& size, Toolki
     }
   }
 
+  const bool isCutoutEnabled = mModel->IsCutoutEnabled();
+  if(isCutoutEnabled)
+  {
+    Vector2 offset = mModel->GetOffsetWithCutout();
+    penX += offset.x;
+    penY += offset.y;
+  }
+
   // Generate the image buffers of the text for each different style first,
   // then combine all of them together as one final image buffer. We try to
   // do all of these in CPU only, so that once the final texture is generated,
index 7e3a4e3..0c31c04 100644 (file)
@@ -794,6 +794,11 @@ const Vector4& ViewModel::GetBackgroundColorWithCutout() const
   return mModel->GetBackgroundColorWithCutout();
 }
 
+const Vector2& ViewModel::GetOffsetWithCutout() const
+{
+  return mModel->GetOffsetWithCutout();
+}
+
 } // namespace Text
 
 } // namespace Toolkit
index dc7363d..1b3ec1a 100644 (file)
@@ -413,6 +413,11 @@ public:
    */
   const Vector4& GetBackgroundColorWithCutout() const override;
 
+  /**
+   * @copydoc ModelInterface::GetOffsetWithCutout()
+   */
+  const Vector2& GetOffsetWithCutout() const override;
+
 private:
   const ModelInterface* const mModel;                           ///< Pointer to the text's model.
   Vector<GlyphInfo>           mElidedGlyphs;                    ///< Stores the glyphs of the elided text.
index ba9f6ca..5083b0f 100644 (file)
@@ -543,6 +543,13 @@ public:
    * @return The color of the background with cutout.
    */
   virtual const Vector4& GetBackgroundColorWithCutout() const = 0;
+
+  /**
+   * @brief Retrieves the left and top offset with cutout.
+   *
+   * @return The offset with cutout.
+   */
+  virtual const Vector2& GetOffsetWithCutout() const = 0;
 };
 
 } // namespace Text
index bbe126b..9a4e761 100644 (file)
@@ -381,6 +381,11 @@ const Vector4& Model::GetBackgroundColorWithCutout() const
   return mVisualModel->GetBackgroundColorWithCutout();
 }
 
+const Vector2& Model::GetOffsetWithCutout() const
+{
+  return mVisualModel->GetOffsetWithCutout();
+}
+
 Model::Model()
 : mLogicalModel(),
   mVisualModel(),
index 5661035..c94362d 100644 (file)
@@ -399,6 +399,11 @@ public:
    */
   const Vector4& GetBackgroundColorWithCutout() const override;
 
+  /**
+   * @copydoc ModelInterface::GetOffsetWithCutout()
+   */
+  const Vector2& GetOffsetWithCutout() const override;
+
 private: // Private contructors & copy operator.
   /**
    * @brief Private constructor.
index 3fdd6b8..2f3ea3e 100644 (file)
@@ -695,6 +695,16 @@ const Vector4& VisualModel::GetBackgroundColorWithCutout() const
   return mBackgroundColorWithCutout;
 }
 
+void VisualModel::SetOffsetWithCutout(const Vector2& offset)
+{
+  mOffsetWithCutout = offset;
+}
+
+const Vector2& VisualModel::GetOffsetWithCutout() const
+{
+  return mOffsetWithCutout;
+}
+
 VisualModel::~VisualModel()
 {
 }
index 7ef55b5..e391113 100644 (file)
@@ -704,6 +704,20 @@ public:
    */
   const Vector4& GetBackgroundColorWithCutout() const;
 
+  /**
+   * @brief Sets the left and top offset with cutout.
+   *
+   * @param[in] offset The offset to set.
+   */
+  void SetOffsetWithCutout(const Vector2& offset);
+
+  /**
+   * @brief Retrieves the left and top offset with cutout.
+   *
+   * @return The offset.
+   */
+  const Vector2& GetOffsetWithCutout() const;
+
 protected:
   /**
    * @brief A reference counted object may only be deleted by calling Unreference().
@@ -750,11 +764,12 @@ public:
   float                            mDashedUnderlineWidth;       ///< The width of the dashes of the dashed underline.
   float                            mDashedUnderlineGap;         ///< The gap between the dashes of the dashed underline.
   float                            mShadowBlurRadius;           ///< Blur radius of shadow, 0 indicates no blur.
-  float                            mOutlineBlurRadius;      ///< Blur radius of outline, 0 indicates no blur.
+  float                            mOutlineBlurRadius;          ///< Blur radius of outline, 0 indicates no blur.
   uint16_t                         mOutlineWidth;               ///< Width of outline.
   Vector<StrikethroughGlyphRun>    mStrikethroughRuns;          ///< Runs of glyphs that have strikethrough.
   Vector<CharacterSpacingGlyphRun> mCharacterSpacingRuns;       ///< Runs of glyphs that have character-spacing.
   Vector4                          mBackgroundColorWithCutout;  ///< Background color with cutout.
+  Vector2                          mOffsetWithCutout;           ///< Left and top offset when cutout.
 
 private:
   Size mNaturalSize;    ///< Size of the text with no line wrapping.
index 55296d6..e1c2d0f 100644 (file)
@@ -590,11 +590,21 @@ void TextVisual::UpdateRenderer()
 
       if(cutoutEnabled)
       {
-        relayoutSize                   = Vector2(controlWidth, controlHeight);
-        mImpl->mTransform.mSize.width  = controlWidth;
+        // mTransform stores the size and offset of the current visual.
+        // padding and alignment information is stored in mOffset.
+        // When Cutout Enabled, the current visual must draw the entire control.
+        // so set the size to controlSize and offset to 0.
+
+        relayoutSize = Vector2(controlWidth, controlHeight);
+        mImpl->mTransform.mSize.width = controlWidth;
         mImpl->mTransform.mSize.height = controlHeight;
-        mImpl->mTransform.mOffset.x    = 0;
-        mImpl->mTransform.mOffset.y    = 0;
+
+        // Relayout to the original size has been completed, so save only the offset information and use it in typesetter.
+
+        Vector2 originOffset = Vector2(mImpl->mTransform.mOffset.x, mImpl->mTransform.mOffset.y);
+        mController->SetOffsetWithCutout(originOffset);
+        mImpl->mTransform.mOffset.x = 0;
+        mImpl->mTransform.mOffset.y = 0;
       }
 
       AddRenderer(control, relayoutSize, hasMultipleTextColors, containsColorGlyph, styleEnabled, isOverlayStyle);