Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track icon selector Categories sorting #1437

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions Tracks/reapertips_Track icon selector.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
-- @description Track icon selector
-- @author Reapertips & Sexan
-- @version 1.04
-- @version 1.07
-- @changelog
-- Push custom font before calculating longest folder name (fixes panel size getting werid widths because of wrong font)
-- Allow keyboard navigation (up,down,left,right,enter)
-- Clicking on any icon sets keyboard focus there
-- @provides
-- reatips_Track icon selector/*.png
-- @screenshot
Expand Down Expand Up @@ -92,6 +93,7 @@ end
local OPEN_CATEGORIES = ALWAYS_SHOW_CATEGORIES

local MAIN_PNG_TBL = {
[-1] = { dir = "Root" },
[0] = { dir = "All Icons" }
}
local FILTERED_PNG
Expand All @@ -100,7 +102,7 @@ local icon_size = 32

r.set_action_options(1)

local ctx = imgui.CreateContext('Track icon selector')
local ctx = imgui.CreateContext('Track icon selector', imgui.ConfigFlags_NavEnableKeyboard)
local WND_W, WND_H = 500, 500
local FLT_MIN, FLT_MAX = imgui.NumericLimits_Float()

Expand Down Expand Up @@ -166,16 +168,27 @@ local function GetDirFilesRecursive(dir, tbl, filter)
local file = r.EnumerateFiles(dir, index)
if not file then break end
if file:find(filter, nil, true) then
tbl[#tbl + 1] = { name = dir .. os_separator .. file, short_name = file }
if dir == reaper_path .. png_path_track_icons then
table.insert(MAIN_PNG_TBL[-1], { name = dir .. os_separator .. file, short_name = file })
else
tbl[#tbl + 1] = { name = dir .. os_separator .. file, short_name = file }
end
table.insert(MAIN_PNG_TBL[0], { name = dir .. os_separator .. file, short_name = file })
end
end
end

GetDirFilesRecursive(reaper_path .. png_path_track_icons, MAIN_PNG_TBL, ".png")

table.sort(MAIN_PNG_TBL,
function(a, b)
if a.dir and b.dir then return a.dir:lower() < b.dir:lower() end
return false
end)

local largest_name = 0
imgui.PushFont(ctx, SYSTEM_FONT_FACTORY)
for i = 0, #MAIN_PNG_TBL do
for i = -1, #MAIN_PNG_TBL do
if MAIN_PNG_TBL[i].dir then
local cur_size = imgui.CalcTextSize(ctx, MAIN_PNG_TBL[i].dir)
largest_name = cur_size > largest_name and cur_size or largest_name
Expand Down Expand Up @@ -316,9 +329,8 @@ local function PngSelector(button_size)
local buttons_count = #FILTERED_PNG
local window_visible_x2 = ({ imgui.GetWindowPos(ctx) })[1] +
({ imgui.GetWindowContentRegionMax(ctx) })[1]
imgui.PushStyleColor(ctx, imgui.Col_Button, COLORS["win_bg"])

if imgui.BeginChild(ctx, "filtered_pngs_list", 0, 0) then
imgui.PushStyleColor(ctx, imgui.Col_Button, COLORS["win_bg"])
if imgui.BeginChild(ctx, "filtered_pngs_list", 0, 0) then
for n = 0, #FILTERED_PNG - 1 do
local image = FILTERED_PNG[n + 1].name
local stripped_name = FILTERED_PNG[n + 1].short_name
Expand All @@ -329,6 +341,7 @@ local function PngSelector(button_size)
end

if imgui.ImageButton(ctx, "##png_select", FILTERED_PNG[n + 1].img_obj, button_size, button_size, 0, 0, 1, 1) then
imgui.SetKeyboardFocusHere( ctx ,-1)
if #TRACKS > 0 then
r.Undo_BeginBlock2(nil)
for i = 1, #TRACKS do
Expand Down Expand Up @@ -394,7 +407,6 @@ end

local function Categories()
local item_spacing_x = imgui.GetStyleVar(ctx, imgui.StyleVar_ItemSpacing)
--local padding = imgui.GetStyleVar(ctx, imgui.StyleVar_FramePadding)
imgui.PushStyleVar(ctx, imgui.StyleVar_ItemSpacing, item_spacing_x, 20)
imgui.PushStyleColor(ctx, imgui.Col_ChildBg, COLORS["sidebar_col"])
if imgui.BeginChild(ctx, "PM_INSPECTOR", largest_name) then
Expand Down Expand Up @@ -544,8 +556,8 @@ local function main()
end

TRACKS = {}
for i = 1, r.CountSelectedTracks(nil) do
TRACKS[#TRACKS + 1] = r.GetSelectedTrack(nil, i - 1)
for i = 1, r.CountSelectedTracks2(nil, true) do
TRACKS[#TRACKS + 1] = r.GetSelectedTrack2(nil, i - 1, true)
end
imgui.PushStyleColor(ctx, imgui.Col_WindowBg, COLORS["win_bg"])
imgui.PushStyleColor(ctx, imgui.Col_TitleBgActive, COLORS["win_bg"])
Expand Down