MCPcopy Create free account
hub / github.com/SpartanJ/eepp / positionRichTextChildren

Method positionRichTextChildren

src/eepp/ui/blocklayouter.cpp:108–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108void BlockLayouter::positionRichTextChildren( Graphics::RichText* rt ) {
109 const auto& lines = rt->getLines();
110 Node* child = mContainer->getFirstChild();
111
112 size_t currentLine = 0;
113 size_t currentSpan = 0;
114
115 auto getNextCustomSpan = [&]() -> const RichText::RenderSpan* {
116 while ( currentLine < lines.size() ) {
117 const auto& line = lines[currentLine];
118 while ( currentSpan < line.spans.size() ) {
119 const auto& span = line.spans[currentSpan];
120 currentSpan++;
121 if ( std::holds_alternative<RichText::CustomBlock>( span.block ) )
122 return &span;
123 }
124 currentSpan = 0;
125 currentLine++;
126 }
127 return nullptr;
128 };
129
130 Int64 curCharIdx = 0;
131
132 auto processWidget = [&]( UIWidget* widget, auto& processWidgetRef ) -> Rectf {
133 constexpr Float maxF = std::numeric_limits<Float>::max();
134 constexpr Float lowF = std::numeric_limits<Float>::lowest();
135 Rectf bounds( maxF, maxF, lowF, lowF );
136
137 Vector2f offset;
138 Node* p = widget->getParent();
139 while ( p && p != mContainer ) {
140 offset += p->isWidget() ? p->asType<UIWidget>()->getPixelsPosition() : p->getPosition();
141 p = p->getParent();
142 }
143
144 if ( widget->isType( UI_TYPE_TEXTSPAN ) ) {
145 UITextSpan* textSpan = widget->asType<UITextSpan>();
146 Int64 startChar = curCharIdx;
147 Int64 endChar = curCharIdx;
148 if ( !textSpan->getText().empty() ) {
149 endChar += textSpan->getText().length();
150 curCharIdx = endChar;
151 }
152
153 auto& hitBoxes = textSpan->getHitBoxes();
154 hitBoxes.clear();
155
156 if ( startChar < endChar ) {
157 for ( const auto& line : lines ) {
158 bool passedText = false;
159 for ( const auto& rspan : line.spans ) {
160 if ( rspan.startCharIndex >= startChar && rspan.endCharIndex <= endChar ) {
161 Rectf hb( mContainer->getPixelsPadding().Left + rspan.position.x,
162 mContainer->getPixelsPadding().Top + line.y +
163 rspan.position.y,
164 mContainer->getPixelsPadding().Left + rspan.position.x +
165 rspan.size.getWidth(),

Callers

nothing calls this directly

Calls 15

eemaxFunction · 0.85
getLinesMethod · 0.80
getFirstChildMethod · 0.80
isWidgetMethod · 0.80
push_backMethod · 0.80
getNextNodeMethod · 0.80
setPixelsPositionMethod · 0.80
getPrevNodeMethod · 0.80
sizeMethod · 0.45
getParentMethod · 0.45
getPositionMethod · 0.45
isTypeMethod · 0.45

Tested by

no test coverage detected