| 239 | } |
| 240 | |
| 241 | Text::DrawResult Text::draw( ImDrawList& list, ImVec2 pos, const TextColor& defaultTextColor ) const |
| 242 | { |
| 243 | DrawResult ret; |
| 244 | |
| 245 | update(); |
| 246 | |
| 247 | ImU32 defaultColorFixed = defaultTextColor.color ? *defaultTextColor.color : ImGui::ColorConvertFloat4ToU32( ImGui::GetStyleColorVec4( ImGuiCol_Text ) ); |
| 248 | ImU32 curColor = defaultColorFixed; |
| 249 | |
| 250 | // Specifically for the full text size, we don't do `max( size, computedSize )`, as it makes more sense this way. |
| 251 | // See the comment on `size` in the class. |
| 252 | ImVec2 curPos = pos + ( size - computedSize ) * align; |
| 253 | ret.cornerA = curPos; |
| 254 | ret.cornerB = curPos + computedSize; |
| 255 | |
| 256 | FontAndSize curFont = defaultFont; |
| 257 | |
| 258 | for ( const Line& line : lines ) |
| 259 | { |
| 260 | ImVec2 linePos = curPos + ( line.computedSizeWithPadding - line.computedSize ) * line.align; |
| 261 | curPos.y += line.computedSizeWithPadding.y; |
| 262 | |
| 263 | for ( const Elem& elem : line.elems ) |
| 264 | { |
| 265 | ImVec2 elemPos = linePos + ( elem.computedSizeWithPadding - elem.computedSize ) * elem.align; |
| 266 | linePos.x += elem.computedSizeWithPadding.x; |
| 267 | |
| 268 | std::visit( overloaded{ |
| 269 | [&]( const std::string& str ) |
| 270 | { |
| 271 | if ( curFont.first ) |
| 272 | ImGui::PushFont( curFont.first, curFont.second ); |
| 273 | MR_FINALLY{ |
| 274 | if ( curFont.first ) |
| 275 | ImGui::PopFont(); |
| 276 | }; |
| 277 | |
| 278 | list.AddText( elemPos, curColor, str.c_str() ); |
| 279 | }, |
| 280 | [&]( TextIcon icon ) |
| 281 | { |
| 282 | switch ( icon ) |
| 283 | { |
| 284 | case TextIcon::diameter: |
| 285 | list.AddCircle( elemPos + elem.computedSize / 2, elem.computedSize.x / 2 - 2 * UI::scale(), curColor, 0, 1.1f * UI::scale() ); |
| 286 | list.AddLine( |
| 287 | elemPos + ImVec2( elem.computedSize.x - 1.5f, 0.5f ) - ImVec2( 0.5f, 0.5f ), |
| 288 | elemPos + ImVec2( 1.5f, elem.computedSize.y - 0.5f ) - ImVec2( 0.5f, 0.5f ), |
| 289 | curColor, 1.1f * UI::scale() |
| 290 | ); |
| 291 | break; |
| 292 | } |
| 293 | }, |
| 294 | [&]( const TextColor& color ) |
| 295 | { |
| 296 | curColor = color.color ? *color.color : defaultColorFixed; |
| 297 | }, |
| 298 | [&]( const TextFont& font ) |