mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 03:58:47 +02:00
Font: Fixed high-level ImGui::CalcTextSize() used by most widgets from erroneously subtracting 1.0f*scale to calculated text width. Among noticeable side-effects, it would make sequences of repeated Text/SameLine calls not align the same as a single call, and create mismatch between high-level size calculation and those performed with the lower-level ImDrawList api. (#792)
This commit is contained in:
@ -3909,11 +3909,7 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex
|
||||
return ImVec2(0.0f, font_size);
|
||||
ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL);
|
||||
|
||||
// Cancel out character spacing for the last character of a line (it is baked into glyph->AdvanceX field)
|
||||
const float font_scale = font_size / font->FontSize;
|
||||
const float character_spacing_x = 1.0f * font_scale;
|
||||
if (text_size.x > 0.0f)
|
||||
text_size.x -= character_spacing_x;
|
||||
// Round
|
||||
text_size.x = (float)(int)(text_size.x + 0.95f);
|
||||
|
||||
return text_size;
|
||||
|
Reference in New Issue
Block a user