From 24a2960745397eaea70e75cad271d883dbd79bf0 Mon Sep 17 00:00:00 2001 From: "joogab.yun" Date: Thu, 4 Nov 2021 10:52:15 +0900 Subject: [PATCH] [Tizen] Enable background color in TextEditor Change-Id: I867f3e5c38c40923f959a04fdff7a9ac58755171 --- .../controls/text-controls/text-editor-impl.cpp | 55 ++++++++++++++++++ .../controls/text-controls/text-editor-impl.h | 1 + .../internal/text/text-controller-impl.cpp | 67 ++++++++++++++-------- 3 files changed, 98 insertions(+), 25 deletions(-) diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index bd924a4..0312f6b 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -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(Toolkit::Control::Property::PADDING); + + // Support Right-To-Left of padding + Dali::LayoutDirection::Type layoutDirection = static_cast(Self().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); + 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::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(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(); diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h index 1fb17a9..ea093c9 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -350,6 +350,7 @@ private: // Data std::vector mClippingDecorationActors; ///< Decoration actors which need clipping. Actor mRenderableActor; + Actor mBackgroundActor; Actor mActiveLayer; CallbackBase* mIdleCallback; diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index ac871d6..70726ab 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -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 -- 2.7.4