0.4.1
Build & Release / build (push) Canceled after 0s

- TextProxy works for any widget that sets PlatformImeData.WantTextInput (+ SelectedText)
- TextProxy: key-code fallback waits for the TextBox (fixes doubled typing); no stuck Ctrl after paste
- Raster: reversed rects (min > max) draw like upstream (fixes ImNodes/ImPlot box select)
- test harness: --module NAME=path loads extra ModuleScripts
- new tests: t_textproxy_custom, t_rect_flip
- extensions/: submodules for imguicolortextedit-luau, imguizmo-luau, implot-luau, implot3d-luau, imnodes-luau
This commit is contained in:
4DBug committed 2026-10-17 07:31:40 -05:00
1 parent c5a0b20132
commit e2d1cf5cf9
24 files changed
+291 -46

No files matched your search

+13 -1
View File
@@ -116,7 +116,7 @@ The Style Editor (`ImGui.ShowStyleEditor()`) and the Metrics/Debugger (`ImGui.Sh
### Getting Started & Integration (Roblox)
With [Wally](https://wally.run) ([4dbug/imgui-luau](https://wally.run/package/4dbug/imgui-luau)): add `ImGui = "4dbug/[email protected].0"` under `[dependencies]` in your `wally.toml`, run `wally install`, then `require(ReplicatedStorage.Packages.ImGui)`. Or from source:
With [Wally](https://wally.run) ([4dbug/imgui-luau](https://wally.run/package/4dbug/imgui-luau)): add `ImGui = "4dbug/[email protected].1"` under `[dependencies]` in your `wally.toml`, run `wally install`, then `require(ReplicatedStorage.Packages.ImGui)`. Or from source:
1. Build the module: `python3 tools/bundle.py` writes `build/ImGui.luau` (`--no-demo` leaves the demo out) and `build/ImGuiTyped.luau`, a small typed entry module (Luau types for the public `ImGui.*` API, `ImVec2`/`ImVec4` and the flag enums) that requires `build/ImGui.luau` as its child `Impl`. The Wally package and the Rojo projects use that layout, so you get autocomplete and type errors in `--!strict` scripts. The single-file `ImGui.luau` also works on its own, just untyped.
2. Sync with [Rojo](https://rojo.space): [`default.project.json`](/default.project.json) puts the module in `ReplicatedStorage.ImGui` and the example LocalScript in `StarterPlayerScripts`.
@@ -312,6 +312,18 @@ python3 tools/test/run.py --main tools/test/scripts/t_tables.luau --frames 120 -
See [docs/PORTING.md](/docs/PORTING.md) for the porting rules.
### Extensions (work in progress)
Separate repos, included as submodules under `extensions/` (clone with `--recursive`):
- [imguicolortextedit-luau](https://git.bug.tools/bug/imguicolortextedit-luau): [ImGuiColorTextEdit](https://github.com/goossens/ImGuiColorTextEdit) (goossens fork), a syntax-highlighting text editor.
- [imguizmo-luau](https://git.bug.tools/bug/imguizmo-luau): [ImGuizmo](https://github.com/CedricGuillemet/ImGuizmo), 3D gizmos with Roblox Camera/CFrame helpers.
- [implot-luau](https://git.bug.tools/bug/implot-luau): [ImPlot](https://github.com/epezent/implot), 2D plotting.
- [implot3d-luau](https://git.bug.tools/bug/implot3d-luau): [ImPlot3D](https://github.com/brenocq/implot3d), 3D plotting.
- [imnodes-luau](https://git.bug.tools/bug/imnodes-luau): [imnodes](https://github.com/Nelarius/imnodes), a node editor.
Usage: `local ImPlot = require(ImPlotModule)(require(ImGuiModule))`.
### Not ported yet
Multi-select / box-select, typing-select, the Assets Browser example, the Item Picker and a few smaller items. The full list is in [docs/TODO.txt](/docs/TODO.txt).
+15
View File
@@ -0,0 +1,15 @@
[submodule "extensions/imguicolortextedit-luau"]
path = extensions/imguicolortextedit-luau
url = https://git.bug.tools/bug/imguicolortextedit-luau.git
[submodule "extensions/imguizmo-luau"]
path = extensions/imguizmo-luau
url = https://git.bug.tools/bug/imguizmo-luau.git
[submodule "extensions/implot-luau"]
path = extensions/implot-luau
url = https://git.bug.tools/bug/implot-luau.git
[submodule "extensions/imnodes-luau"]
path = extensions/imnodes-luau
url = https://git.bug.tools/bug/imnodes-luau.git
[submodule "extensions/implot3d-luau"]
path = extensions/implot3d-luau
url = https://git.bug.tools/bug/implot3d-luau.git
+13 -1
View File
@@ -113,7 +113,7 @@ The Style Editor (`ImGui.ShowStyleEditor()`) and the Metrics/Debugger (`ImGui.Sh
### Getting Started & Integration (Roblox)
With [Wally](https://wally.run) ([4dbug/imgui-luau](https://wally.run/package/4dbug/imgui-luau)): add `ImGui = "4dbug/[email protected].0"` under `[dependencies]` in your `wally.toml`, run `wally install`, then `require(ReplicatedStorage.Packages.ImGui)`. Or from source:
With [Wally](https://wally.run) ([4dbug/imgui-luau](https://wally.run/package/4dbug/imgui-luau)): add `ImGui = "4dbug/[email protected].1"` under `[dependencies]` in your `wally.toml`, run `wally install`, then `require(ReplicatedStorage.Packages.ImGui)`. Or from source:
1. Build the module: `python3 tools/bundle.py` writes `build/ImGui.luau` (`--no-demo` leaves the demo out) and `build/ImGuiTyped.luau`, a small typed entry module (Luau types for the public `ImGui.*` API, `ImVec2`/`ImVec4` and the flag enums) that requires `build/ImGui.luau` as its child `Impl`. The Wally package and the Rojo projects use that layout, so you get autocomplete and type errors in `--!strict` scripts. The single-file `ImGui.luau` also works on its own, just untyped.
2. Sync with [Rojo](https://rojo.space): [`default.project.json`](default.project.json) puts the module in `ReplicatedStorage.ImGui` and the example LocalScript in `StarterPlayerScripts`.
@@ -309,6 +309,18 @@ python3 tools/test/run.py --main tools/test/scripts/t_tables.luau --frames 120 -
See [docs/PORTING.md](docs/PORTING.md) for the porting rules.
### Extensions (work in progress)
Separate repos, included as submodules under `extensions/` (clone with `--recursive`):
- [imguicolortextedit-luau](https://git.bug.tools/bug/imguicolortextedit-luau): [ImGuiColorTextEdit](https://github.com/goossens/ImGuiColorTextEdit) (goossens fork), a syntax-highlighting text editor.
- [imguizmo-luau](https://git.bug.tools/bug/imguizmo-luau): [ImGuizmo](https://github.com/CedricGuillemet/ImGuizmo), 3D gizmos with Roblox Camera/CFrame helpers.
- [implot-luau](https://git.bug.tools/bug/implot-luau): [ImPlot](https://github.com/epezent/implot), 2D plotting.
- [implot3d-luau](https://git.bug.tools/bug/implot3d-luau): [ImPlot3D](https://github.com/brenocq/implot3d), 3D plotting.
- [imnodes-luau](https://git.bug.tools/bug/imnodes-luau): [imnodes](https://github.com/Nelarius/imnodes), a node editor.
Usage: `local ImPlot = require(ImPlotModule)(require(ImGuiModule))`.
### Not ported yet
Multi-select / box-select, typing-select, the Assets Browser example, the Item Picker and a few smaller items. The full list is in [docs/TODO.txt](docs/TODO.txt).
+31 -17
View File
@@ -251,9 +251,13 @@ function ImGui_ImplRoblox_SetTextProxy(enabled)
BackendData.ProxyLostId = nil
return
end
BackendData.ProxyLostId = BackendData.ProxyActiveId
BackendData.ProxyLostId = BackendData.ProxyActiveId -- don't recapture for the same field
local g = ImGui.GetCurrentContext()
if g and g.ActiveId ~= 0 and g.ActiveId == BackendData.ProxyActiveId then ImGui.ClearActiveID() end
if g and g.ActiveId ~= 0 and g.ActiveId == BackendData.ProxyActiveId then
ImGui.ClearActiveID()
-- the key falls back to the focused window next: the "don't recapture" covers it too
if g.NavWindow then BackendData.ProxyActiveId = g.NavWindow.ID; BackendData.ProxyLostId = g.NavWindow.ID end
end
end)
end
@@ -307,14 +311,18 @@ function ImGui_ImplRoblox_NewFrame()
local proxy = BackendData.Proxy
local g = ImGui.GetCurrentContext()
local focused_box = proxy and UserInputService:GetFocusedTextBox()
-- key: the active item (InputText), else the focused window (custom widgets setting PlatformImeData.WantTextInput)
local proxy_key = g.ActiveId
if proxy_key == 0 and g.NavWindow then proxy_key = g.NavWindow.ID end
if proxy_key ~= BackendData.ProxyActiveId then BackendData.ProxyLostId = nil end -- (a "don't recapture" never outlives its field)
if not proxy then
elseif io.WantTextInput and g.ActiveId ~= 0 then
if g.ActiveId ~= BackendData.ProxyActiveId or g.ActiveIdIsJustActivated or g.IO.MouseClicked[0] then
BackendData.ProxyActiveId = g.ActiveId
elseif io.WantTextInput and proxy_key ~= 0 then
if proxy_key ~= BackendData.ProxyActiveId or (g.ActiveId ~= 0 and g.ActiveIdIsJustActivated) or g.IO.MouseClicked[0] then
BackendData.ProxyActiveId = proxy_key
BackendData.ProxyLostId = nil
end
local mouse_up = not (io.MouseDown[0] or io.MouseDown[1] or io.MouseDown[2])
if focused_box ~= proxy and mouse_up and BackendData.ProxyLostId ~= g.ActiveId
if focused_box ~= proxy and mouse_up and BackendData.ProxyLostId ~= proxy_key and proxy.Parent
and (focused_box == nil or not focused_box:IsDescendantOf(game)) then
-- what it already holds is not new input (else re-typing it would collapse imgui's selection)
BackendData.ProxyText = proxy.Text
@@ -352,17 +360,15 @@ function ImGui_ImplRoblox_NewFrame()
for _, cp in utf8.codes(text:sub(#prev + 1)) do io:AddInputCharacter(cp) end
end
end
if ctrl then io:AddKeyEvent(ImGuiMod_Ctrl, true) end
-- re-press only if still physically held: the text can arrive after Ctrl's InputEnded, and re-pressing
-- then left Ctrl stuck down in imgui (typing ignored, shortcuts broken until Ctrl was pressed again)
if ctrl and (UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) or UserInputService:IsKeyDown(Enum.KeyCode.RightControl)) then
io:AddKeyEvent(ImGuiMod_Ctrl, true)
end
used_proxy_text = true
BackendData.ProxyText = nil
end
local st = g.InputTextState
local sel = ""
if st and st.ID ~= 0 and st.ID == g.ActiveId and st.Stb and st:HasSelection() then
local a, b = math.min(st.Stb.select_start, st.Stb.select_end),
math.max(st.Stb.select_start, st.Stb.select_end)
sel = ImGui._ByteArrayToString(st.TextA.Data, a, b) -- stb positions are 1-based in this port
end
local sel = g.PlatformImeData.SelectedText or "" -- (last frame's widget selection: ImGui.NewFrame() not run yet)
if sel ~= BackendData.ProxyText then
proxy.Text = sel
BackendData.ProxyLastRaw = nil
@@ -377,9 +383,17 @@ function ImGui_ImplRoblox_NewFrame()
BackendData.DeleteKeySeen = false
local pending = BackendData.PendingChars
if #pending > 0 then
if not used_proxy_text then for _, c in ipairs(pending) do io:AddInputCharacter(c) end end
table.clear(pending)
if used_proxy_text then
table.clear(pending) -- the proxy delivered the text: the key-code copies would double it
BackendData.PendingAge = 0
elseif #pending > 0 then
-- the TextBox's Text can update a frame or two after InputBegan: wait before falling back to key codes
BackendData.PendingAge = (BackendData.PendingAge or 0) + 1
if not ProxyFocused or BackendData.PendingAge > 3 then
for _, c in ipairs(pending) do io:AddInputCharacter(c) end
table.clear(pending)
BackendData.PendingAge = 0
end
end
-- Tiles Active while over imgui, so Roblox stops passing clicks/wheel to the game (camera zoom etc.)
+1 -1
View File
@@ -1 +1 @@
[[46, "imgui.lua"], [22647, "imgui_demo.lua"], [34504, "imgui_draw.lua"], [42828, "imgui_h.lua"], [45827, "roblox/raster.lua"], [46303, "roblox/textures.lua"], [46474, "roblox/layers.lua"], [46811, "roblox/overlays.lua"], [46892, "roblox/render.lua"], [47737, "roblox/parallel.lua"], [48136, "imgui_impl_roblox.lua"], [48623, "imgui_impl_roblox_fonts.lua"], [55026, "imgui_internal.lua"], [58992, "imgui_tables.lua"], [64084, "imgui_widgets.lua"], [76318, "imstb_rectpack.lua"], [76982, "imstb_textedit.lua"], [78524, "imstb_truetype.lua"], [81312, "imstd_minstdio.lua"]]
[[46, "imgui.lua"], [22648, "imgui_demo.lua"], [34505, "imgui_draw.lua"], [42835, "imgui_h.lua"], [45838, "roblox/raster.lua"], [46314, "roblox/textures.lua"], [46485, "roblox/layers.lua"], [46822, "roblox/overlays.lua"], [46903, "roblox/render.lua"], [47748, "roblox/parallel.lua"], [48147, "imgui_impl_roblox.lua"], [48648, "imgui_impl_roblox_fonts.lua"], [55051, "imgui_internal.lua"], [59017, "imgui_tables.lua"], [64109, "imgui_widgets.lua"], [76347, "imstb_rectpack.lua"], [77011, "imstb_textedit.lua"], [78553, "imstb_truetype.lua"], [81341, "imstd_minstdio.lua"]]
+48 -19
View File
@@ -14418,6 +14418,7 @@ function ImGui.NewFrame()
ImGuiPlatformImeData_Copy(g.PlatformImeDataPrev, g.PlatformImeData)
g.PlatformImeData.WantVisible = false
g.PlatformImeData.WantTextInput = false
g.PlatformImeData.SelectedText = "" -- [Port]
-- Mouse wheel scrolling, scale
ImGui.UpdateMouseWheel()
@@ -40648,6 +40649,10 @@ function MT.ImDrawList:AddRect(p_min, p_max, col, rounding, thickness, flags)
return
end
-- [Port] reversed corners (min > max, e.g. a box selection dragged up/left): upstream's min_dim checks drop them, older ImGui drew them
if p_min.x > p_max.x or p_min.y > p_max.y then
p_min, p_max = ImVec2(ImMin(p_min.x, p_max.x), ImMin(p_min.y, p_max.y)), ImVec2(ImMax(p_min.x, p_max.x), ImMax(p_min.y, p_max.y))
end
flags = bit32.bor(flags, self.Flags)
local stroke_pos = _GetStrokePos(flags, 131072 --[[ImDrawFlags.StrokeInside]])
if stroke_pos == 917504 --[[ImDrawFlags.StrokeLegacy]] then
@@ -40865,6 +40870,8 @@ function MT.ImDrawList:AddRectFilled(p_min, p_max, col, rounding, flags)
end
local ax, ay, bx, by = p_min.x, p_min.y, p_max.x, p_max.y
if ax > bx then ax, bx = bx, ax end -- [Port] reversed corners: see AddRect
if ay > by then ay, by = by, ay end
local width = bx - ax
local height = by - ay
local min_dim = ImMin(width, height)
@@ -44265,6 +44272,7 @@ end
--- @field InputPos ImVec2
--- @field InputLineHeight float
--- @field ViewportId ImGuiID
--- @field SelectedText string
--- @return ImGuiPlatformImeData
--- @nodiscard
@@ -44274,7 +44282,8 @@ function ImGuiPlatformImeData()
WantTextInput = false, -- A widget wants text input, not necessarily IME to be visible. This is automatically set to the upcoming value of io.WantTextInput.
InputPos = ImVec2(), -- Position of input cursor (for IME).
InputLineHeight = 0.0, -- Line height (for IME).
ViewportId = 0 -- ID of platform window/viewport.
ViewportId = 0, -- ID of platform window/viewport.
SelectedText = "" -- [Port] Text currently selected in the widget wanting text input (backends may mirror it, e.g. for native copy).
}
end
@@ -44286,6 +44295,7 @@ function ImGuiPlatformImeData_Copy(dest, src)
ImVec2_Copy(dest.InputPos, src.InputPos)
dest.InputLineHeight = src.InputLineHeight
dest.ViewportId = src.ViewportId
dest.SelectedText = src.SelectedText -- [Port]
end
--- @param data1 ImGuiPlatformImeData
@@ -44295,7 +44305,8 @@ function ImGuiPlatformImeData_Compare(data1, data2)
data1.WantTextInput ~= data2.WantTextInput or
data1.InputPos ~= data2.InputPos or
data1.InputLineHeight ~= data2.InputLineHeight or
data1.ViewportId ~= data2.ViewportId then
data1.ViewportId ~= data2.ViewportId or
data1.SelectedText ~= data2.SelectedText then
return false
end
@@ -48386,9 +48397,13 @@ function ImGui_ImplRoblox_SetTextProxy(enabled)
BackendData.ProxyLostId = nil
return
end
BackendData.ProxyLostId = BackendData.ProxyActiveId
BackendData.ProxyLostId = BackendData.ProxyActiveId -- don't recapture for the same field
local g = ImGui.GetCurrentContext()
if g and g.ActiveId ~= 0 and g.ActiveId == BackendData.ProxyActiveId then ImGui.ClearActiveID() end
if g and g.ActiveId ~= 0 and g.ActiveId == BackendData.ProxyActiveId then
ImGui.ClearActiveID()
-- the key falls back to the focused window next: the "don't recapture" covers it too
if g.NavWindow then BackendData.ProxyActiveId = g.NavWindow.ID; BackendData.ProxyLostId = g.NavWindow.ID end
end
end)
end
@@ -48442,14 +48457,18 @@ function ImGui_ImplRoblox_NewFrame()
local proxy = BackendData.Proxy
local g = ImGui.GetCurrentContext()
local focused_box = proxy and UserInputService:GetFocusedTextBox()
-- key: the active item (InputText), else the focused window (custom widgets setting PlatformImeData.WantTextInput)
local proxy_key = g.ActiveId
if proxy_key == 0 and g.NavWindow then proxy_key = g.NavWindow.ID end
if proxy_key ~= BackendData.ProxyActiveId then BackendData.ProxyLostId = nil end -- (a "don't recapture" never outlives its field)
if not proxy then
elseif io.WantTextInput and g.ActiveId ~= 0 then
if g.ActiveId ~= BackendData.ProxyActiveId or g.ActiveIdIsJustActivated or g.IO.MouseClicked[0] then
BackendData.ProxyActiveId = g.ActiveId
elseif io.WantTextInput and proxy_key ~= 0 then
if proxy_key ~= BackendData.ProxyActiveId or (g.ActiveId ~= 0 and g.ActiveIdIsJustActivated) or g.IO.MouseClicked[0] then
BackendData.ProxyActiveId = proxy_key
BackendData.ProxyLostId = nil
end
local mouse_up = not (io.MouseDown[0] or io.MouseDown[1] or io.MouseDown[2])
if focused_box ~= proxy and mouse_up and BackendData.ProxyLostId ~= g.ActiveId
if focused_box ~= proxy and mouse_up and BackendData.ProxyLostId ~= proxy_key and proxy.Parent
and (focused_box == nil or not focused_box:IsDescendantOf(game)) then
-- what it already holds is not new input (else re-typing it would collapse imgui's selection)
BackendData.ProxyText = proxy.Text
@@ -48487,17 +48506,15 @@ function ImGui_ImplRoblox_NewFrame()
for _, cp in utf8.codes(text:sub(#prev + 1)) do io:AddInputCharacter(cp) end
end
end
if ctrl then io:AddKeyEvent(4096 --[[ImGuiMod_Ctrl]], true) end
-- re-press only if still physically held: the text can arrive after Ctrl's InputEnded, and re-pressing
-- then left Ctrl stuck down in imgui (typing ignored, shortcuts broken until Ctrl was pressed again)
if ctrl and (UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) or UserInputService:IsKeyDown(Enum.KeyCode.RightControl)) then
io:AddKeyEvent(4096 --[[ImGuiMod_Ctrl]], true)
end
used_proxy_text = true
BackendData.ProxyText = nil
end
local st = g.InputTextState
local sel = ""
if st and st.ID ~= 0 and st.ID == g.ActiveId and st.Stb and st:HasSelection() then
local a, b = math.min(st.Stb.select_start, st.Stb.select_end),
math.max(st.Stb.select_start, st.Stb.select_end)
sel = ImGui._ByteArrayToString(st.TextA.Data, a, b) -- stb positions are 1-based in this port
end
local sel = g.PlatformImeData.SelectedText or "" -- (last frame's widget selection: ImGui.NewFrame() not run yet)
if sel ~= BackendData.ProxyText then
proxy.Text = sel
BackendData.ProxyLastRaw = nil
@@ -48512,9 +48529,17 @@ function ImGui_ImplRoblox_NewFrame()
BackendData.DeleteKeySeen = false
local pending = BackendData.PendingChars
if #pending > 0 then
if not used_proxy_text then for _, c in ipairs(pending) do io:AddInputCharacter(c) end end
table.clear(pending)
if used_proxy_text then
table.clear(pending) -- the proxy delivered the text: the key-code copies would double it
BackendData.PendingAge = 0
elseif #pending > 0 then
-- the TextBox's Text can update a frame or two after InputBegan: wait before falling back to key codes
BackendData.PendingAge = (BackendData.PendingAge or 0) + 1
if not ProxyFocused or BackendData.PendingAge > 3 then
for _, c in ipairs(pending) do io:AddInputCharacter(c) end
table.clear(pending)
BackendData.PendingAge = 0
end
end
-- Tiles Active while over imgui, so Roblox stops passing clicks/wheel to the game (camera zoom etc.)
@@ -70491,6 +70516,10 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
ImVec2_Copy(ime_data.InputPos, ImVec2(cursor_screen_pos.x - 1.0, cursor_screen_pos.y - g.FontSize))
ime_data.InputLineHeight = g.FontSize
ime_data.ViewportId = window.Viewport.ID
-- [Port] selection for backends (stb positions are 1-based in this port)
if state.Stb and state:HasSelection() then
ime_data.SelectedText = ImGui._ByteArrayToString(state.TextA.Data, ImMin(state.Stb.select_start, state.Stb.select_end), ImMax(state.Stb.select_start, state.Stb.select_end))
end
end
end
+1 -1
View File
@@ -1 +1 @@
[[183, "imgui.lua"], [22784, "imgui_demo.lua"], [34641, "imgui_draw.lua"], [42965, "imgui_h.lua"], [45962, "imgui_impl_love.lua"], [46506, "imgui_internal.lua"], [50472, "imgui_tables.lua"], [55564, "imgui_widgets.lua"], [67798, "imstb_rectpack.lua"], [68462, "imstb_textedit.lua"], [70004, "imstb_truetype.lua"], [72792, "imstd_minstdio.lua"]]
[[183, "imgui.lua"], [22785, "imgui_demo.lua"], [34642, "imgui_draw.lua"], [42972, "imgui_h.lua"], [45973, "imgui_impl_love.lua"], [46517, "imgui_internal.lua"], [50483, "imgui_tables.lua"], [55575, "imgui_widgets.lua"], [67813, "imstb_rectpack.lua"], [68477, "imstb_textedit.lua"], [70019, "imstb_truetype.lua"], [72807, "imstd_minstdio.lua"]]
+17 -2
View File
@@ -14555,6 +14555,7 @@ function ImGui.NewFrame()
ImGuiPlatformImeData_Copy(g.PlatformImeDataPrev, g.PlatformImeData)
g.PlatformImeData.WantVisible = false
g.PlatformImeData.WantTextInput = false
g.PlatformImeData.SelectedText = "" -- [Port]
-- Mouse wheel scrolling, scale
ImGui.UpdateMouseWheel()
@@ -40785,6 +40786,10 @@ function MT.ImDrawList:AddRect(p_min, p_max, col, rounding, thickness, flags)
return
end
-- [Port] reversed corners (min > max, e.g. a box selection dragged up/left): upstream's min_dim checks drop them, older ImGui drew them
if p_min.x > p_max.x or p_min.y > p_max.y then
p_min, p_max = ImVec2(ImMin(p_min.x, p_max.x), ImMin(p_min.y, p_max.y)), ImVec2(ImMax(p_min.x, p_max.x), ImMax(p_min.y, p_max.y))
end
flags = bit32.bor(flags, self.Flags)
local stroke_pos = _GetStrokePos(flags, 131072 --[[ImDrawFlags.StrokeInside]])
if stroke_pos == 917504 --[[ImDrawFlags.StrokeLegacy]] then
@@ -41002,6 +41007,8 @@ function MT.ImDrawList:AddRectFilled(p_min, p_max, col, rounding, flags)
end
local ax, ay, bx, by = p_min.x, p_min.y, p_max.x, p_max.y
if ax > bx then ax, bx = bx, ax end -- [Port] reversed corners: see AddRect
if ay > by then ay, by = by, ay end
local width = bx - ax
local height = by - ay
local min_dim = ImMin(width, height)
@@ -44402,6 +44409,7 @@ end
--- @field InputPos ImVec2
--- @field InputLineHeight float
--- @field ViewportId ImGuiID
--- @field SelectedText string
--- @return ImGuiPlatformImeData
--- @nodiscard
@@ -44411,7 +44419,8 @@ function ImGuiPlatformImeData()
WantTextInput = false, -- A widget wants text input, not necessarily IME to be visible. This is automatically set to the upcoming value of io.WantTextInput.
InputPos = ImVec2(), -- Position of input cursor (for IME).
InputLineHeight = 0.0, -- Line height (for IME).
ViewportId = 0 -- ID of platform window/viewport.
ViewportId = 0, -- ID of platform window/viewport.
SelectedText = "" -- [Port] Text currently selected in the widget wanting text input (backends may mirror it, e.g. for native copy).
}
end
@@ -44423,6 +44432,7 @@ function ImGuiPlatformImeData_Copy(dest, src)
ImVec2_Copy(dest.InputPos, src.InputPos)
dest.InputLineHeight = src.InputLineHeight
dest.ViewportId = src.ViewportId
dest.SelectedText = src.SelectedText -- [Port]
end
--- @param data1 ImGuiPlatformImeData
@@ -44432,7 +44442,8 @@ function ImGuiPlatformImeData_Compare(data1, data2)
data1.WantTextInput ~= data2.WantTextInput or
data1.InputPos ~= data2.InputPos or
data1.InputLineHeight ~= data2.InputLineHeight or
data1.ViewportId ~= data2.ViewportId then
data1.ViewportId ~= data2.ViewportId or
data1.SelectedText ~= data2.SelectedText then
return false
end
@@ -61971,6 +61982,10 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
ImVec2_Copy(ime_data.InputPos, ImVec2(cursor_screen_pos.x - 1.0, cursor_screen_pos.y - g.FontSize))
ime_data.InputLineHeight = g.FontSize
ime_data.ViewportId = window.Viewport.ID
-- [Port] selection for backends (stb positions are 1-based in this port)
if state.Stb and state:HasSelection() then
ime_data.SelectedText = ImGui._ByteArrayToString(state.TextA.Data, ImMin(state.Stb.select_start, state.Stb.select_end), ImMax(state.Stb.select_start, state.Stb.select_end))
end
end
end
+1
View File
@@ -14373,6 +14373,7 @@ function ImGui.NewFrame()
ImGuiPlatformImeData_Copy(g.PlatformImeDataPrev, g.PlatformImeData)
g.PlatformImeData.WantVisible = false
g.PlatformImeData.WantTextInput = false
g.PlatformImeData.SelectedText = "" -- [Port]
-- Mouse wheel scrolling, scale
ImGui.UpdateMouseWheel()
+6
View File
@@ -6145,6 +6145,10 @@ function MT.ImDrawList:AddRect(p_min, p_max, col, rounding, thickness, flags)
return
end
-- [Port] reversed corners (min > max, e.g. a box selection dragged up/left): upstream's min_dim checks drop them, older ImGui drew them
if p_min.x > p_max.x or p_min.y > p_max.y then
p_min, p_max = ImVec2(ImMin(p_min.x, p_max.x), ImMin(p_min.y, p_max.y)), ImVec2(ImMax(p_min.x, p_max.x), ImMax(p_min.y, p_max.y))
end
flags = bit32.bor(flags, self.Flags)
local stroke_pos = _GetStrokePos(flags, ImDrawFlags.StrokeInside)
if stroke_pos == ImDrawFlags.StrokeLegacy then
@@ -6362,6 +6366,8 @@ function MT.ImDrawList:AddRectFilled(p_min, p_max, col, rounding, flags)
end
local ax, ay, bx, by = p_min.x, p_min.y, p_max.x, p_max.y
if ax > bx then ax, bx = bx, ax end -- [Port] reversed corners: see AddRect
if ay > by then ay, by = by, ay end
local width = bx - ax
local height = by - ay
local min_dim = ImMin(width, height)
+6 -2
View File
@@ -1438,6 +1438,7 @@ end
--- @field InputPos ImVec2
--- @field InputLineHeight float
--- @field ViewportId ImGuiID
--- @field SelectedText string
--- @return ImGuiPlatformImeData
--- @nodiscard
@@ -1447,7 +1448,8 @@ function ImGuiPlatformImeData()
WantTextInput = false, -- A widget wants text input, not necessarily IME to be visible. This is automatically set to the upcoming value of io.WantTextInput.
InputPos = ImVec2(), -- Position of input cursor (for IME).
InputLineHeight = 0.0, -- Line height (for IME).
ViewportId = 0 -- ID of platform window/viewport.
ViewportId = 0, -- ID of platform window/viewport.
SelectedText = "" -- [Port] Text currently selected in the widget wanting text input (backends may mirror it, e.g. for native copy).
}
end
@@ -1459,6 +1461,7 @@ function ImGuiPlatformImeData_Copy(dest, src)
ImVec2_Copy(dest.InputPos, src.InputPos)
dest.InputLineHeight = src.InputLineHeight
dest.ViewportId = src.ViewportId
dest.SelectedText = src.SelectedText -- [Port]
end
--- @param data1 ImGuiPlatformImeData
@@ -1468,7 +1471,8 @@ function ImGuiPlatformImeData_Compare(data1, data2)
data1.WantTextInput ~= data2.WantTextInput or
data1.InputPos ~= data2.InputPos or
data1.InputLineHeight ~= data2.InputLineHeight or
data1.ViewportId ~= data2.ViewportId then
data1.ViewportId ~= data2.ViewportId or
data1.SelectedText ~= data2.SelectedText then
return false
end
+4
View File
@@ -6408,6 +6408,10 @@ function ImGui.InputTextEx(label, hint, buf, buf_size, size_arg, flags, callback
ImVec2_Copy(ime_data.InputPos, ImVec2(cursor_screen_pos.x - 1.0, cursor_screen_pos.y - g.FontSize))
ime_data.InputLineHeight = g.FontSize
ime_data.ViewportId = window.Viewport.ID
-- [Port] selection for backends (stb positions are 1-based in this port)
if state.Stb and state:HasSelection() then
ime_data.SelectedText = ImGui._ByteArrayToString(state.TextA.Data, ImMin(state.Stb.select_start, state.Stb.select_end), ImMax(state.Stb.select_start, state.Stb.select_end))
end
end
end
+2
View File
@@ -31,6 +31,7 @@ CHECKS=(
"passthru|PASSTHRU OK|$R --main tools/test/scripts/t_passthru.luau --frames 40"
"fonts|FONTS OK|$R --main tools/test/scripts/t_fonts.luau --frames 8"
"textproxy|PROXY OK|$R --main tools/test/scripts/t_textproxy.luau --frames 30"
"textproxy_custom|CUSTOM PROXY OK|$R --main tools/test/scripts/t_textproxy_custom.luau --frames 15"
"style_editor|SE OK|$R --main tools/test/scripts/t_style_editor.luau --frames 20"
"style_leak|STYLE OK|$R --main tools/test/scripts/t_style_leak.luau --frames 60 --open"
"apps|APPS OK|$R --main tools/test/scripts/t_apps.luau --frames 120 --open"
@@ -38,6 +39,7 @@ CHECKS=(
"demo_open|DRAWHASH|$R --main tools/test/scripts/t_drawhash.luau --frames 150 --open"
"demo_random|^|python3 tools/test/run.py --roblox --timeout 600 --frames 400 --open"
"pixels|PIXELS SAME|a=\$($R --main tools/test/scripts/t_pixels.luau --frames 600 | grep -P '^PIX\t'); b=\$(RUN_FLAGS=ARG_FORCE=true $R --main tools/test/scripts/t_pixels.luau --frames 600 | grep -P '^PIX\t'); [ -n \"\$a\" ] && [ \"\$a\" = \"\$b\" ] && echo PIXELS SAME"
"rect_flip|RECTFLIP OK|$R --main tools/test/scripts/t_rect_flip.luau --frames 30"
"tile_bound|TILEBOUND OK|$R --main tools/test/scripts/t_tile_bound.luau --frames 200"
"parallel|PARALLEL OK|$R --main tools/test/scripts/t_parallel.luau --frames 500"
"pool_ctx|POOLCTX OK|$R --main tools/test/scripts/t_pool_ctx.luau --frames 60"
+1
View File
@@ -192,6 +192,7 @@ ROBLOX = setmetatable({
}, { __index = realG })
local mod = newInst("ModuleScript", "ImGui", ReplicatedStorage); rawset(mod, "_src", "ImGui.luau")
for _, name in EXTRA_MODULES or {} do rawset(newInst("ModuleScript", name, ReplicatedStorage), "_src", name) end
-- Run main.lua as a LocalScript
local main = loadAsScript("main.client.luau", newInst("LocalScript", "main"))
main()
+5
View File
@@ -24,6 +24,10 @@ def build_run(args, flags):
out.append("SOURCE_FNS[%r] = function(%s)\n%s\nend" % (key, G, s))
add("ImGui.luau", os.path.join(TMP, "ImGui.luau"))
add("main.client.luau", args.main)
for m in args.module: # [extensions] NAME=path -> ReplicatedStorage.NAME ModuleScript
name, path = m.split("=", 1)
add(name, path)
out.append("EXTRA_MODULES = {%s}" % ",".join(repr(m.split("=", 1)[0]) for m in args.module))
out.append(open(os.path.join(HERE, "roblox_mock.luau")).read())
global OFFSET, LAST_LINE, STRIPPED
bundle = open(os.path.join(TMP, "ImGui.luau")).read()
@@ -66,6 +70,7 @@ def main():
ap.add_argument("--profile", action="store_true", help="sampling profile (no codegen) -> profile.out; see tools/test/prof.py")
ap.add_argument("--open", action="store_true", help="force all CollapsingHeader/TreeNode open")
ap.add_argument("--timeout", type=int, default=120)
ap.add_argument("--module", action="append", default=[], help="NAME=path: extra ModuleScript in ReplicatedStorage (extension repos)")
ap.add_argument("--quiet", action="store_true", help="no random input (scripted tests drive io themselves)")
args = ap.parse_args()
+89
View File
@@ -0,0 +1,89 @@
-- Reversed rects (min > max, e.g. box-select dragged up/left) must draw like upstream's GPU path:
-- AddRectFilled + AddRect from each of the 4 drag directions composite to identical, non-blank pixels.
local G = require(game:GetService("ReplicatedStorage"):WaitForChild("ImGui"))
local ImGui, ImVec2 = G.ImGui, G.ImVec2
ImGui.CreateContext()
G.ImGui_ImplRoblox.Init()
G.ImGui_ImplRoblox.SetRenderRate(0)
local io = ImGui.GetIO()
local W, H = 1280, 760
local function composite(gui)
local screen = buffer.create(W * H * 3)
local function walk(inst, ox, oy, kx0, ky0, kx1, ky1)
local kids = inst:GetChildren()
table.sort(kids, function(a, b) return (a.ZIndex or 1) < (b.ZIndex or 1) end)
for _, c in ipairs(kids) do
if c.Visible ~= false then
local x, y = ox + (c.Position and c.Position.X or 0), oy + (c.Position and c.Position.Y or 0)
local cx0, cy0, cx1, cy1 = kx0, ky0, kx1, ky1
if c.ClipsDescendants then
cx0, cy0 = math.max(cx0, x), math.max(cy0, y)
cx1, cy1 = math.min(cx1, x + c.Size.X), math.min(cy1, y + c.Size.Y)
end
if c.ClassName == "ImageLabel" then
local img = c.ImageContent.Object
local px, sz = img.Pixels, img.Size.X
for ty = 0, sz - 1 do
local sy = y + ty
if sy >= cy0 and sy < cy1 then
for tx = 0, sz - 1 do
local sx = x + tx
if sx >= cx0 and sx < cx1 then
local o = (ty * sz + tx) * 4
local a = buffer.readu8(px, o + 3)
if a > 0 then
local d = (sy * W + sx) * 3
local fa = a / 255
for ch = 0, 2 do
local v = buffer.readu8(px, o + ch) * fa + buffer.readu8(screen, d + ch) * (1 - fa)
buffer.writeu8(screen, d + ch, math.floor(v + 0.5))
end
end
end
end
end
end
end
walk(c, x, y, cx0, cy0, cx1, cy1)
end
end
end
walk(gui, 0, 0, 0, 0, W, H)
local h = 0
for i = 0, W * H * 3 - 4, 4 do h = (h * 31 + buffer.readu32(screen, i)) % 2147483647 end
return h
end
local A, B = ImVec2(200, 150), ImVec2(520, 400) -- drag start/end, down-right
local DIRS = { "none", "dr", "ul", "ur", "dl" }
local CORNERS = {
dr = { A, B }, ul = { B, A },
ur = { ImVec2(A.x, B.y), ImVec2(B.x, A.y) }, dl = { ImVec2(B.x, A.y), ImVec2(A.x, B.y) },
}
local di, pf, res = 1, 0, {}
game:GetService("RunService").Stepped:Connect(function()
local d = DIRS[di]
if not d then return end
pf += 1
G.ImGui_ImplRoblox.NewFrame()
io.DeltaTime = 1 / 60
ImGui.NewFrame()
local c = CORNERS[d]
if c then
local dl = ImGui.GetForegroundDrawList()
dl:AddRectFilled(c[1], c[2], 0x6496FF32)
dl:AddRect(c[1], c[2], 0xFFFF9664, 0, 2)
dl:AddRectFilled(c[1], c[2], 0xFF00FF00, 12) -- rounded too
end
ImGui.Render()
G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if pf == 4 then
res[d] = composite(game:GetService("Players").LocalPlayer.PlayerGui:FindFirstChild("ImGui"))
print("RECT", d, res[d])
di += 1; pf = 0
if not DIRS[di] then
local ok = res.dr ~= res.none and res.ul == res.dr and res.ur == res.dr and res.dl == res.dr
print(ok and "RECTFLIP OK" or "RECTFLIP MISMATCH")
end
end
end)
+1 -1
View File
@@ -64,7 +64,7 @@ game:GetService("RunService").Stepped:Connect(function()
assert(st.TextLen == 0, "backspace should delete imgui's whole selection, len " .. st.TextLen)
print("BACKSPACE OK")
end
if f == 27 then
if f == 30 then -- (key-code fallback waits a few frames for the TextBox first)
local st = ImGui.GetCurrentContext().InputTextState
local got = G.ImGui._ByteArrayToString(st.TextA.Data, 1, st.TextLen + 1)
assert(got:find("z"), "key fallback while proxy focused: " .. got)
@@ -0,0 +1,31 @@
-- Text proxy for a custom widget (no ActiveId): it sets PlatformImeData.WantTextInput/SelectedText while its window is focused.
local G = require(game:GetService("ReplicatedStorage"):WaitForChild("ImGui"))
local ImGui, ImVec2 = G.ImGui, G.ImVec2
local UIS = game:GetService("UserInputService")
ImGui.CreateContext(); G.ImGui_ImplRoblox.Init(); G.ImGui_ImplRoblox.SetTextProxy(true)
local io = ImGui.GetIO()
local got, proxy, f = "", nil, 0
game:GetService("RunService").Stepped:Connect(function()
f += 1
G.ImGui_ImplRoblox.NewFrame()
proxy = proxy or game:GetService("Players").LocalPlayer.PlayerGui.ImGui.TextProxy
if f == 3 then io:AddMousePosEvent(60, 45); io:AddMouseButtonEvent(0, true) end
if f == 4 then io:AddMouseButtonEvent(0, false) end
if f == 8 then assert(UIS:GetFocusedTextBox() == proxy, "proxy focused"); proxy.Text = "x" end
ImGui.NewFrame()
ImGui.SetNextWindowPos(ImVec2(10, 10)); ImGui.SetNextWindowSize(ImVec2(300, 100))
ImGui.Begin("Editor")
if ImGui.IsWindowFocused() then
local ime = ImGui.GetCurrentContext().PlatformImeData
ime.WantTextInput = true; ime.SelectedText = "abc"
local q = io.InputQueueCharacters
for i = 1, q.Size do got ..= utf8.char(q.Data[i]) end
end
ImGui.End()
ImGui.Render(); G.ImGui_ImplRoblox.RenderDrawData(ImGui.GetDrawData())
if f == 12 then
assert(got == "x", "widget got: " .. got)
assert(proxy.Text == "abc", "mirror: " .. proxy.Text)
print("CUSTOM PROXY OK")
end
end)
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "4dbug/imgui-luau"
version = "0.4.0"
version = "0.4.1"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
license = "MIT"