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
@@ -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
|
||||
@@ -356,13 +364,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
|
||||
|
||||
Reference in new issue
Block a user