Less garbage per frame: scalar text-size path (ImFontCalcTextSizeXY, ImGui.CalcTextSizeXY) for TextEx/ButtonEx, scratch rects in ButtonEx (160 -> 103 KB/frame on demo+stress)

This commit is contained in:
4DBug committed 2026-10-17 08:43:13 -05:00
1 parent 0663b79ddd
commit 5029525f2a
8 files changed
+134 -92

No files matched your search

+11 -8
View File
@@ -14660,10 +14660,10 @@ end
--- @param hide_text_after_double_hash? bool
--- @param wrap_width? float
--- @return ImVec2
-- [Luau] scalar CalcTextSizeEx(): returns x, y without allocating an ImVec2 (hot widget paths)
@native
function ImGui.CalcTextSizeEx(text, text_begin, text_end, hide_text_after_double_hash, wrap_width)
if hide_text_after_double_hash == nil then hide_text_after_double_hash = false end
if wrap_width == nil then wrap_width = -1.0 end
function ImGui.CalcTextSizeXY(text, text_begin, text_end, hide_text_after_double_hash, wrap_width)
if wrap_width == nil then wrap_width = -1.0 end
local g = GImGui
@@ -14674,19 +14674,22 @@ function ImGui.CalcTextSizeEx(text, text_begin, text_end, hide_text_after_double
text_display_end = text_end
end
local font = g.Font
local font_size = g.FontSize
if text == "" or (text_end and text_end <= text_begin) then
return ImVec2(0.0, font_size)
return 0.0, font_size
end
local text_size = ImFontCalcTextSizeEx(font, font_size, FLT_MAX, wrap_width, text, text_begin, text_display_end, text_display_end, nil, ImDrawTextFlags.None) -- [Luau] inline font:CalcTextSizeA()
local x, y = ImFontCalcTextSizeXY(g.Font, font_size, FLT_MAX, wrap_width, text, text_begin, text_display_end, text_display_end, nil, ImDrawTextFlags.None) -- [Luau] inline font:CalcTextSizeA()
-- Round
-- (see 7b0bf230, 4622fa4b6, #791 for details about this.)
-- FIXME: Add a way to disable this.
text_size.x = math.ceil(text_size.x) -- [Luau] == ImCeilFast() for all finite values, builtin
return math.ceil(x), y -- [Luau] == ImCeilFast() for all finite values, builtin
end
return text_size
@native
function ImGui.CalcTextSizeEx(text, text_begin, text_end, hide_text_after_double_hash, wrap_width)
local x, y = ImGui.CalcTextSizeXY(text, text_begin, text_end, hide_text_after_double_hash, wrap_width)
return ImVec2(x, y)
end
-- Pass this to your backend rendering function! Valid after Render() and until the next call to NewFrame()