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

Release Track icon selector v1.05 #1438

Merged
merged 1 commit into from
Oct 1, 2024
Merged
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
30 changes: 22 additions & 8 deletions Tracks/reapertips_Track icon selector.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
-- @description Track icon selector
-- @author Reapertips & Sexan
-- @version 1.04
-- @version 1.05
-- @changelog
-- Push custom font before calculating longest folder name (fixes panel size getting werid widths because of wrong font)
-- - Add root level images to "root" table (needed to make sorting work)
-- - Sort categories alphabetically
-- - Account master track in selections
-- @provides
-- reatips_Track icon selector/*.png
-- reatips_Track icon selector/Menu.png
-- reatips_Track icon selector/Reset.png
-- @screenshot
-- https://i.imgur.com/bFK2HYk.png
-- https://i.imgur.com/MabMOW1.png
Expand Down Expand Up @@ -92,6 +95,7 @@ end
local OPEN_CATEGORIES = ALWAYS_SHOW_CATEGORIES

local MAIN_PNG_TBL = {
[-1] = { dir = "Root" },
[0] = { dir = "All Icons" }
}
local FILTERED_PNG
Expand Down Expand Up @@ -166,16 +170,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 @@ -394,7 +409,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 +558,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