MCPcopy Create free account
hub / github.com/RenderKit/embree / CalcTextSize

Method CalcTextSize

tutorials/common/imgui/imgui.cpp:5277–5301  ·  view source on GitHub ↗

Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker. CalcTextSize("") should return ImVec2(0.0f, g.FontSize)

Source from the content-addressed store, hash-verified

5275// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
5276// CalcTextSize("") should return ImVec2(0.0f, g.FontSize)
5277ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_text_after_double_hash, float wrap_width)
5278{
5279 ImGuiContext& g = *GImGui;
5280
5281 const char* text_display_end;
5282 if (hide_text_after_double_hash)
5283 text_display_end = FindRenderedTextEnd(text, text_end); // Hide anything after a '##' string
5284 else
5285 text_display_end = text_end;
5286
5287 ImFont* font = g.Font;
5288 const float font_size = g.FontSize;
5289 if (text == text_display_end)
5290 return ImVec2(0.0f, font_size);
5291 ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL);
5292
5293 // Round
5294 // FIXME: This has been here since Dec 2015 (7b0bf230) but down the line we want this out.
5295 // FIXME: Investigate using ceilf or e.g.
5296 // - https://git.musl-libc.org/cgit/musl/tree/src/math/ceilf.c
5297 // - https://embarkstudios.github.io/rust-gpu/api/src/libm/math/ceilf.rs.html
5298 text_size.x = IM_FLOOR(text_size.x + 0.99999f);
5299
5300 return text_size;
5301}
5302
5303// Find window given position, search front-to-back
5304// FIXME: Note that we have an inconsequential lag here: OuterRectClipped is updated in Begin(), so windows moved programmatically

Callers

nothing calls this directly

Calls 2

ImVec2Function · 0.85
CalcTextSizeAMethod · 0.80

Tested by

no test coverage detected