Skip to content

Commit 4747fa0

Browse files
authored
Lil FX Slot Homie Update v1.2.1 (ReaTeam#1416)
Scroll to selected items if they are not in view Fix ESC Clear/close script
1 parent 522c39d commit 4747fa0

File tree

1 file changed

+62
-28
lines changed

1 file changed

+62
-28
lines changed

FX/sexan_Lil FX Slot Homie.lua

+62-28
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
-- @description Lil FX Slot Homie
22
-- @author Sexan
3-
-- @version 1.2
3+
-- @version 1.2.1
44
-- @link https://forum.cockos.com/showthread.php?p=2680992#post2680992
55
-- @changelog
6-
-- Imgui Shims
7-
-- Implement FX Browser parser
6+
-- Scroll to selected items if they are not in view
7+
-- Fix ESC Clear/close script
88

99
local SLOT = 1
1010

@@ -58,7 +58,7 @@ if r.file_exists(fx_browser_script_path) then
5858
dofile(fx_browser_script_path)
5959
end
6060

61-
local ctx = r.ImGui_CreateContext('Lil FX Slot Homie', r.ImGui_ConfigFlags_NavEnableKeyboard())
61+
local ctx = r.ImGui_CreateContext('Lil FX Slot Homie')
6262

6363
local FX_LIST = ReadFXFile()
6464

@@ -121,7 +121,7 @@ local function SetMinMax(Input, Min, Max)
121121
return Input
122122
end
123123

124-
local FILTER = ''
124+
FILTER = ''
125125
local function AddFxToTracks(fx)
126126
if r.CountTracks(0) == 1 and r.CountSelectedTracks(0) == 0 then
127127
local track = r.GetTrack(0, 0)
@@ -166,11 +166,36 @@ local function AllowChildFocus(i)
166166
end
167167
end
168168

169+
function SetMinMax(Input, Min, Max)
170+
if Input >= Max then
171+
Input = Max
172+
elseif Input <= Min then
173+
Input = Min
174+
else
175+
Input = Input
176+
end
177+
return Input
178+
end
179+
180+
local function scroll(pos)
181+
if not reaper.ImGui_IsItemVisible(ctx) then
182+
reaper.ImGui_SetScrollHereY(ctx,pos)
183+
end
184+
185+
end
186+
169187
local filter_h = 60
170188
local MAX_FX_SIZE = 300
171189
function FilterBox()
172190
CheckKeyNumbers()
173191
r.ImGui_SetNextWindowSize(ctx, 0, filter_h)
192+
if r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_Escape()) then
193+
if #FILTER == 0 then
194+
CLOSE = true
195+
else
196+
FOCUS = true
197+
end
198+
end
174199
if r.ImGui_BeginPopup(ctx, "popup") then
175200
r.ImGui_Text(ctx, "ADD TO SLOT : " .. (SLOT < 100 and tostring(SLOT) or "LAST"))
176201
r.ImGui_SameLine(ctx, 0, 20)
@@ -179,33 +204,42 @@ function FilterBox()
179204
end
180205
r.ImGui_PushItemWidth(ctx, MAX_FX_SIZE)
181206
if r.ImGui_IsWindowAppearing(ctx) then r.ImGui_SetKeyboardFocusHere(ctx) end
182-
-- IF KEYBOARD FOCUS IS ON CHILD ITEMS SET IT HERE
183-
if r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_Escape()) then r.ImGui_SetKeyboardFocusHere(ctx) end
184-
_, FILTER = r.ImGui_InputText(ctx, '##input', FILTER)
185-
if r.ImGui_IsItemFocused(ctx) then
186-
ALLOW_IN_LIST, PASS_FOCUS = nil, nil
187-
-- IF FOCUS IS ALREADY HERE CLOSE POPUP
188-
if r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_Escape()) then r.ImGui_CloseCurrentPopup(ctx) end
207+
if FOCUS then
208+
r.ImGui_SetKeyboardFocusHere(ctx)
209+
FOCUS = nil
189210
end
211+
if CLOSE then
212+
r.ImGui_CloseCurrentPopup(ctx)
213+
end
214+
_, FILTER = r.ImGui_InputText(ctx, '##input', FILTER)
190215

191216
local filtered_fx = Filter_actions(FILTER)
217+
ADDFX_Sel_Entry = SetMinMax(ADDFX_Sel_Entry or 1, 1, #filtered_fx)
192218
filter_h = #filtered_fx == 0 and 60 or (#filtered_fx > 40 and 20 * 17 or (17 * #filtered_fx) + 55)
193-
194-
if r.ImGui_BeginChild(ctx, "aaaaa") then
195-
-- DANCING AROUND SOME LIMITATIONS OF SELECTING CHILDS
196-
if r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_DownArrow()) then
197-
if not ALLOW_IN_LIST then ALLOW_IN_LIST = true end
198-
end
199-
for i = 1, #filtered_fx do
200-
AllowChildFocus(i)
201-
r.ImGui_PushID(ctx, i)
202-
if r.ImGui_Selectable(ctx, filtered_fx[i].name, true, nil, MAX_FX_SIZE) then
203-
AddFxToTracks(filtered_fx[i].name)
204-
end
205-
r.ImGui_PopID(ctx)
206-
end
207-
r.ImGui_EndChild(ctx)
208-
end
219+
220+
if r.ImGui_BeginChild(ctx, "aaaaa") then
221+
for i = 1, #filtered_fx do
222+
r.ImGui_PushID(ctx, i)
223+
if r.ImGui_Selectable(ctx, filtered_fx[i].name, i == ADDFX_Sel_Entry, nil, MAX_FX_SIZE) then
224+
AddFxToTracks(filtered_fx[i].name)
225+
end
226+
r.ImGui_PopID(ctx)
227+
if i == ADDFX_Sel_Entry then
228+
scroll(scroll_pos)
229+
end
230+
end
231+
if r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_Enter()) then
232+
AddFxToTracks(filtered_fx[ADDFX_Sel_Entry].name)
233+
ADDFX_Sel_Entry = nil
234+
elseif r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_UpArrow()) then
235+
ADDFX_Sel_Entry = ADDFX_Sel_Entry - 1
236+
elseif r.ImGui_IsKeyPressed(ctx, r.ImGui_Key_DownArrow()) then
237+
ADDFX_Sel_Entry = ADDFX_Sel_Entry + 1
238+
end
239+
r.ImGui_EndChild(ctx)
240+
end
241+
242+
209243
r.ImGui_EndPopup(ctx)
210244
r.defer(FilterBox)
211245
end

0 commit comments

Comments
 (0)