[Tizen] Enable background color in TextEditor 86/265986/5 accepted/tizen/6.0/unified/20211104.123341 submit/tizen_6.0/20211104.034658
authorjoogab.yun <joogab.yun@samsung.com>
Thu, 4 Nov 2021 01:52:15 +0000 (10:52 +0900)
committerjoogab.yun <joogab.yun@samsung.com>
Thu, 4 Nov 2021 01:56:16 +0000 (10:56 +0900)
Change-Id: I867f3e5c38c40923f959a04fdff7a9ac58755171

dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-editor-impl.h
dali-toolkit/internal/text/text-controller-impl.cpp

index bd924a4..0312f6b 100644 (file)
@@ -1375,16 +1375,50 @@ void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType)
 
     if(renderableActor != mRenderableActor)
     {
+      UnparentAndReset(mBackgroundActor);
       UnparentAndReset(mRenderableActor);
       mRenderableActor = renderableActor;
+
+      if(mRenderableActor)
+      {
+        mBackgroundActor = mController->CreateBackgroundActor();
+      }
     }
   }
 
   if(mRenderableActor)
   {
+    const Vector2& scrollOffset = mController->GetTextModel()->GetScrollPosition();
+
+    float renderableActorPositionX, renderableActorPositionY;
+
+    if(mStencil)
+    {
+      renderableActorPositionX = scrollOffset.x + mAlignmentOffset;
+      renderableActorPositionY = scrollOffset.y;
+    }
+    else
+    {
+      Extents padding;
+      padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
+
+      // Support Right-To-Left of padding
+      Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
+      if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
+      {
+        std::swap(padding.start, padding.end);
+      }
+
+      renderableActorPositionX = scrollOffset.x + mAlignmentOffset + padding.start;
+      renderableActorPositionY = scrollOffset.y + padding.top;
+    }
+
+    mRenderableActor.SetProperty(Actor::Property::POSITION, Vector2(renderableActorPositionX, renderableActorPositionY));
     // Make sure the actors are parented correctly with/without clipping
     Actor self = mStencil ? mStencil : Self();
 
+    Actor highlightActor;
+
     for(std::vector<Actor>::iterator it    = mClippingDecorationActors.begin(),
                                      endIt = mClippingDecorationActors.end();
         it != endIt;
@@ -1392,11 +1426,32 @@ void TextEditor::RenderText(Text::Controller::UpdateTextType updateTextType)
     {
       self.Add(*it);
       it->LowerToBottom();
+
+      if(it->GetProperty<std::string>(Dali::Actor::Property::NAME) == "HighlightActor")
+      {
+        highlightActor = *it;
+      }
     }
     mClippingDecorationActors.clear();
 
     self.Add(mRenderableActor);
 
+    if(mBackgroundActor)
+    {
+      if(mDecorator && mDecorator->IsHighlightVisible())
+      {
+        self.Add(mBackgroundActor);
+        mBackgroundActor.SetProperty(Actor::Property::POSITION, Vector2(renderableActorPositionX, renderableActorPositionY)); // In text field's coords.
+        mBackgroundActor.LowerBelow(highlightActor);
+      }
+      else
+      {
+        mRenderableActor.Add(mBackgroundActor);
+        mBackgroundActor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f)); // In renderable actor's coords.
+        mBackgroundActor.LowerToBottom();
+      }
+    }
+
     ApplyScrollPosition();
   }
   UpdateScrollBar();
index 1fb17a9..ea093c9 100644 (file)
@@ -350,6 +350,7 @@ private: // Data
   std::vector<Actor>            mClippingDecorationActors; ///< Decoration actors which need clipping.
 
   Actor         mRenderableActor;
+  Actor         mBackgroundActor;
   Actor         mActiveLayer;
   CallbackBase* mIdleCallback;
 
index ac871d6..70726ab 100644 (file)
@@ -2737,6 +2737,10 @@ Actor Controller::Impl::CreateBackgroundActor()
 
     Vector4 quad;
     uint32_t numberOfQuads = 0u;
+    Length    yLineOffset   = 0;
+    Length    prevLineIndex = 0;
+    LineIndex lineIndex;
+    Length    numberOfLines;
 
     for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i )
     {
@@ -2747,38 +2751,46 @@ Actor Controller::Impl::CreateBackgroundActor()
       const ColorIndex backgroundColorIndex = ( nullptr == backgroundColorsBuffer ) ? 0u : *( backgroundColorIndicesBuffer + i );
       const Vector4& backgroundColor = ( 0u == backgroundColorIndex ) ? defaultBackgroundColor : *( backgroundColorsBuffer + backgroundColorIndex - 1u );
 
+      mModel->mVisualModel->GetNumberOfLines(i, 1, lineIndex, numberOfLines);
+      Length lineHeight = lineRun[lineIndex].ascender + -(lineRun[lineIndex].descender) + lineRun[lineIndex].lineSpacing;
+
+      if(lineIndex != prevLineIndex)
+      {
+        yLineOffset += lineHeight;
+      }
+
       // Only create quads for glyphs with a background color
-      if ( backgroundColor != Color::TRANSPARENT )
+      if(backgroundColor != Color::TRANSPARENT)
       {
-        const Vector2 position = *( positionsBuffer + i );
+        const Vector2 position = *(positionsBuffer + i);
 
-        if ( i == 0u && glyphSize == 1u ) // Only one glyph in the whole text
+        if(i == 0u && glyphSize == 1u) // Only one glyph in the whole text
         {
           quad.x = position.x;
-          quad.y = 0.0f;
-          quad.z = quad.x + std::max( glyph.advance, glyph.xBearing + glyph.width );
-          quad.w = textSize.height;
+          quad.y = yLineOffset;
+          quad.z = quad.x + std::max(glyph.advance, glyph.xBearing + glyph.width);
+          quad.w = lineHeight;
         }
-        else if ( i == 0u ) // The first glyph in the whole text
+        else if((lineIndex != prevLineIndex) || (i == 0u)) // The first glyph in the line
         {
           quad.x = position.x;
-          quad.y = 0.0f;
+          quad.y = yLineOffset;
           quad.z = quad.x - glyph.xBearing + glyph.advance;
-          quad.w = textSize.height;
+          quad.w = quad.y + lineHeight;
         }
-        else if ( i == glyphSize - 1u ) // The last glyph in the whole text
+        else if(i == glyphSize - 1u) // The last glyph in the whole text
         {
           quad.x = position.x - glyph.xBearing;
-          quad.y = 0.0f;
-          quad.z = quad.x + std::max( glyph.advance, glyph.xBearing + glyph.width );
-          quad.w = textSize.height;
+          quad.y = yLineOffset;
+          quad.z = quad.x + std::max(glyph.advance, glyph.xBearing + glyph.width);
+          quad.w = quad.y + lineHeight;
         }
         else // The glyph in the middle of the text
         {
           quad.x = position.x - glyph.xBearing;
-          quad.y = 0.0f;
+          quad.y = yLineOffset;
           quad.z = quad.x + glyph.advance;
-          quad.w = textSize.height;
+          quad.w = quad.y + lineHeight;
         }
 
         BackgroundVertex vertex;
@@ -2787,36 +2799,41 @@ Actor Controller::Impl::CreateBackgroundActor()
         vertex.mPosition.x = quad.x - offsetX;
         vertex.mPosition.y = quad.y - offsetY;
         vertex.mColor = backgroundColor;
-        mesh.mVertices.PushBack( vertex );
+        mesh.mVertices.PushBack(vertex);
 
         // Top right
         vertex.mPosition.x = quad.z - offsetX;
         vertex.mPosition.y = quad.y - offsetY;
         vertex.mColor = backgroundColor;
-        mesh.mVertices.PushBack( vertex );
+        mesh.mVertices.PushBack(vertex);
 
         // Bottom left
         vertex.mPosition.x = quad.x - offsetX;
         vertex.mPosition.y = quad.w - offsetY;
         vertex.mColor = backgroundColor;
-        mesh.mVertices.PushBack( vertex );
+        mesh.mVertices.PushBack(vertex);
 
         // Bottom right
         vertex.mPosition.x = quad.z - offsetX;
         vertex.mPosition.y = quad.w - offsetY;
         vertex.mColor = backgroundColor;
-        mesh.mVertices.PushBack( vertex );
+        mesh.mVertices.PushBack(vertex);
 
         // Six indices in counter clockwise winding
-        mesh.mIndices.PushBack( 1u + 4 * numberOfQuads );
-        mesh.mIndices.PushBack( 0u + 4 * numberOfQuads );
-        mesh.mIndices.PushBack( 2u + 4 * numberOfQuads );
-        mesh.mIndices.PushBack( 2u + 4 * numberOfQuads );
-        mesh.mIndices.PushBack( 3u + 4 * numberOfQuads );
-        mesh.mIndices.PushBack( 1u + 4 * numberOfQuads );
+        mesh.mIndices.PushBack(1u + 4 * numberOfQuads);
+        mesh.mIndices.PushBack(0u + 4 * numberOfQuads);
+        mesh.mIndices.PushBack(2u + 4 * numberOfQuads);
+        mesh.mIndices.PushBack(2u + 4 * numberOfQuads);
+        mesh.mIndices.PushBack(3u + 4 * numberOfQuads);
+        mesh.mIndices.PushBack(1u + 4 * numberOfQuads);
 
         numberOfQuads++;
       }
+
+      if(lineIndex != prevLineIndex)
+      {
+        prevLineIndex = lineIndex;
+      }
     }
 
     // Only create the background actor if there are glyphs with background color