Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e575a5f
Implement `SliderBehaviorT()` and `SliderBehavior()` stub
GrayWolf64 Jun 10, 2026
48d0a0b
Make stb_truetype use casting helpers already defined
GrayWolf64 Jun 10, 2026
2c1dc99
Finish `SliderBehavior()` impl
GrayWolf64 Jun 10, 2026
f9b421f
Implement `SliderScalar()`
GrayWolf64 Jun 10, 2026
18f033a
Implement `SliderFloat()` and fix some bugs to get it working...
GrayWolf64 Jun 10, 2026
f6a7a67
Add `ImAtof()` stub and use it
GrayWolf64 Jun 11, 2026
df304d6
Add buggy `SliderInt()`
GrayWolf64 Jun 11, 2026
932e89e
Seem to have fixed `SliderInt()` by patching `ScaleValueFromRatioT()`
GrayWolf64 Jun 11, 2026
8bf3371
Improve the patch in `ScaleValueFromRatioT()`
GrayWolf64 Jun 11, 2026
4536793
Add `DragInt()` demo and update its decl. Also fix
GrayWolf64 Jun 11, 2026
1b3be90
Add `DragInt()` WrapAround demo call. It's bugged now
GrayWolf64 Jun 12, 2026
23b109d
Remove broken `ImS64` and `ImU64` types,
GrayWolf64 Jun 12, 2026
be943cf
Update previous DataTypeFormat func. Amend comment
GrayWolf64 Jun 12, 2026
092f0cf
Attempt to fix `DragInt` wrapping bug.
GrayWolf64 Jun 13, 2026
491a5e2
Update `DragBehaviorT()` annotations
GrayWolf64 Jun 13, 2026
6664bff
Update `DragFloat()` def, add related demo code
GrayWolf64 Jun 13, 2026
f65c20c
Attempt to fix `ScaleValueFromRatioT()` bug that caused `SliderInt()`…
GrayWolf64 Jun 13, 2026
471c65e
Partial sync with ocornut/imgui@e5ff2d07d732e6145f5183d5e8116e13c386a…
GrayWolf64 Jun 16, 2026
9e6a664
Sync with ocornut/imgui@1ba29f2beccf56b7231ddbeb97dfb2c33b17248a
GrayWolf64 Jun 17, 2026
3330f0a
Add `SliderAngle()`
GrayWolf64 Jun 17, 2026
d97484c
Add currently untested `SliderScalarN()` and `SliderFloat2|3|4()`
GrayWolf64 Jun 19, 2026
58f3758
Mark current `ImStd.sscanf()` impl as *deprecated*
GrayWolf64 Jun 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lua/imgui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ local IMGUI_VIEWPORT_DEFAULT_ID = 0x11111111
local string = string
ImFormatString = string.format -- TODO: an simplified version that operates on byte tables directly?

--- @deprecated
--- @module "imstd_minstdio"
ImStd.sscanf = IM_INCLUDE"imstd_minstdio.lua"

Expand Down Expand Up @@ -863,7 +864,9 @@ local GLocalizationEntriesEnUS = {
ImGuiLocEntry(ImGuiLocKey.TableSizeOne, "Size column to fit###SizeOne"),
ImGuiLocEntry(ImGuiLocKey.TableSizeAllFit, "Size all columns to fit###SizeAll"),
ImGuiLocEntry(ImGuiLocKey.TableSizeAllDefault, "Size all columns to default###SizeAll"),
ImGuiLocEntry(ImGuiLocKey.TableReset, "Reset"),
ImGuiLocEntry(ImGuiLocKey.TableResetOrder, "Reset order###ResetOrder"),
ImGuiLocEntry(ImGuiLocKey.TableResetVisibility, "Reset visibility###ResetVisibility"),
ImGuiLocEntry(ImGuiLocKey.WindowingMainMenuBar, "(Main menu bar)"),
ImGuiLocEntry(ImGuiLocKey.WindowingPopup, "(Popup)"),
ImGuiLocEntry(ImGuiLocKey.WindowingUntitled, "(Untitled)"),
Expand Down Expand Up @@ -5511,7 +5514,7 @@ function ImGui.Begin(name, open, flags)
-- Default item width. Make it proportional to window size if window can be manually resized.
-- (we cannot use AutoFitFramesX/AutoFitFramesY which is a temporary state)
local is_resizable_width
if bit.band(flags, ImGuiWindowFlags.ChildWindow) ~= 0 then
if bit.band(flags, ImGuiWindowFlags.ChildWindow) ~= 0 and not window.DockIsActive then
is_resizable_width = (window.Size.x > 0.0) and (bit.band(window.ChildFlags, bit.bor(ImGuiChildFlags.AutoResizeX, ImGuiChildFlags.AlwaysAutoResize)) == 0)
else
is_resizable_width = (window.Size.x > 0.0) and (bit.band(flags, ImGuiWindowFlags.AlwaysAutoResize) == 0)
Expand Down
44 changes: 42 additions & 2 deletions lua/imgui_demo.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
--- ImGui Sincerely WIP
-- (Demo Code)

-- FIXME: this is problematic
local static = {}

local IM_MIN = math.min
local IM_MAX = math.max
local function IM_CLAMP(V, MN, MX) return (V < MN) and MN or (V > MX) and MX or V end
Expand Down Expand Up @@ -171,7 +174,21 @@ str1[1] = 0
local hint0 = {string.byte("enter text here", 1, 15)}
table.insert(hint0, 0)

local i0 = 233
static.i0 = 233
static.i1 = 50
static.i2 = 42
static.i3 = 128

static.f1 = 1.00
static.f2 = 0.0067

local f1 = 0.123
local f2 = 0.0
local angle = 0.0

local Element = { Fire = 1, Earth = 2, Air = 3, Water = 4, COUNT = 5 }
local elems_names = { "Fire", "Earth", "Air", "Water" }
local elem = Element.Fire

function DemoWindowWidgetsBasic()
if ImGui.TreeNode("Basic") then
Expand Down Expand Up @@ -243,10 +260,33 @@ function DemoWindowWidgetsBasic()

ImGui.InputTextWithHint("input text (w/ hint)", hint0, str1, 128)

i0 = ImGui.InputInt("input int", i0)
static.i0 = ImGui.InputInt("input int", static.i0)
-- TODO:
end

ImGui.SeparatorText("Drags")

do
static.i1 = ImGui.DragInt("drag int", static.i1, 1)
static.i2 = ImGui.DragInt("drag int 0..100", static.i2, 1, 0, 100, "%d%%", ImGuiSliderFlags.AlwaysClamp)
static.i3 = ImGui.DragInt("drag int wrap 100..200", static.i3, 1, 100, 200, "%d", ImGuiSliderFlags.WrapAround)

static.f1 = ImGui.DragFloat("drag float", static.f1, 0.005)
static.f2 = ImGui.DragFloat("drag small float", static.f2, 0.0001, 0.0, 0.0, "%.06f ns")
end

ImGui.SeparatorText("Sliders")

do
f1 = ImGui.SliderFloat("slider float", f1, 0.0, 1.0, "ratio = %.3f")
f2 = ImGui.SliderFloat("slider float (log)", f2, -10.0, 10.0, "%.4f", ImGuiSliderFlags.Logarithmic)

angle = ImGui.SliderAngle("slider angle", angle)

local elem_name = (elem >= 1 and elem < Element.COUNT) and elems_names[elem] or "Unknown"
elem = ImGui.SliderInt("slider enum", elem, 1, Element.COUNT - 1, elem_name)
end

ImGui.TreePop()
end
end
Expand Down
60 changes: 37 additions & 23 deletions lua/imgui_h.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

--- @meta

-- [LuaBitOp](https://bitop.luajit.org/semantics.html)
local _band = bit.band

--- @class char : integer
Expand All @@ -14,16 +15,30 @@ local _band = bit.band
--- @class ImU16 : integer
--- @class ImS16 : integer

function ImU8(val) return _band(val, 0xFF) end --- @type fun(val: number): ImU8
function ImS8(val) return _band(val, 0xFF) - (_band(val, 0x80) ~= 0 and 0x100 or 0) end --- @type fun(val: number): ImS8
--- @class ImU32 : integer
--- @class ImS32 : integer

--- @param val number
--- @return ImU8
function ImU8(val) return _band(val, 0xFF) end
--- @param val number
--- @return ImS8
function ImS8(val) return _band(val, 0xFF) - (_band(val, 0x80) ~= 0 and 0x100 or 0) end

--- @param val number
--- @return ImU16
function ImU16(val) return _band(val, 0xFFFF) end
--- @param val number
--- @return ImS16
function ImS16(val) return _band(val, 0xFFFF) - (_band(val, 0x8000) ~= 0 and 0x10000 or 0) end

--- @param val number
--- @return ImU32
function ImU32(val) return _band(val, 0xFFFFFFFF) end
--- @param val number
--- @return ImS32
function ImS32(val) return _band(val, 0xFFFFFFFF) end

function ImU16(val) return _band(val, 0xFFFF) end --- @type fun(val: number): ImU16
function ImS16(val) return _band(val, 0xFFFF) - (_band(val, 0x8000) ~= 0 and 0x10000 or 0) end --- @type fun(val: number): ImS16

--- @alias ImU32 integer
--- @alias ImU64 integer

--- @alias ImS64 integer
--- @alias float number

--- @alias int integer
Expand All @@ -41,7 +56,7 @@ function ImS16(val) return _band(val, 0xFFFF) - (_band(val, 0x8000) ~= 0 and 0x1

--- @alias ImGuiID unsigned_int

--- @alias ImTextureID ImU64
--- @alias ImTextureID integer

--- @alias ImGuiKeyChord int

Expand Down Expand Up @@ -1740,21 +1755,20 @@ ImGuiDragDropFlags = {

ImGuiDragDropFlags.AcceptPeekOnly = bit.bor(ImGuiDragDropFlags.AcceptBeforeDelivery, ImGuiDragDropFlags.AcceptNoDrawDefaultRect)

--- Note that `U64` isn't supported
--- Note that `S64` and `U64` are not supported
--- @enum ImGuiDataType
ImGuiDataType = {
S8 = 1, -- signed char / char
U8 = 2, -- unsigned char
S16 = 3, -- short
U16 = 4, -- unsigned short
S32 = 5, -- int
U32 = 6, -- unsigned int
S64 = 7, -- long long / __int64
Float = 8, -- float
Double = 9, -- double
Bool = 10, -- bool (provided for user convenience, not supported by scalar widgets)
String = 11, -- string (provided for user convenience, not supported by scalar widgets)
COUNT = 11
S8 = 0, -- signed char / char
U8 = 1, -- unsigned char
S16 = 2, -- short
U16 = 3, -- unsigned short
S32 = 4, -- int
U32 = 5, -- unsigned int
Float = 6, -- float
Double = 7, -- double
Bool = 8, -- bool (provided for user convenience, not supported by scalar widgets)
String = 9, -- string (provided for user convenience, not supported by scalar widgets)
COUNT = 10
}

IM_COL32_R_SHIFT = 0
Expand Down
32 changes: 20 additions & 12 deletions lua/imgui_internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ DBL_MAX = 1.7976931348623e+308
INT_MIN = -0x7fffffff - 1
INT_MAX = 0x7fffffff
UINT_MAX = 0x7fffffff * 2 + 1
LLONG_MIN = -9223372036854775807 - 1
LLONG_MAX = 9223372036854775807

IM_PI = math.pi
ImPow = math.pow
Expand Down Expand Up @@ -187,6 +185,12 @@ function ImStd.ImExponentialMovingAverage(avg, sample, n)
return avg
end

-- Uses `string.match` internally
--- @param str string
function ImAtof(str)
return tonumber(string.match(str, "[+-]?%d*%.?%d+"))
end

--- @param s table # 1-based
--- @param c any
--- @param n int
Expand Down Expand Up @@ -2675,6 +2679,7 @@ ImGuiDebugLogFlags = {
EventInputRouting = bit.lshift(1, 9),
EventDocking = bit.lshift(1, 10),
EventViewport = bit.lshift(1, 11),
EventTable = bit.lshift(1, 12),

OutputToTTY = bit.lshift(1, 20), -- Also send output to TTY
OutputToDebugger = bit.lshift(1, 21), -- Also send output to Debugger Console
Expand All @@ -2689,6 +2694,7 @@ ImGuiDebugLogFlags.EventMask_ = bit.bor(
ImGuiDebugLogFlags.EventNav,
ImGuiDebugLogFlags.EventClipper,
ImGuiDebugLogFlags.EventSelection,
ImGuiDebugLogFlags.EventTable,
ImGuiDebugLogFlags.EventIO,
ImGuiDebugLogFlags.EventFont,
ImGuiDebugLogFlags.EventInputRouting,
Expand All @@ -2702,16 +2708,18 @@ ImGuiLocKey = {
TableSizeOne = 2,
TableSizeAllFit = 3,
TableSizeAllDefault = 4,
TableResetOrder = 5,
WindowingMainMenuBar = 6,
WindowingPopup = 7,
WindowingUntitled = 8,
OpenLink_s = 9,
CopyLink = 10,
DockingHideTabBar = 11,
DockingHoldShiftToDock = 12,
DockingDragToUndockOrMoveNode = 13,
COUNT = 13
TableReset = 5,
TableResetOrder = 6,
TableResetVisibility = 7,
WindowingMainMenuBar = 8,
WindowingPopup = 9,
WindowingUntitled = 10,
OpenLink_s = 11,
CopyLink = 12,
DockingHideTabBar = 13,
DockingHoldShiftToDock = 14,
DockingDragToUndockOrMoveNode = 15,
COUNT = 15
}

--- @class ImGuiLocEntry
Expand Down
Loading