Library: @native on small, frequently called helpers (style color stack, tree push/pop, indent, item size, draw list clip/cmd, glyph lookup, table column helpers)
Picked from a per-function call census of the whole demo opened (hundreds of calls/frame each); +~100 KB of native code. Whole demo open (headless --roblox) 10.35 -> 9.84 ms/frame together with the previous commits; draw data unchanged.
This commit is contained in:
1 parent
b05d2535c0
commit
90363f4a6e
5 files changed
+31
No files matched your search
@@ -6783,6 +6783,7 @@ function ImGui.SameLine(offset_from_start_x, spacing_w)
|
||||
end
|
||||
|
||||
--- @param indent_w? float
|
||||
@native
|
||||
function ImGui.Indent(indent_w)
|
||||
if indent_w == nil then indent_w = 0.0 end
|
||||
|
||||
@@ -6799,6 +6800,7 @@ function ImGui.Indent(indent_w)
|
||||
end
|
||||
|
||||
--- @param indent_w? float
|
||||
@native
|
||||
function ImGui.Unindent(indent_w)
|
||||
if indent_w == nil then indent_w = 0.0 end
|
||||
|
||||
@@ -6835,6 +6837,7 @@ function ImGui.PushItemWidth(item_width)
|
||||
g.NextItemData.HasFlags = bit32.band(g.NextItemData.HasFlags, bit32.bnot(ImGuiNextItemDataFlags.HasWidth))
|
||||
end
|
||||
|
||||
@native
|
||||
function ImGui.PopItemWidth()
|
||||
local g = GImGui
|
||||
local window = g.CurrentWindow
|
||||
@@ -7133,12 +7136,14 @@ end
|
||||
--- @param default_w float
|
||||
--- @param default_h float
|
||||
--- @return ImVec2
|
||||
@native
|
||||
function ImGui.CalcItemSize(size, default_w, default_h)
|
||||
return ImVec2(ImGui._CalcItemSizeXY(size.x, size.y, default_w, default_h)) -- [Luau] 'size' is by value upstream: never written to
|
||||
end
|
||||
|
||||
-- [Luau] scalar CalcItemSize(): callers that build 'size' themselves skip both ImVec2 allocations
|
||||
--- @return float, float
|
||||
@native
|
||||
function ImGui._CalcItemSizeXY(size_x, size_y, default_w, default_h)
|
||||
local avail_x, avail_y
|
||||
if size_x < 0.0 or size_y < 0.0 then
|
||||
@@ -7716,6 +7721,7 @@ end
|
||||
|
||||
-- Push a given id value ignoring the ID stack as a seed.
|
||||
--- @param id ImGuiID
|
||||
@native
|
||||
function ImGui.PushOverrideID(id)
|
||||
local g = GImGui
|
||||
local window = g.CurrentWindow
|
||||
@@ -8684,6 +8690,7 @@ end
|
||||
--- @param ctx? ImGuiContext
|
||||
--- @param key ImGuiKey
|
||||
--- @return ImGuiKeyData, int
|
||||
@native
|
||||
function ImGui.GetKeyData(ctx, key)
|
||||
if ctx == nil then ctx = GImGui end
|
||||
|
||||
@@ -8751,6 +8758,7 @@ end
|
||||
-- Consider transitioning from 'IsKeyDown(MY_ENGINE_KEY_A)' (<1.87) to IsKeyDown(ImGuiKey.A) (>= 1.87)
|
||||
--- @param key ImGuiKey
|
||||
--- @param owner_id? ImGuiID
|
||||
@native
|
||||
function ImGui.IsKeyDown(key, owner_id)
|
||||
if owner_id == nil then owner_id = ImGuiKeyOwner_Any end
|
||||
|
||||
@@ -13993,6 +14001,7 @@ function ImGui.GetScale()
|
||||
end
|
||||
|
||||
--- @return ImGuiWindow
|
||||
@native
|
||||
function ImGui.GetCurrentWindowRead()
|
||||
local g = GImGui
|
||||
return g.CurrentWindow
|
||||
@@ -15105,6 +15114,7 @@ end
|
||||
-- FIXME: This may incur a round-trip (if the end user got their data from a float4) but eventually we aim to store the in-flight colors as ImU32
|
||||
--- @param idx ImGuiCol
|
||||
--- @param col ImU32|ImVec4
|
||||
@native
|
||||
function ImGui.PushStyleColor(idx, col)
|
||||
local g = GImGui
|
||||
local backup = ImGuiColorMod(idx, g.Style.Colors[idx])
|
||||
@@ -15122,6 +15132,7 @@ function ImGui.PushStyleColor(idx, col)
|
||||
end
|
||||
|
||||
--- @param count? int
|
||||
@native
|
||||
function ImGui.PopStyleColor(count)
|
||||
if count == nil then count = 1 end
|
||||
|
||||
|
||||
@@ -2834,6 +2834,7 @@ end
|
||||
-- Find glyph, load if necessary, return fallback if missing
|
||||
--- @param c ImWchar
|
||||
--- @return ImFontGlyph?
|
||||
@native
|
||||
function MT.ImFontBaked:FindGlyph(c)
|
||||
if c < self.IndexLookup.Size then
|
||||
local i = self.IndexLookup.Data[c + 1]
|
||||
@@ -4377,6 +4378,7 @@ function MT.ImDrawList:CloneOutput()
|
||||
return dst
|
||||
end
|
||||
|
||||
@native
|
||||
function MT.ImDrawList:AddDrawCmd()
|
||||
local draw_cmd = ImDrawCmd()
|
||||
|
||||
@@ -4507,6 +4509,7 @@ end
|
||||
|
||||
-- Our scheme may appears a bit unusual, basically we want the most-common calls AddLine AddRect etc. to not have to perform any check so we always have a command ready in the stack.
|
||||
-- The cost of figuring out if a new command has to be added or if we can merge is paid in those Update** functions only.
|
||||
@native
|
||||
function MT.ImDrawList:_OnChangedClipRect()
|
||||
-- If current command is used with different settings we need to add a new command
|
||||
IM_ASSERT_PARANOID(self.CmdBuffer.Size > 0)
|
||||
@@ -4866,6 +4869,7 @@ end
|
||||
MT.ImDrawList.PrimReserve = PrimReserve
|
||||
|
||||
-- Release the number of reserved vertices/indices from the end of the last reservation made with PrimReserve().
|
||||
@native
|
||||
function MT.ImDrawList:PrimUnreserve(idx_count, vtx_count)
|
||||
IM_ASSERT_PARANOID(idx_count >= 0 and vtx_count >= 0)
|
||||
|
||||
@@ -4922,6 +4926,7 @@ end
|
||||
--- @param uv_a ImVec2
|
||||
--- @param uv_c ImVec2
|
||||
--- @param col any
|
||||
@native
|
||||
function MT.ImDrawList:PrimRectUV(a, c, uv_a, uv_c, col)
|
||||
local idx = self._VtxCurrentIdx
|
||||
local idx_data = self.IdxBuffer.Data; local vtx_data = self.VtxBuffer.Buf
|
||||
@@ -7034,6 +7039,7 @@ function MT.ImDrawList:_CalcCircleAutoSegmentCount(radius)
|
||||
end
|
||||
|
||||
-- Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui.PushClipRect() to affect logic (hit-testing and widget culling)
|
||||
@native
|
||||
function MT.ImDrawList:PushClipRect(cr_min, cr_max, intersect_with_current_clip_rect)
|
||||
-- [Luau] reuse the stack slot's ImVec4 left from earlier frames (each slot stays uniquely owned by the stack)
|
||||
local stack = self._ClipRectStack
|
||||
@@ -7068,6 +7074,7 @@ function MT.ImDrawList:PushClipRectFullScreen()
|
||||
self:PushClipRect(ImVec2(cr.x, cr.y), ImVec2(cr.z, cr.w))
|
||||
end
|
||||
|
||||
@native
|
||||
function MT.ImDrawList:PopClipRect()
|
||||
local stack = self._ClipRectStack
|
||||
IM_ASSERT(stack.Size > 0)
|
||||
|
||||
@@ -577,6 +577,7 @@ ImGuiKeyOwner_NoOwner = 4294967295 -- Require key to have no owner.
|
||||
function ImGui.MouseButtonToKey(button) IM_ASSERT(button >= 0 and button < ImGuiMouseButton.COUNT) return ImGuiKey.MouseLeft + button end
|
||||
|
||||
--- @param key ImGuiKey
|
||||
@native
|
||||
function ImGui.IsNamedKey(key)
|
||||
return key >= ImGuiKey.NamedKey_BEGIN and key < ImGuiKey.NamedKey_END
|
||||
end
|
||||
@@ -1449,6 +1450,7 @@ MT.ImGuiNextItemData = {}
|
||||
MT.ImGuiNextItemData.__index = MT.ImGuiNextItemData
|
||||
|
||||
-- Also cleared manually by ItemAdd()!
|
||||
@native
|
||||
function MT.ImGuiNextItemData:ClearFlags()
|
||||
self.HasFlags = ImGuiNextItemDataFlags.None
|
||||
self.ItemFlagsSet = ImGuiItemFlags.None
|
||||
@@ -1498,6 +1500,7 @@ end
|
||||
MT.ImGuiNextWindowData = {}
|
||||
MT.ImGuiNextWindowData.__index = MT.ImGuiNextWindowData
|
||||
|
||||
@native
|
||||
function MT.ImGuiNextWindowData:ClearFlags()
|
||||
self.HasFlags = ImGuiNextWindowDataFlags.None
|
||||
end
|
||||
|
||||
@@ -429,6 +429,7 @@ end
|
||||
|
||||
--- @param table_ ImGuiTable
|
||||
--- @param instance_no int
|
||||
@native
|
||||
function ImGui.TableGetInstanceData(table_, instance_no)
|
||||
if instance_no == 0 then
|
||||
return table_.InstanceDataFirst
|
||||
@@ -2512,6 +2513,7 @@ function ImGui.TableGetColumnIndex()
|
||||
end
|
||||
|
||||
-- [Public] Append into a specific column
|
||||
@native
|
||||
function ImGui.TableSetColumnIndex(column_n)
|
||||
local g = GImGui
|
||||
local table_ = g.CurrentTable
|
||||
@@ -2686,6 +2688,7 @@ end
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
-- Maximum column content width given current layout. Use column.MinX so this value differs on a per-column basis.
|
||||
@native
|
||||
function ImGui.TableCalcMaxColumnWidth(table_, column_n)
|
||||
local column = table_.Columns[column_n]
|
||||
local max_width = FLT_MAX
|
||||
@@ -2713,6 +2716,7 @@ function ImGui.TableCalcMaxColumnWidth(table_, column_n)
|
||||
end
|
||||
|
||||
-- Note this is meant to be stored in column.WidthAuto, please generally use the WidthAuto field
|
||||
@native
|
||||
function ImGui.TableGetColumnWidthAuto(table_, column)
|
||||
local content_width_body = mathMax(column.ContentMaxXFrozen, column.ContentMaxXUnfrozen) - column.WorkMinX
|
||||
local content_width_headers = column.ContentMaxXHeadersIdeal - column.WorkMinX
|
||||
|
||||
@@ -254,6 +254,7 @@ end
|
||||
|
||||
--- @param fmt string
|
||||
--- @param ... any
|
||||
@native
|
||||
function ImGui.TextDisabled(fmt, ...)
|
||||
local g = GImGui
|
||||
ImGui.PushStyleColor(ImGuiCol.Text, g.Style.Colors[ImGuiCol.TextDisabled])
|
||||
@@ -7776,6 +7777,7 @@ end
|
||||
|
||||
--- @param storage_id ImGuiID
|
||||
--- @param is_open bool
|
||||
@native
|
||||
function ImGui.TreeNodeSetOpen(storage_id, is_open)
|
||||
local g = GImGui
|
||||
local storage = g.CurrentWindow.DC.StateStorage
|
||||
@@ -7784,6 +7786,7 @@ end
|
||||
|
||||
--- @param storage_id ImGuiID
|
||||
--- @param flags ImGuiTreeNodeFlags
|
||||
@native
|
||||
function ImGui.TreeNodeUpdateNextOpen(storage_id, flags)
|
||||
-- Leaf node always open a new tree/id scope. If you never use it, add ImGuiTreeNodeFlags.NoTreePushOnOpen.
|
||||
if bit32.band(flags, ImGuiTreeNodeFlags.Leaf) ~= 0 then
|
||||
@@ -8239,6 +8242,7 @@ function ImGui.TreePush(str_id)
|
||||
end
|
||||
|
||||
--- @param id ImGuiID
|
||||
@native
|
||||
function ImGui.TreePushOverrideID(id)
|
||||
local g = GImGui
|
||||
local window = g.CurrentWindow
|
||||
@@ -8247,6 +8251,7 @@ function ImGui.TreePushOverrideID(id)
|
||||
ImGui.PushOverrideID(id)
|
||||
end
|
||||
|
||||
@native
|
||||
function ImGui.TreePop()
|
||||
local g = GImGui
|
||||
local window = g.CurrentWindow
|
||||
@@ -8283,6 +8288,7 @@ end
|
||||
-- Set next TreeNode/CollapsingHeader open state.
|
||||
--- @param is_open bool
|
||||
--- @param cond? ImGuiCond
|
||||
@native
|
||||
function ImGui.SetNextItemOpen(is_open, cond)
|
||||
if cond == nil then cond = 0 end
|
||||
|
||||
|
||||
Reference in new issue
Block a user