| 106 | } |
| 107 | |
| 108 | void 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(), |
nothing calls this directly
no test coverage detected