TextProxy: works for any widget that sets PlatformImeData.WantTextInput (+SelectedText)
Build & Release / build (push) Canceled after 0s
Build & Release / build (push) Canceled after 0s
This commit is contained in:
1 parent
8f2dfe358d
commit
b0e4f105f5
10 files changed
+97
-34
No files matched your search
Generated
+1
-1
@@ -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"], [42829, "imgui_h.lua"], [45832, "roblox/raster.lua"], [46308, "roblox/textures.lua"], [46479, "roblox/layers.lua"], [46816, "roblox/overlays.lua"], [46897, "roblox/render.lua"], [47742, "roblox/parallel.lua"], [48141, "imgui_impl_roblox.lua"], [48630, "imgui_impl_roblox_fonts.lua"], [55033, "imgui_internal.lua"], [58999, "imgui_tables.lua"], [64091, "imgui_widgets.lua"], [76329, "imstb_rectpack.lua"], [76993, "imstb_textedit.lua"], [78535, "imstb_truetype.lua"], [81323, "imstd_minstdio.lua"]]
|
||||
Generated
+26
-15
@@ -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()
|
||||
@@ -44265,6 +44266,7 @@ end
|
||||
--- @field InputPos ImVec2
|
||||
--- @field InputLineHeight float
|
||||
--- @field ViewportId ImGuiID
|
||||
--- @field SelectedText string
|
||||
|
||||
--- @return ImGuiPlatformImeData
|
||||
--- @nodiscard
|
||||
@@ -44274,7 +44276,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 +44289,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 +44299,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 +48391,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 +48451,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
|
||||
@@ -48491,13 +48504,7 @@ function ImGui_ImplRoblox_NewFrame()
|
||||
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
|
||||
@@ -70491,6 +70498,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
|
||||
|
||||
|
||||
Generated
+1
-1
@@ -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"], [42966, "imgui_h.lua"], [45967, "imgui_impl_love.lua"], [46511, "imgui_internal.lua"], [50477, "imgui_tables.lua"], [55569, "imgui_widgets.lua"], [67807, "imstb_rectpack.lua"], [68471, "imstb_textedit.lua"], [70013, "imstb_truetype.lua"], [72801, "imstd_minstdio.lua"]]
|
||||
Generated
+11
-2
@@ -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()
|
||||
@@ -44402,6 +44403,7 @@ end
|
||||
--- @field InputPos ImVec2
|
||||
--- @field InputLineHeight float
|
||||
--- @field ViewportId ImGuiID
|
||||
--- @field SelectedText string
|
||||
|
||||
--- @return ImGuiPlatformImeData
|
||||
--- @nodiscard
|
||||
@@ -44411,7 +44413,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 +44426,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 +44436,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 +61976,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
|
||||
|
||||
|
||||
Reference in new issue
Block a user