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:
1 parent
0663b79ddd
commit
5029525f2a
8 files changed
+134
-92
No files matched your search
+8
-5
@@ -110,13 +110,13 @@ function ImGui.TextEx(text, text_end, flags)
|
||||
-- [Luau] scalar text_pos, scratch bb (ItemAdd() copies it, RenderTextWrapped() only reads it)
|
||||
local text_pos_x, text_pos_y = dc.CursorPos.x, dc.CursorPos.y + dc.CurrLineTextBaseOffset
|
||||
local wrap_width = wrap_enabled and ImGui.CalcWrapWidthForPos(dc.CursorPos, wrap_pos_x) or 0.0
|
||||
local text_size = ImGui.CalcTextSizeEx(text, 1, text_end, false, wrap_width)
|
||||
local text_size_x, text_size_y = ImGui.CalcTextSizeXY(text, 1, text_end, false, wrap_width)
|
||||
|
||||
local bb = TextEx_bb
|
||||
local bb_min, bb_max = bb.Min, bb.Max
|
||||
bb_min.x = text_pos_x; bb_min.y = text_pos_y
|
||||
bb_max.x = text_pos_x + text_size.x; bb_max.y = text_pos_y + text_size.y
|
||||
ImGui.ItemSize(text_size, 0.0)
|
||||
bb_max.x = text_pos_x + text_size_x; bb_max.y = text_pos_y + text_size_y
|
||||
ImGui.ItemSize(bb, 0.0) -- [Luau] the bb's size == text_size
|
||||
if not ImGui.ItemAdd(bb, 0) then
|
||||
return
|
||||
end
|
||||
@@ -744,6 +744,7 @@ end
|
||||
--- @param size_arg? ImVec2
|
||||
--- @param flags? ImGuiButtonFlags
|
||||
--- @return bool
|
||||
local ButtonEx_bb, ButtonEx_label_size = ImRect(), ImVec2()
|
||||
local ButtonEx_text_min, ButtonEx_text_max = ImVec2(), ImVec2()
|
||||
|
||||
@native
|
||||
@@ -760,7 +761,8 @@ function ImGui.ButtonEx(label, size_arg, flags)
|
||||
local style = g.Style
|
||||
local id = window:GetID(label)
|
||||
local label_end = ImGui.FindRenderedTextEnd(label)
|
||||
local label_size = ImGui.CalcTextSize(label, label_end, false)
|
||||
local label_size = ButtonEx_label_size -- [Luau] scratch: only read below (RenderTextClipped text_size_if_known)
|
||||
label_size.x, label_size.y = ImGui.CalcTextSizeXY(label, 1, label_end, false)
|
||||
|
||||
-- [Luau] scalar pos, no temporary ImVec2
|
||||
local pos_x, pos_y = window.DC.CursorPos.x, window.DC.CursorPos.y
|
||||
@@ -770,7 +772,8 @@ function ImGui.ButtonEx(label, size_arg, flags)
|
||||
end
|
||||
local size = ImGui.CalcItemSize(size_arg, label_size.x + frame_padding.x * 2.0, label_size.y + frame_padding.y * 2.0)
|
||||
|
||||
local bb = ImRect(pos_x, pos_y, pos_x + size.x, pos_y + size.y)
|
||||
local bb = ButtonEx_bb -- [Luau] scratch: ItemAdd() copies it, ButtonBehavior()/Render*() only read it
|
||||
bb.Min.x, bb.Min.y, bb.Max.x, bb.Max.y = pos_x, pos_y, pos_x + size.x, pos_y + size.y
|
||||
ImGui.ItemSize(size, frame_padding.y)
|
||||
if not ImGui.ItemAdd(bb, id) then
|
||||
return false
|
||||
|
||||
Reference in new issue
Block a user