MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / AddTextVertical

Function AddTextVertical

Source/3rdParty/implot/implot.cpp:378–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376//-----------------------------------------------------------------------------
377
378void AddTextVertical(ImDrawList *DrawList, ImVec2 pos, ImU32 col, const char *text_begin, const char* text_end) {
379 // the code below is based loosely on ImFont::RenderText
380 if (!text_end)
381 text_end = text_begin + strlen(text_begin);
382 ImGuiContext& g = *GImGui;
383#ifdef IMGUI_HAS_TEXTURES
384 ImFontBaked* font = g.Font->GetFontBaked(g.FontSize);
385 const float scale = g.FontSize / font->Size;
386#else
387 ImFont* font = g.Font;
388 const float scale = g.FontSize / font->FontSize;
389#endif
390 // Align to be pixel perfect
391 pos.x = ImFloor(pos.x);
392 pos.y = ImFloor(pos.y);
393 const char* s = text_begin;
394 int chars_exp = (int)(text_end - s);
395 int chars_rnd = 0;
396 const int vtx_count_max = chars_exp * 4;
397 const int idx_count_max = chars_exp * 6;
398 DrawList->PrimReserve(idx_count_max, vtx_count_max);
399 while (s < text_end) {
400 unsigned int c = (unsigned int)*s;
401 if (c < 0x80) {
402 s += 1;
403 }
404 else {
405 s += ImTextCharFromUtf8(&c, s, text_end);
406 if (c == 0) // Malformed UTF-8?
407 break;
408 }
409 const ImFontGlyph * glyph = font->FindGlyph((ImWchar)c);
410 if (glyph == nullptr) {
411 continue;
412 }
413 DrawList->PrimQuadUV(pos + ImVec2(glyph->Y0, -glyph->X0) * scale, pos + ImVec2(glyph->Y0, -glyph->X1) * scale,
414 pos + ImVec2(glyph->Y1, -glyph->X1) * scale, pos + ImVec2(glyph->Y1, -glyph->X0) * scale,
415 ImVec2(glyph->U0, glyph->V0), ImVec2(glyph->U1, glyph->V0),
416 ImVec2(glyph->U1, glyph->V1), ImVec2(glyph->U0, glyph->V1),
417 col);
418 pos.y -= glyph->AdvanceX * scale;
419 chars_rnd++;
420 }
421 // Give back unused vertices
422 int chars_skp = chars_exp-chars_rnd;
423 DrawList->PrimUnreserve(chars_skp*6, chars_skp*4);
424}
425
426void AddTextCentered(ImDrawList* DrawList, ImVec2 top_center, ImU32 col, const char* text_begin, const char* text_end) {
427 float txt_ht = ImGui::GetTextLineHeight();

Callers 3

SetupFinishFunction · 0.85
ColormapScaleFunction · 0.85
PlotTextFunction · 0.85

Calls 9

strlenFunction · 0.85
ImFloorFunction · 0.85
ImTextCharFromUtf8Function · 0.85
ImVec2Function · 0.85
PrimReserveMethod · 0.80
FindGlyphMethod · 0.80
PrimQuadUVMethod · 0.80
PrimUnreserveMethod · 0.80
GetFontBakedMethod · 0.45

Tested by

no test coverage detected