Как сделать список файлов в имгуи окне

Lill_Chich

Участник
Автор темы
73
5
Версия SA-MP
  1. Любая
у меня есть имгуи окно:
if threewindow.v then
        local xplayer,yplayer = 500,500
        imgui.SetNextWindowPos(imgui.ImVec2(xplayer,yplayer), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(382, 560), imgui.Cond.FirstUseEver)
        imgui.Begin('Player', threewindow, imgui.WindowFlags.NoResize)
            imgui.BeginChild('##spisok', imgui.ImVec2(350, 450), true)
                local activate = imgui.ImBool(false)
            imgui.EndChild()
            imgui.BeginChild('##button', imgui.ImVec2(350, 40), true)
            imgui.Button(u8'Включить эту песню')
            imgui.SameLine()
            imgui.Button(u8'Поставить на паузу')
            imgui.EndChild()
        imgui.End()
end

там где чайлд "spisok", нужно чтобы появлялись названия файлов с .mp3.
Как только там появляется название, нужно чтобы можно было его выбрать и работать с ним, тоесть
Если я нажму на название песни, то я с помощью кнопок imgui.Button(u8'Включить эту песню') и imgui.Button(u8'Поставить на паузу') мог выключить песню и включить.
Вроде понятно объяснил.
 
Решение
Lua:
local path = getWorkingDirectory()..'\\resource' -- путь к папке с мп3 файлами
function getFilesInPath(path, ftype)
    local Files, SearchHandle, File = {}, findFirstFile(path.."\\"..ftype)
    table.insert(Files, File)
    while File do File = findNextFile(SearchHandle) table.insert(Files, File) end
    return Files
end


-- frame
for _, file in ipairs(getFilesInPath(path, '*.mp3')) do
    if imgui.Button(file, imgui.ImVec2(150, 24)) then
        sampAddChatMessage('Выбран файл '..path..'\\'..file, -1)
    end
end

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,778
11,225
Lua:
local path = getWorkingDirectory()..'\\resource' -- путь к папке с мп3 файлами
function getFilesInPath(path, ftype)
    local Files, SearchHandle, File = {}, findFirstFile(path.."\\"..ftype)
    table.insert(Files, File)
    while File do File = findNextFile(SearchHandle) table.insert(Files, File) end
    return Files
end


-- frame
for _, file in ipairs(getFilesInPath(path, '*.mp3')) do
    if imgui.Button(file, imgui.ImVec2(150, 24)) then
        sampAddChatMessage('Выбран файл '..path..'\\'..file, -1)
    end
end
 
  • Нравится
Реакции: Lill_Chich