2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <dali/public-api/actors/layer.h>
19 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
20 #include <dali-toolkit/devel-api/controls/control-devel.h>
21 #include <dali-toolkit/internal/controls/text-controls/common-text-utils.h>
22 #include <dali-toolkit/internal/text/text-view.h>
24 namespace Dali::Toolkit::Internal
26 void CommonTextUtils::SynchronizeTextAnchorsInParent(
28 Text::ControllerPtr controller,
29 std::vector<Toolkit::TextAnchor>& anchorActors)
31 for(auto& anchorActor : anchorActors)
33 parent.Remove(anchorActor);
35 if(Dali::Accessibility::IsUp())
37 controller->GetAnchorActors(anchorActors);
38 for(auto& anchorActor : anchorActors)
40 parent.Add(anchorActor);
45 void CommonTextUtils::RenderText(
47 Text::RendererPtr renderer,
48 Text::ControllerPtr controller,
49 Text::DecoratorPtr decorator,
50 float& alignmentOffset,
51 Actor& renderableActor,
52 Actor& backgroundActor,
53 Toolkit::Control& stencil,
54 std::vector<Actor>& clippingDecorationActors,
55 std::vector<Toolkit::TextAnchor>& anchorActors,
56 Text::Controller::UpdateTextType updateTextType)
58 Actor newRenderableActor;
60 if(Text::Controller::NONE_UPDATED != (Text::Controller::MODEL_UPDATED & updateTextType))
64 newRenderableActor = renderer->Render(controller->GetView(),
66 Property::INVALID_INDEX, // Animatable property not supported
71 if(renderableActor != newRenderableActor)
73 UnparentAndReset(backgroundActor);
74 UnparentAndReset(renderableActor);
75 renderableActor = newRenderableActor;
79 backgroundActor = controller->CreateBackgroundActor();
86 const Vector2& scrollOffset = controller->GetTextModel()->GetScrollPosition();
88 float renderableActorPositionX, renderableActorPositionY;
92 renderableActorPositionX = scrollOffset.x + alignmentOffset;
93 renderableActorPositionY = scrollOffset.y;
98 padding = textActor.GetProperty<Extents>(Toolkit::Control::Property::PADDING);
100 // Support Right-To-Left of padding
101 Dali::LayoutDirection::Type layoutDirection = static_cast<Dali::LayoutDirection::Type>(textActor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
102 if(Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection)
104 std::swap(padding.start, padding.end);
107 renderableActorPositionX = scrollOffset.x + alignmentOffset + padding.start;
108 renderableActorPositionY = scrollOffset.y + padding.top;
111 renderableActor.SetProperty(Actor::Property::POSITION, Vector2(renderableActorPositionX, renderableActorPositionY));
113 // Make sure the actors are parented correctly with/without clipping
114 Actor self = stencil ? stencil : textActor;
116 Actor highlightActor;
118 for(std::vector<Actor>::iterator it = clippingDecorationActors.begin(),
119 endIt = clippingDecorationActors.end();
126 if(it->GetProperty<std::string>(Dali::Actor::Property::NAME) == "HighlightActor")
128 highlightActor = *it;
131 clippingDecorationActors.clear();
133 self.Add(renderableActor);
137 if(decorator && decorator->IsHighlightVisible())
139 self.Add(backgroundActor);
140 backgroundActor.SetProperty(Actor::Property::POSITION, Vector2(renderableActorPositionX, renderableActorPositionY)); // In text field's coords.
141 backgroundActor.LowerBelow(highlightActor);
145 renderableActor.Add(backgroundActor);
146 backgroundActor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f)); // In renderable actor's coords.
147 backgroundActor.LowerToBottom();
150 SynchronizeTextAnchorsInParent(textActor, controller, anchorActors);
154 } // namespace Dali::Toolkit::Internal