ImGui
BeamNG ImGui Data Types
ImGui uses C-style pointers for mutable values. BeamNG wraps these as Lua tables with a `[0]` index.
Pointer Types
ImGui uses C-style pointers for mutable values. BeamNG wraps these as Lua tables with a [0] index.
BoolPtr
local checked = im.BoolPtr(false)
if im.Checkbox("Enable", checked) then
print("Now: " .. tostring(checked[0]))
end
-- Read: checked[0] → true/false
-- Write: checked[0] = trueIntPtr
local count = im.IntPtr(5)
if im.InputInt("Count", count) then
print("Value: " .. count[0])
end
if im.SliderInt("Slider", count, 0, 100) then end
if im.DragInt("Drag", count) then endFloatPtr
local speed = im.FloatPtr(1.0)
if im.InputFloat("Speed", speed, 0.1, 1.0, "%.2f") then end
if im.SliderFloat("Slider", speed, 0, 10, "%.1f") then end
if im.DragFloat("Drag", speed, 0.01, 0, 100) then endDoublePtr
local precise = im.DoublePtr(3.14159)
if im.InputDouble("Value", precise, 0.01, 0.1, "%.5f") then endArrayChar (String Buffer)
local ffi = require("ffi")
local buf = im.ArrayChar(256, "default text")
-- InputText: returns true when modified
if im.InputText("Name", buf, 256) then
local text = ffi.string(buf)
print("Typed: " .. text)
end
-- InputTextMultiline
local bigBuf = im.ArrayChar(4096, "line1\nline2")
if im.InputTextMultiline("##editor", bigBuf, 4096, im.ImVec2(400, 200)) then end
-- InputText with flags
if im.InputText("Search", buf, 256, im.InputTextFlags_EnterReturnsTrue) then
-- Only fires on Enter key
endArrayFloat / ArrayInt
local floats = im.ArrayFloat(4) -- [0]=0, [1]=0, [2]=0, [3]=0
local ints = im.ArrayInt(3)Vector Types
ImVec2
local size = im.ImVec2(200, 100)
local pos = im.ImVec2(0, 0)
-- Access fields
print(size.x, size.y)
-- Common uses
im.SetNextWindowSize(im.ImVec2(400, 300))
im.SetNextWindowPos(im.ImVec2(100, 100))
im.Button("OK", im.ImVec2(120, 0)) -- 0 = auto height
im.Dummy(im.ImVec2(0, 20)) -- spacerImVec4
local color = im.ImVec4(1, 0, 0, 1) -- RGBA, 0-1 range
im.TextColored(color, "Red text")
im.PushStyleColor2(im.Col_Text, im.ImVec4(0.5, 1, 0.5, 1))
-- ... green text widgets ...
im.PopStyleColor()Color Types
ImVec4 Colors (float RGBA)
-- Most ImGui color functions use ImVec4 (0.0-1.0 range)
im.PushStyleColor2(im.Col_WindowBg, im.ImVec4(0.1, 0.1, 0.1, 0.95))
im.TextColored(im.ImVec4(1, 0.8, 0, 1), "Warning!")ImColor (helper)
local color = im.ImColor(255, 128, 0, 255) -- integer RGBA
-- Or use the RGB helper:
local c = im.ImColorByRGB(255, 128, 0, 255) -- returns ImColor with .Value as ImVec4ColorF (BeamNG engine type)
-- Used outside ImGui (scene objects, markers, etc.)
local color = ColorF(1, 0, 0, 0.5)
-- Convert to ImGui linear:
local linear = color:asLinear4F()GetColorU32 (for draw lists)
local drawList = im.GetWindowDrawList()
local colorU32 = im.GetColorU322(im.ImVec4(1, 0, 0, 1))
im.ImDrawList_AddRectFilled(drawList, im.ImVec2(10, 10), im.ImVec2(100, 50), colorU32)Type Conversion Summary
| Need | Create With | Read With | Write With |
|---|---|---|---|
| Bool | im.BoolPtr(false) | ptr[0] | ptr[0] = true |
| Int | im.IntPtr(0) | ptr[0] | ptr[0] = 5 |
| Float | im.FloatPtr(0) | ptr[0] | ptr[0] = 1.5 |
| String | im.ArrayChar(256, "") | ffi.string(buf) | Recreate buffer |
| Vec2 | im.ImVec2(x, y) | .x, .y | Create new |
| Vec4 | im.ImVec4(x, y, z, w) | .x, .y, .z, .w | Create new |