Library: fewer temporaries per window, child, input field, separator text and resizable table: Begin() skips CalcWindowAutoFitSize() when no axis auto-fits (result unused; still called when a size callback would see it), scalar scrollbar/auto-fit/avail/needed sizes, ScrollbarSizes updated in place, scratch viewport/visibility rects, OuterRectClipped and the previous-child overlap test without ImRects; RenderWindowOuterBorders() scratch corner; EndChild() scratch size/bb; InputTextEx() scalar label/frame/inner sizes, scratch total_bb and (single-line, until ItemAdd() accepts it) frame_bb, so clipped fields allocate nothing; SeparatorTextEx() scratch sizes/rect/positions; TableUpdateBorders() scratch hit rect

demo_all scene headless: 825 -> 553 KB/frame allocated (Begin 5.3 -> 1.4 KB per window, InputTextEx 0.8 KB -> 0 per
clipped field), user instructions/frame -1.3%. GC steps in that scene cost ~+1.5 ms on 2-4 frames per cycle, so
cycles get ~1/3 rarer. Draw data unchanged.
This commit is contained in:
4DBug committed 2026-10-21 03:00:23 -05:00
1 parent 30afa19ed1
commit 278f978d3e
3 files changed
+97 -51

No files matched your search

+55 -25
View File
@@ -10831,12 +10831,15 @@ local function RenderWindowOuterSingleBorder(window, border_n, border_col, borde
window.DrawList:PathStroke(border_col, border_size)
end
local RenderWindowOuterBorders_max = ImVec2() -- [Luau] scratch, AddRect() only reads it
local function RenderWindowOuterBorders(window)
local g = GImGui
local border_size = window.WindowBorderSize
local border_col = ImGui.GetColorU32(ImGuiCol.Border)
if border_size > 0.0 and (bit32.band(window.Flags, ImGuiWindowFlags.NoBackground) == 0) then
window.DrawList:AddRect(window.Pos, window.Pos + window.Size, border_col, window.WindowRounding, window.WindowBorderSize, 0)
local p_max = RenderWindowOuterBorders_max
p_max.x = window.Pos.x + window.Size.x; p_max.y = window.Pos.y + window.Size.y
window.DrawList:AddRect(window.Pos, p_max, border_col, window.WindowRounding, window.WindowBorderSize, 0)
elseif border_size > 0.0 then
if bit32.band(window.ChildFlags, ImGuiChildFlags.ResizeX) ~= 0 then -- Similar code as 'resize_border_mask' computation in UpdateWindowManualResize() but we specifically only always draw explicit child resize border.
RenderWindowOuterSingleBorder(window, 1, border_col, border_size)
@@ -10866,6 +10869,7 @@ end
--- @param handle_borders_and_resize_grips bool
--- @param resize_grip_col ImU32[]
--- @param resize_grip_draw_size float
local Begin_viewport_rect, Begin_visibility_rect = ImRect(), ImRect() -- [Luau] Begin() scratch, see there
-- [Luau] scratch for RenderWindowDecorations()/RenderWindowTitleBarContents(): callees only read or copy these
local WindowDecoScratch = { text_size = ImVec2(), layout_r = ImRect(), clip_r = ImRect(), bg_rect = ImRect(), p = ImVec2(), title_bar_rect = ImRect() }
@@ -11703,6 +11707,7 @@ function ImGui.SetLastItemDataForChildWindowItem(window, rect)
ImGui.SetLastItemData(window.ChildId, g.CurrentItemFlags, window.DC.ChildItemStatusFlags or 0, rect)
end
local EndChild_size, EndChild_bb = ImVec2(), ImRect()
function ImGui.EndChild()
local g = GImGui
local child_window = g.CurrentWindow
@@ -11711,11 +11716,14 @@ function ImGui.EndChild()
IM_ASSERT(bit32.band(child_window.Flags, ImGuiWindowFlags.ChildWindow) ~= 0) -- Mismatched BeginChild()/EndChild() calls
g.WithinEndChildID = child_window.ID
local child_size = ImVec2(child_window.Size.x, child_window.Size.y)
local child_size_x, child_size_y = child_window.Size.x, child_window.Size.y -- [Luau] scalar copy
ImGui.End()
if child_window.BeginCount == 1 then
local parent_window = g.CurrentWindow
local bb = ImRect(parent_window.DC.CursorPos, parent_window.DC.CursorPos + child_size)
-- [Luau] scratch size/bb filled after End(): ItemSize()/ItemAdd() copy or read them, RenderNavCursor() reads bb
local child_size, bb, cursor = EndChild_size, EndChild_bb, parent_window.DC.CursorPos
child_size.x = child_size_x; child_size.y = child_size_y
bb.Min.x = cursor.x; bb.Min.y = cursor.y; bb.Max.x = cursor.x + child_size_x; bb.Max.y = cursor.y + child_size_y
ImGui.ItemSize(child_size)
local nav_flattened = bit32.band(child_window.ChildFlags, ImGuiChildFlags.NavFlattened) ~= 0
if (child_window.DC.NavLayersActiveMask ~= 0 or child_window.DC.NavWindowHasScrollY) and not nav_flattened then
@@ -12516,14 +12524,13 @@ function ImGui.Begin(name, open, flags)
-- Outer Decoration Sizes
-- (we need to clear ScrollbarSize immediately as CalcWindowAutoFitSize() needs it and can be called from other locations).
local scrollbar_sizes_from_last_frame = ImVec2()
ImVec2_Copy(scrollbar_sizes_from_last_frame, window.ScrollbarSizes)
local scrollbar_sizes_from_last_frame_x, scrollbar_sizes_from_last_frame_y = window.ScrollbarSizes.x, window.ScrollbarSizes.y -- [Luau] scalar copy
window.DecoOuterSizeX1 = 0.0
window.DecoOuterSizeX2 = 0.0
window.DecoOuterSizeY1 = window.TitleBarHeight + window.MenuBarHeight
window.DecoOuterSizeY2 = 0.0
window.ScrollbarSizes = ImVec2(0.0, 0.0)
window.ScrollbarSizes.x = 0.0; window.ScrollbarSizes.y = 0.0 -- [Luau] in place
-- Calculate auto-fit size, handle automatic resize
-- - Using SetNextWindowSize() overrides ImGuiWindowFlags.AlwaysAutoResize, so it can be used on tooltips/popups, etc.
@@ -12543,8 +12550,12 @@ function ImGui.Begin(name, open, flags)
size_auto_fit_mask = bit32.bor(size_auto_fit_mask, bit32.lshift(1, ImGuiAxis.Y - 1))
end
local size_auto_fit = CalcWindowAutoFitSize(window, window.ContentSizeIdeal, size_auto_fit_mask)
local old_size = ImVec2(window.SizeFull.x, window.SizeFull.y)
-- [Luau] the auto-fit size is only read when an axis auto-fits: not computed otherwise (unless a size callback would see the call)
local size_auto_fit
if size_auto_fit_mask ~= 0 or (bit32.band(g.NextWindowData.HasFlags, ImGuiNextWindowDataFlags.HasSizeConstraint) ~= 0 and g.NextWindowData.SizeCallback) then
size_auto_fit = CalcWindowAutoFitSize(window, window.ContentSizeIdeal, size_auto_fit_mask)
end
local old_size_x, old_size_y = window.SizeFull.x, window.SizeFull.y -- [Luau] scalar copy
if size_auto_fit_x_always or size_auto_fit_x_current then
if size_auto_fit_x_always then
@@ -12571,7 +12582,7 @@ function ImGui.Begin(name, open, flags)
use_current_size_for_scrollbar_y = true
end
if old_size.x ~= window.SizeFull.x or old_size.y ~= window.SizeFull.y then
if old_size_x ~= window.SizeFull.x or old_size_y ~= window.SizeFull.y then
ImGui.MarkIniSettingsDirty(window)
end
end
@@ -12633,10 +12644,19 @@ function ImGui.Begin(name, open, flags)
-- Calculate the range of allowed position for that window (to be movable and visible past safe area padding)
-- When clamping to stay visible, we will enforce that window.Pos stays inside of visibility_rect.
local viewport_rect = window.Viewport:GetMainRect()
local viewport_work_rect = window.Viewport:GetWorkRect()
local visibility_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding)
local visibility_rect = ImRect(viewport_work_rect.Min.x + visibility_padding.x, viewport_work_rect.Min.y + visibility_padding.y, viewport_work_rect.Max.x - visibility_padding.x, viewport_work_rect.Max.y - visibility_padding.y) -- [Luau] scalar form: no temporary ImVec2s
-- [Luau] scratch rects filled in place (only read, last read by PushClipRect() below; no nested Begin() in between), scalar padding
local viewport_rect = Begin_viewport_rect
do
local vp = window.Viewport
local r_min, r_max = viewport_rect.Min, viewport_rect.Max
r_min.x = vp.Pos.x; r_min.y = vp.Pos.y; r_max.x = vp.Pos.x + vp.Size.x; r_max.y = vp.Pos.y + vp.Size.y
end
local work_pos, work_size = window.Viewport.WorkPos, window.Viewport.WorkSize
local visibility_padding_x = ImMax(style.DisplayWindowPadding.x, style.DisplaySafeAreaPadding.x)
local visibility_padding_y = ImMax(style.DisplayWindowPadding.y, style.DisplaySafeAreaPadding.y)
local visibility_rect = Begin_visibility_rect
visibility_rect.Min.x = work_pos.x + visibility_padding_x; visibility_rect.Min.y = work_pos.y + visibility_padding_y
visibility_rect.Max.x = (work_pos.x + work_size.x) - visibility_padding_x; visibility_rect.Max.y = (work_pos.y + work_size.y) - visibility_padding_y
-- Clamp position/size so window stays visible within its viewport or monitor
-- Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
@@ -12734,18 +12754,24 @@ function ImGui.Begin(name, open, flags)
-- When reading the current size we need to read it after size constraints have been applied.
-- Intentionally use previous frame values for InnerRect and ScrollbarSizes.
-- And when we use window.DecorationUp here it doesn't have ScrollbarSizes.y applied yet.
local avail_size_from_current_frame = ImVec2(window.SizeFull.x, window.SizeFull.y - (window.DecoOuterSizeY1 + window.DecoOuterSizeY2))
local avail_size_from_last_frame = window.InnerRect:GetSize() + scrollbar_sizes_from_last_frame
local needed_size_from_last_frame = window_just_created and ImVec2(0, 0) or window.ContentSize + window.WindowPadding * 2.0
-- [Luau] scalar avail/needed sizes
local avail_size_from_current_frame_x, avail_size_from_current_frame_y = window.SizeFull.x, window.SizeFull.y - (window.DecoOuterSizeY1 + window.DecoOuterSizeY2)
local inner_rect = window.InnerRect
local avail_size_from_last_frame_x = (inner_rect.Max.x - inner_rect.Min.x) + scrollbar_sizes_from_last_frame_x
local avail_size_from_last_frame_y = (inner_rect.Max.y - inner_rect.Min.y) + scrollbar_sizes_from_last_frame_y
local needed_size_from_last_frame_x, needed_size_from_last_frame_y = 0, 0
if not window_just_created then
needed_size_from_last_frame_x = window.ContentSize.x + window.WindowPadding.x * 2.0; needed_size_from_last_frame_y = window.ContentSize.y + window.WindowPadding.y * 2.0
end
local size_for_scrollbars_x = use_current_size_for_scrollbar_x and avail_size_from_current_frame.x or avail_size_from_last_frame.x
local size_for_scrollbars_y = use_current_size_for_scrollbar_y and avail_size_from_current_frame.y or avail_size_from_last_frame.y
local size_for_scrollbars_x = use_current_size_for_scrollbar_x and avail_size_from_current_frame_x or avail_size_from_last_frame_x
local size_for_scrollbars_y = use_current_size_for_scrollbar_y and avail_size_from_current_frame_y or avail_size_from_last_frame_y
local scrollbar_x_prev = window.ScrollbarX
-- local scrollbar_y_from_last_frame = window.ScrollbarY -- FIXME: May want to use that in the ScrollbarX expression? How many pros vs cons?
window.ScrollbarY = (bit32.band(flags, ImGuiWindowFlags.AlwaysVerticalScrollbar) ~= 0) or ((needed_size_from_last_frame.y > size_for_scrollbars_y) and not (bit32.band(flags, ImGuiWindowFlags.NoScrollbar) ~= 0))
window.ScrollbarX = (bit32.band(flags, ImGuiWindowFlags.AlwaysHorizontalScrollbar) ~= 0) or ((needed_size_from_last_frame.x > size_for_scrollbars_x - (window.ScrollbarY and style.ScrollbarSize or 0.0)) and not (bit32.band(flags, ImGuiWindowFlags.NoScrollbar) ~= 0) and (bit32.band(flags, ImGuiWindowFlags.HorizontalScrollbar) ~= 0))
window.ScrollbarY = (bit32.band(flags, ImGuiWindowFlags.AlwaysVerticalScrollbar) ~= 0) or ((needed_size_from_last_frame_y > size_for_scrollbars_y) and not (bit32.band(flags, ImGuiWindowFlags.NoScrollbar) ~= 0))
window.ScrollbarX = (bit32.band(flags, ImGuiWindowFlags.AlwaysHorizontalScrollbar) ~= 0) or ((needed_size_from_last_frame_x > size_for_scrollbars_x - (window.ScrollbarY and style.ScrollbarSize or 0.0)) and not (bit32.band(flags, ImGuiWindowFlags.NoScrollbar) ~= 0) and (bit32.band(flags, ImGuiWindowFlags.HorizontalScrollbar) ~= 0))
-- Track when ScrollbarX visibility keeps toggling, which is a sign of a feedback loop, and stabilize by enforcing visibility (#3285, #8488)
-- (Feedback loops of this sort can manifest in various situations, but combining horizontal + vertical scrollbar + using a clipper with varying width items is one frequent cause.
@@ -12766,10 +12792,10 @@ function ImGui.Begin(name, open, flags)
window.ScrollbarXStabilizeEnabled = scrollbar_x_stabilize
if window.ScrollbarX and not window.ScrollbarY then
window.ScrollbarY = (needed_size_from_last_frame.y > size_for_scrollbars_y - style.ScrollbarSize) and not (bit32.band(flags, ImGuiWindowFlags.NoScrollbar) ~= 0)
window.ScrollbarY = (needed_size_from_last_frame_y > size_for_scrollbars_y - style.ScrollbarSize) and not (bit32.band(flags, ImGuiWindowFlags.NoScrollbar) ~= 0)
end
window.ScrollbarSizes = ImVec2(window.ScrollbarY and style.ScrollbarSize or 0.0, window.ScrollbarX and style.ScrollbarSize or 0.0)
window.ScrollbarSizes.x = window.ScrollbarY and style.ScrollbarSize or 0.0; window.ScrollbarSizes.y = window.ScrollbarX and style.ScrollbarSize or 0.0 -- [Luau] in place
-- Amend the partially filled window.DecorationXXX values.
window.DecoOuterSizeX2 = window.DecoOuterSizeX2 + window.ScrollbarSizes.x
@@ -12791,9 +12817,11 @@ function ImGui.Begin(name, open, flags)
else
host_rect = viewport_rect
end
local outer_rect = window:Rect()
local title_bar_rect = window:TitleBarRect()
ImRect_Copy(window.OuterRectClipped, outer_rect)
do -- [Luau] ImRect_Copy(window.OuterRectClipped, window:Rect()) without the temporary ImRect
local r = window.OuterRectClipped
r.Min.x = window.Pos.x; r.Min.y = window.Pos.y; r.Max.x = window.Pos.x + window.Size.x; r.Max.y = window.Pos.y + window.Size.y
end
if window.DockIsActive then
window.OuterRectClipped.Min.y = window.OuterRectClipped.Min.y + window.TitleBarHeight
end
@@ -12868,7 +12896,9 @@ function ImGui.Begin(name, open, flags)
end
local previous_child_overlapping
if previous_child ~= nil then
previous_child_overlapping = previous_child:Rect():Overlaps(window:Rect())
-- [Luau] scalar previous_child:Rect():Overlaps(window:Rect())
local pp, ps, wp, ws = previous_child.Pos, previous_child.Size, window.Pos, window.Size
previous_child_overlapping = pp.x <= wp.x + ws.x and pp.x + ps.x >= wp.x and pp.y <= wp.y + ws.y and pp.y + ps.y >= wp.y
else
previous_child_overlapping = false
end
+4 -1
View File
@@ -1567,6 +1567,8 @@ function ImGui.TableApplyExternalUnclipRect(table_, rect)
end
end
local TableUpdateBorders_hit_rect = ImRect()
-- Process hit-testing on resizing borders. Actual size change will be applied in EndTable()
-- - Set table.HoveredColumnBorder with a short delay/timer to reduce visual feedback noise.
function ImGui.TableUpdateBorders(table_)
@@ -1606,7 +1608,8 @@ function ImGui.TableUpdateBorders(table_)
end
local column_id = ImGui.TableGetColumnResizeID(table_, column_n, table_.InstanceCurrent)
local hit_rect = ImRect(column.MaxX - hit_half_width, hit_y1, column.MaxX + hit_half_width, border_y2_hit)
local hit_rect = TableUpdateBorders_hit_rect -- [Luau] scratch: ItemAdd() copies it, ButtonBehavior() reads it
hit_rect.Min.x = column.MaxX - hit_half_width; hit_rect.Min.y = hit_y1; hit_rect.Max.x = column.MaxX + hit_half_width; hit_rect.Max.y = border_y2_hit
ImGui.ItemAdd(hit_rect, column_id, nil, ImGuiItemFlags.NoNav)
--ImGui.GetForegroundDrawList():AddRect(hit_rect.Min, hit_rect.Max, IM_COL32(255, 0, 0, 100))
+38 -25
View File
@@ -1903,19 +1903,25 @@ end
--- @param label string
--- @param label_end? int
--- @param extra_w float
local SeparatorTextEx_label_size, SeparatorTextEx_min_size, SeparatorTextEx_bb, SeparatorTextEx_label_pos, SeparatorTextEx_clip_max = ImVec2(), ImVec2(), ImRect(), ImVec2(), ImVec2()
function ImGui.SeparatorTextEx(id, label, label_end, extra_w)
local g = GImGui
local window = g.CurrentWindow
local style = g.Style
local label_size = ImGui.CalcTextSize(label, label_end, false)
local pos = ImVec2(window.DC.CursorPos.x, window.DC.CursorPos.y)
-- [Luau] scratch vectors/rect (callees only read them or copy them), scalar pos
local label_size = SeparatorTextEx_label_size
label_size.x, label_size.y = ImGui.CalcTextSizeXY(label, 1, label_end, false)
local pos_x, pos_y = window.DC.CursorPos.x, window.DC.CursorPos.y
local padding = style.SeparatorTextPadding
local separator_thickness = style.SeparatorTextBorderSize
local min_size = ImVec2(label_size.x + extra_w + padding.x * 2.0, ImMax(label_size.y + padding.y * 2.0, separator_thickness))
local min_size = SeparatorTextEx_min_size
min_size.x = label_size.x + extra_w + padding.x * 2.0; min_size.y = ImMax(label_size.y + padding.y * 2.0, separator_thickness)
local bb = ImRect(pos, ImVec2(window.WorkRect.Max.x, pos.y + min_size.y))
local bb = SeparatorTextEx_bb
bb.Min.x = pos_x; bb.Min.y = pos_y; bb.Max.x = window.WorkRect.Max.x; bb.Max.y = pos_y + min_size.y
local text_baseline_y = ImTrunc((bb:GetHeight() - label_size.y) * style.SeparatorTextAlign.y + 0.999) --ImMax(padding.y, ImTrunc((style.SeparatorTextSize - label_size.y) * 0.5f))
ImGui.ItemSize(min_size, text_baseline_y)
@@ -1923,12 +1929,13 @@ function ImGui.SeparatorTextEx(id, label, label_end, extra_w)
return
end
local sep1_x1 = pos.x
local sep1_x1 = pos_x
local sep2_x2 = bb.Max.x
local seps_y = ImTrunc((bb.Min.y + bb.Max.y) * 0.5) + 1.0
local label_avail_w = ImMax(0.0, sep2_x2 - sep1_x1 - padding.x * 2.0)
local label_pos = ImVec2(pos.x + padding.x + ImMax(0.0, (label_avail_w - label_size.x - extra_w) * style.SeparatorTextAlign.x), pos.y + text_baseline_y) -- FIXME-ALIGN
local label_pos = SeparatorTextEx_label_pos
label_pos.x = pos_x + padding.x + ImMax(0.0, (label_avail_w - label_size.x - extra_w) * style.SeparatorTextAlign.x); label_pos.y = pos_y + text_baseline_y -- FIXME-ALIGN
-- This allows using SameLine() to position something in the 'extra_w'
window.DC.CursorPosPrevLine.x = label_pos.x + label_size.x
@@ -1951,7 +1958,9 @@ function ImGui.SeparatorTextEx(id, label, label_end, extra_w)
ImGui.LogSetNextTextDecoration("---", nil)
end
ImGui.RenderTextEllipsis(window.DrawList, label_pos, ImVec2(bb.Max.x, bb.Max.y + style.ItemSpacing.y), bb.Max.x, label, label_end, label_size)
local clip_max = SeparatorTextEx_clip_max
clip_max.x = bb.Max.x; clip_max.y = bb.Max.y + style.ItemSpacing.y
ImGui.RenderTextEllipsis(window.DrawList, label_pos, clip_max, bb.Max.x, label, label_end, label_size)
else
if g.LogEnabled then
ImGui.LogText("---")
@@ -5500,6 +5509,7 @@ end
--- @param flags ImGuiInputTextFlags
--- @param callback? ImGuiInputTextCallback
--- @param callback_user_data any
local InputTextEx_frame_bb, InputTextEx_total_bb = ImRect(), ImRect() -- [Luau] scratch, see InputTextEx()
local HintBufCache = setmetatable({}, { __mode = "k" })
local function HintToBuf(hint)
local t = HintBufCache[hint]
@@ -5538,17 +5548,19 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
end
local id = window:GetID(label)
local label_end = ImGui.FindRenderedTextEnd(label)
local label_size = ImGui.CalcTextSize(label, label_end, false)
local frame_size = ImGui.CalcItemSize(size_arg, ImGui.CalcItemWidth(), (is_multiline and g.FontSize * 8.0 or label_size.y) + style.FramePadding.y * 2.0) -- Arbitrary default of 8 lines high for multi-line
local total_size_x, total_size_y = frame_size.x + ((label_size.x > 0.0) and (style.ItemInnerSpacing.x + label_size.x) or 0.0), frame_size.y -- [Luau] scalar total_size
local label_size_x, label_size_y = ImGui.CalcTextSizeXY(label, 1, label_end, false) -- [Luau] scalar label_size, frame_size, inner_size
local frame_size_x, frame_size_y = ImGui._CalcItemSizeXY(size_arg.x, size_arg.y, ImGui.CalcItemWidth(), (is_multiline and g.FontSize * 8.0 or label_size_y) + style.FramePadding.y * 2.0) -- Arbitrary default of 8 lines high for multi-line
local total_size_x, total_size_y = frame_size_x + ((label_size_x > 0.0) and (style.ItemInnerSpacing.x + label_size_x) or 0.0), frame_size_y -- [Luau] scalar total_size
-- [Luau] total_bb is a scratch rect (only ItemSize()/ItemAdd() read it); a single-line field's frame_bb too until ItemAdd() accepts it (clipped fields allocate nothing)
local cursor = window.DC.CursorPos
local frame_bb = ImRect(cursor.x, cursor.y, cursor.x + frame_size.x, cursor.y + frame_size.y) -- [Luau] scalar forms: no temporary ImVec2s
local total_bb = ImRect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + total_size_x, frame_bb.Min.y + total_size_y)
local frame_bb = is_multiline and ImRect() or InputTextEx_frame_bb
frame_bb.Min.x = cursor.x; frame_bb.Min.y = cursor.y; frame_bb.Max.x = cursor.x + frame_size_x; frame_bb.Max.y = cursor.y + frame_size_y
local total_bb = InputTextEx_total_bb
total_bb.Min.x = frame_bb.Min.x; total_bb.Min.y = frame_bb.Min.y; total_bb.Max.x = frame_bb.Min.x + total_size_x; total_bb.Max.y = frame_bb.Min.y + total_size_y
local draw_window = window
local inner_size = ImVec2()
ImVec2_Copy(inner_size, frame_size)
local inner_size_x, inner_size_y = frame_size_x, frame_size_y
local item_data_backup = is_multiline and ImGuiLastItemData() or nil -- [Luau] only used by the multi-line path
if is_multiline then
local backup_pos = ImVec2()
@@ -5590,7 +5602,7 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
draw_window = g.CurrentWindow -- Child window
draw_window.DC.NavLayersActiveMaskNext = bit32.bor(draw_window.DC.NavLayersActiveMaskNext, bit32.lshift(1, draw_window.DC.NavLayerCurrent)) -- This is to ensure that EndChild() will display a navigation highlight so we can "enter" into it.
ImVec2_Copy(draw_window.DC.CursorPos, draw_window.DC.CursorPos + style.FramePadding)
inner_size.x = inner_size.x - draw_window.ScrollbarSizes.x
inner_size_x = inner_size_x - draw_window.ScrollbarSizes.x
-- FIXME: Could this be a ImGuiChildFlags to affect the SetLastItemDataForWindow() call?
g.LastItemData.ID = id
@@ -5605,6 +5617,7 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
return false
end
end
frame_bb = ImRect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Max.x, frame_bb.Max.y) -- [Luau] own copy of the scratch from here on
end
-- Ensure mouse cursor is set even after switching to keyboard/gamepad mode. May generalize further? (#6417)
@@ -5704,7 +5717,7 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
-- Find initial scroll position for right alignment
ImVec2_Copy(state.Scroll, ImVec2(0.0, 0.0))
if bit32.band(flags, ImGuiInputTextFlags.ElideLeft) ~= 0 then
state.Scroll.x = state.Scroll.x + ImMax(0.0, ImGui.CalcTextSize(table.concat(buf)).x - frame_size.x + style.FramePadding.x * 2.0) -- [Port] FIXME: no table.concat here
state.Scroll.x = state.Scroll.x + ImMax(0.0, ImGui.CalcTextSize(table.concat(buf)).x - frame_size_x + style.FramePadding.x * 2.0) -- [Port] FIXME: no table.concat here
end
-- Recycle existing cursor/selection/undo stack but clamp position
@@ -5943,7 +5956,7 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
IM_ASSERT(state ~= nil)
--- @cast state ImGuiInputTextState
local row_count_per_page = ImMax(ImTrunc((inner_size.y - style.FramePadding.y) / g.FontSize), 1)
local row_count_per_page = ImMax(ImTrunc((inner_size_y - style.FramePadding.y) / g.FontSize), 1)
state.Stb.row_count_per_page = row_count_per_page
local k_mask = (io.KeyShift and STB_TEXTEDIT_K_SHIFT or 0)
@@ -6297,7 +6310,7 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
local draw_pos = ImVec2()
ImVec2_Copy(draw_pos, is_multiline and draw_window.DC.CursorPos or (frame_bb.Min + style.FramePadding))
local clip_rect = ImRect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + inner_size.x, frame_bb.Min.y + inner_size.y) -- Not using frame_bb.Max because we have adjusted size
local clip_rect = ImRect(frame_bb.Min.x, frame_bb.Min.y, frame_bb.Min.x + inner_size_x, frame_bb.Min.y + inner_size_y) -- Not using frame_bb.Max because we have adjusted size
if is_multiline then
clip_rect:ClipWith(draw_window.ClipRect)
end
@@ -6386,8 +6399,8 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
if render_cursor and state.CursorFollow then
-- Horizontal scroll in chunks of quarter width
if bit32.band(flags, ImGuiInputTextFlags.NoHorizontalScroll) == 0 then
local scroll_increment_x = inner_size.x * 0.25
local visible_width = inner_size.x - style.FramePadding.x
local scroll_increment_x = inner_size_x * 0.25
local visible_width = inner_size_x - style.FramePadding.x
if cursor_offset.x < state.Scroll.x then
state.Scroll.x = IM_TRUNC(ImMax(0.0, cursor_offset.x - scroll_increment_x))
elseif cursor_offset.x - visible_width >= state.Scroll.x then
@@ -6402,21 +6415,21 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
-- Test if cursor is vertically visible
if cursor_offset.y - g.FontSize < scroll_y then
new_scroll_y = ImMax(0.0, cursor_offset.y - g.FontSize)
elseif cursor_offset.y - (inner_size.y - style.FramePadding.y * 2.0) >= scroll_y then
new_scroll_y = cursor_offset.y - inner_size.y + style.FramePadding.y * 2.0
elseif cursor_offset.y - (inner_size_y - style.FramePadding.y * 2.0) >= scroll_y then
new_scroll_y = cursor_offset.y - inner_size_y + style.FramePadding.y * 2.0
end
end
state.CursorFollow = false
end
if state.CursorCenterY then
if is_multiline then
new_scroll_y = cursor_offset.y - g.FontSize - (inner_size.y * 0.5 - style.FramePadding.y)
new_scroll_y = cursor_offset.y - g.FontSize - (inner_size_y * 0.5 - style.FramePadding.y)
end
state.CursorCenterY = false
render_cursor = false
end
if new_scroll_y ~= scroll_y then
local scroll_max_y = ImMax((text_size_y + style.FramePadding.y * 2.0) - inner_size.y, 0.0)
local scroll_max_y = ImMax((text_size_y + style.FramePadding.y * 2.0) - inner_size_y, 0.0)
scroll_y = ImClamp(new_scroll_y, 0.0, scroll_max_y)
draw_pos.y = draw_pos.y + (draw_window.Scroll.y - scroll_y) -- Manipulate cursor pos immediately avoid a frame of lag
draw_window.Scroll.y = scroll_y
@@ -6547,7 +6560,7 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
ImGui.LogRenderedText(draw_pos, ImGui._ByteArrayToString(buf_display, 1, buf_display_end))
end
if label_size.x > 0.0 then
if label_size_x > 0.0 then
ImGui.RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label, 1, label_end, false)
end