ImStrv: detect and fixed misuses of CalcTextSize() old signature. (9321)

For IMGUI_DISABLE_OBSOLETE_FUNCTIONS only.
This commit is contained in:
ocornut
2026-03-25 12:22:53 +01:00
parent 1a0dcccc95
commit f10c152608
4 changed files with 12 additions and 8 deletions

View File

@@ -17156,7 +17156,7 @@ bool ImGui::DebugBreakButton(const char* label, const char* description_of_locat
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
const ImGuiID id = window->GetID(label); const ImGuiID id = window->GetID(label);
const ImVec2 label_size = CalcTextSize(label, NULL, true); const ImVec2 label_size = CalcTextSize(label, true);
ImVec2 pos = window->DC.CursorPos + ImVec2(0.0f, window->DC.CurrLineTextBaseOffset); ImVec2 pos = window->DC.CursorPos + ImVec2(0.0f, window->DC.CurrLineTextBaseOffset);
ImVec2 size = ImVec2(label_size.x + g.Style.FramePadding.x * 2.0f, label_size.y); ImVec2 size = ImVec2(label_size.x + g.Style.FramePadding.x * 2.0f, label_size.y);

View File

@@ -1195,6 +1195,10 @@ IM_MSVC_RUNTIME_CHECKS_OFF
inline IM_FMTLIST(3) bool TreeNodeExV(const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) { return TreeNodeEx(ImStrv(str_id), flags, fmt, args); } inline IM_FMTLIST(3) bool TreeNodeExV(const char* str_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) { return TreeNodeEx(ImStrv(str_id), flags, fmt, args); }
inline void TreePush(const char* str_id) { TreePush(ImStrv(str_id)); } inline void TreePush(const char* str_id) { TreePush(ImStrv(str_id)); }
IM_MSVC_RUNTIME_CHECKS_RESTORE IM_MSVC_RUNTIME_CHECKS_RESTORE
// Detect misuses (#9321)
// FIXME-IMSTR: Validate that syntax is ok for our minimum target.
ImVec2 CalcTextSize(ImStrv, const char*, bool hide_text_after_double_hash = false, float wrap_width = -1.0f) = delete;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@@ -3099,7 +3099,7 @@ float ImGui::TableGetHeaderAngledMaxLabelWidth()
for (int column_n = 0; column_n < table->ColumnsCount; column_n++) for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n)) if (IM_BITARRAY_TESTBIT(table->EnabledMaskByIndex, column_n))
if (table->Columns[column_n].Flags & ImGuiTableColumnFlags_AngledHeader) if (table->Columns[column_n].Flags & ImGuiTableColumnFlags_AngledHeader)
width = ImMax(width, CalcTextSize(TableGetColumnName(table, column_n), NULL, true).x); width = ImMax(width, CalcTextSize(TableGetColumnName(table, column_n), true).x);
return width + g.Style.CellPadding.y * 2.0f; // Swap padding return width + g.Style.CellPadding.y * 2.0f; // Swap padding
} }

View File

@@ -1510,10 +1510,10 @@ bool ImGui::TextLink(ImStrv label)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
const ImGuiID id = window->GetID(label); const ImGuiID id = window->GetID(label);
const char* label_end = FindRenderedTextEnd(label); label.End = FindRenderedTextEnd(label);
ImVec2 pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); ImVec2 pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset);
ImVec2 size = CalcTextSize(label.Begin, label_end, true); ImVec2 size = CalcTextSize(label, true);
ImRect bb(pos, pos + size); ImRect bb(pos, pos + size);
ItemSize(size, 0.0f); ItemSize(size, 0.0f);
if (!ItemAdd(bb, id)) if (!ItemAdd(bb, id))
@@ -1547,7 +1547,7 @@ bool ImGui::TextLink(ImStrv label)
window->DrawList->AddLine(ImVec2(bb.Min.x, line_y), ImVec2(bb.Max.x, line_y), GetColorU32(line_colf), 1.0f * (float)(int)g.Style._MainScale); // FIXME-TEXT: Underline mode // FIXME-DPI window->DrawList->AddLine(ImVec2(bb.Min.x, line_y), ImVec2(bb.Max.x, line_y), GetColorU32(line_colf), 1.0f * (float)(int)g.Style._MainScale); // FIXME-TEXT: Underline mode // FIXME-DPI
PushStyleColor(ImGuiCol_Text, GetColorU32(text_colf)); PushStyleColor(ImGuiCol_Text, GetColorU32(text_colf));
RenderText(bb.Min, label.Begin, label_end); RenderText(bb.Min, label);
PopStyleColor(); PopStyleColor();
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags);
@@ -5587,14 +5587,14 @@ bool ImGui::InputTextEx(ImStrv label, ImStrv hint, char* buf, int buf_size, cons
float rect_width = 0.0f; float rect_width = 0.0f;
if (line_selected_begin < line_selected_end) if (line_selected_begin < line_selected_end)
rect_width += CalcTextSize(line_selected_begin, line_selected_end).x; rect_width += CalcTextSize(ImStrv(line_selected_begin, line_selected_end)).x;
if (text_selected_begin <= p_eol && text_selected_end > p_eol && !p_eol_is_wrap) if (text_selected_begin <= p_eol && text_selected_end > p_eol && !p_eol_is_wrap)
rect_width += bg_eol_width; // So we can see selected empty lines rect_width += bg_eol_width; // So we can see selected empty lines
if (rect_width == 0.0f) if (rect_width == 0.0f)
continue; continue;
ImRect rect; ImRect rect;
rect.Min.x = draw_pos.x - draw_scroll.x + CalcTextSize(p, line_selected_begin).x; rect.Min.x = draw_pos.x - draw_scroll.x + CalcTextSize(ImStrv(p, line_selected_begin)).x;
rect.Min.y = draw_pos.y - draw_scroll.y + line_n * g.FontSize; rect.Min.y = draw_pos.y - draw_scroll.y + line_n * g.FontSize;
rect.Max.x = rect.Min.x + rect_width; rect.Max.x = rect.Min.x + rect_width;
rect.Max.y = rect.Min.y + bg_offy_dn + g.FontSize; rect.Max.y = rect.Min.y + bg_offy_dn + g.FontSize;
@@ -5607,7 +5607,7 @@ bool ImGui::InputTextEx(ImStrv label, ImStrv hint, char* buf, int buf_size, cons
// Find render position for right alignment (single-line only) // Find render position for right alignment (single-line only)
if (g.ActiveId != id && (flags & ImGuiInputTextFlags_ElideLeft) && !render_cursor && !render_selection) if (g.ActiveId != id && (flags & ImGuiInputTextFlags_ElideLeft) && !render_cursor && !render_selection)
draw_pos.x = ImMin(draw_pos.x, frame_bb.Max.x - CalcTextSize(buf_display, NULL).x - style.FramePadding.x); draw_pos.x = ImMin(draw_pos.x, frame_bb.Max.x - CalcTextSize(buf_display).x - style.FramePadding.x);
//draw_scroll.x = state->Scroll.x; // Preserve scroll when inactive? //draw_scroll.x = state->Scroll.x; // Preserve scroll when inactive?
// Render text // Render text