GUI: dynamic sample list buttons

only show those which fit
This commit is contained in:
tildearrow 2025-07-29 20:11:25 -05:00
parent 1b40577585
commit 4bd72574cf

View file

@ -922,11 +922,20 @@ void FurnaceGUI::drawSampleList(bool asChild) {
} }
if (began) { if (began) {
// hide buttons if there isn't enough space // hide buttons if there isn't enough space
// buttons and their space requirements:
// - new: 2
// - duplicate: 7
// - open: 3
// - save: 5
// - folder view: 8
// - move up: 9
// - move down: 9
// - preview: 6
// - delete: 4
float buttonSize=ImGui::GetStyle().FramePadding.x*2.0f+settings.iconSize*dpiScale+ImGui::GetStyle().ItemSpacing.x; float buttonSize=ImGui::GetStyle().FramePadding.x*2.0f+settings.iconSize*dpiScale+ImGui::GetStyle().ItemSpacing.x;
float buttonSpace=ImGui::GetContentRegionAvail().x/MAX(1.0f,buttonSize); float buttonSpace=ImGui::GetContentRegionAvail().x/MAX(1.0f,buttonSize);
logV("%f",buttonSpace); if (buttonSpace>=2.0f) {
// add // add
if (ImGui::Button(ICON_FA_FILE "##SampleAdd")) { if (ImGui::Button(ICON_FA_FILE "##SampleAdd")) {
doAction(GUI_ACTION_SAMPLE_LIST_ADD); doAction(GUI_ACTION_SAMPLE_LIST_ADD);
@ -935,7 +944,9 @@ void FurnaceGUI::drawSampleList(bool asChild) {
ImGui::SetTooltip(_("Add")); ImGui::SetTooltip(_("Add"));
} }
ImGui::SameLine(); ImGui::SameLine();
}
if (buttonSpace>=7.0f) {
// duplicate // duplicate
if (ImGui::Button(ICON_FA_FILES_O "##SampleClone")) { if (ImGui::Button(ICON_FA_FILES_O "##SampleClone")) {
doAction(GUI_ACTION_SAMPLE_LIST_DUPLICATE); doAction(GUI_ACTION_SAMPLE_LIST_DUPLICATE);
@ -944,7 +955,9 @@ void FurnaceGUI::drawSampleList(bool asChild) {
ImGui::SetTooltip(_("Duplicate")); ImGui::SetTooltip(_("Duplicate"));
} }
ImGui::SameLine(); ImGui::SameLine();
}
if (buttonSpace>=3.0f) {
// open // open
if (ImGui::Button(ICON_FA_FOLDER_OPEN "##SampleLoad")) { if (ImGui::Button(ICON_FA_FOLDER_OPEN "##SampleLoad")) {
doAction(GUI_ACTION_SAMPLE_LIST_OPEN); doAction(GUI_ACTION_SAMPLE_LIST_OPEN);
@ -970,7 +983,9 @@ void FurnaceGUI::drawSampleList(bool asChild) {
ImGui::EndPopup(); ImGui::EndPopup();
} }
ImGui::SameLine(); ImGui::SameLine();
}
if (buttonSpace>=5.0f) {
// save // save
if (ImGui::Button(ICON_FA_FLOPPY_O "##SampleSave")) { if (ImGui::Button(ICON_FA_FLOPPY_O "##SampleSave")) {
doAction(GUI_ACTION_SAMPLE_LIST_SAVE); doAction(GUI_ACTION_SAMPLE_LIST_SAVE);
@ -992,7 +1007,9 @@ void FurnaceGUI::drawSampleList(bool asChild) {
ImGui::EndPopup(); ImGui::EndPopup();
} }
ImGui::SameLine(); ImGui::SameLine();
}
if (buttonSpace>=8.0f) {
// dir mode // dir mode
pushToggleColors(sampleListDir); pushToggleColors(sampleListDir);
if (ImGui::Button(ICON_FA_SITEMAP "##SampleDirMode")) { if (ImGui::Button(ICON_FA_SITEMAP "##SampleDirMode")) {
@ -1002,8 +1019,11 @@ void FurnaceGUI::drawSampleList(bool asChild) {
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(_("Toggle folders/standard view")); ImGui::SetTooltip(_("Toggle folders/standard view"));
} }
if (!sampleListDir) {
ImGui::SameLine(); ImGui::SameLine();
}
if (buttonSpace>=(sampleListDir?8.0f:9.0f)) {
if (!sampleListDir) {
if (ImGui::Button(ICON_FA_ARROW_UP "##SampleUp")) { if (ImGui::Button(ICON_FA_ARROW_UP "##SampleUp")) {
doAction(GUI_ACTION_SAMPLE_LIST_MOVE_UP); doAction(GUI_ACTION_SAMPLE_LIST_MOVE_UP);
} }
@ -1018,7 +1038,6 @@ void FurnaceGUI::drawSampleList(bool asChild) {
ImGui::SetTooltip(_("Move down")); ImGui::SetTooltip(_("Move down"));
} }
} else { } else {
ImGui::SameLine();
if (ImGui::Button(ICON_FA_FOLDER "##SampleFolder")) { if (ImGui::Button(ICON_FA_FOLDER "##SampleFolder")) {
folderString=""; folderString="";
} }
@ -1040,6 +1059,9 @@ void FurnaceGUI::drawSampleList(bool asChild) {
} }
} }
ImGui::SameLine(); ImGui::SameLine();
}
if (buttonSpace>=6.0f) {
if (ImGui::Button(ICON_FA_VOLUME_UP "##PreviewSampleL")) { if (ImGui::Button(ICON_FA_VOLUME_UP "##PreviewSampleL")) {
doAction(GUI_ACTION_SAMPLE_LIST_PREVIEW); doAction(GUI_ACTION_SAMPLE_LIST_PREVIEW);
} }
@ -1050,6 +1072,9 @@ void FurnaceGUI::drawSampleList(bool asChild) {
doAction(GUI_ACTION_SAMPLE_LIST_STOP_PREVIEW); doAction(GUI_ACTION_SAMPLE_LIST_STOP_PREVIEW);
} }
ImGui::SameLine(); ImGui::SameLine();
}
if (buttonSpace>=4.0f) {
pushDestColor(); pushDestColor();
if (ImGui::Button(ICON_FA_TIMES "##SampleDelete")) { if (ImGui::Button(ICON_FA_TIMES "##SampleDelete")) {
doAction(GUI_ACTION_SAMPLE_LIST_DELETE); doAction(GUI_ACTION_SAMPLE_LIST_DELETE);
@ -1058,6 +1083,79 @@ void FurnaceGUI::drawSampleList(bool asChild) {
if (ImGui::IsItemHovered()) { if (ImGui::IsItemHovered()) {
ImGui::SetTooltip(_("Delete")); ImGui::SetTooltip(_("Delete"));
} }
if (buttonSpace<9.0f) {
ImGui::SameLine();
}
}
if (buttonSpace<(sampleListDir?8.0f:9.0f)) {
if (ImGui::Button(ICON_FA_ELLIPSIS_H "##SampleMore")) {
}
if (ImGui::BeginPopupContextItem("SampleListMore",ImGuiMouseButton_Left)) {
if (buttonSpace<2.0f) if (ImGui::MenuItem("add")) {
doAction(GUI_ACTION_SAMPLE_LIST_ADD);
}
if (buttonSpace<7.0f) if (ImGui::MenuItem("duplicate")) {
doAction(GUI_ACTION_SAMPLE_LIST_DUPLICATE);
}
if (buttonSpace<3.0f) {
if (ImGui::MenuItem("open...")) {
doAction(GUI_ACTION_SAMPLE_LIST_OPEN);
}
if (ImGui::MenuItem("replace...")) {
doAction((curSample>=0 && curSample<(int)e->song.sample.size())?GUI_ACTION_SAMPLE_LIST_OPEN_REPLACE:GUI_ACTION_SAMPLE_LIST_OPEN);
}
if (ImGui::MenuItem("import raw...")) {
doAction(GUI_ACTION_SAMPLE_LIST_OPEN_RAW);
}
if (ImGui::MenuItem("import raw (replace)...")) {
doAction((curSample>=0 && curSample<(int)e->song.sample.size())?GUI_ACTION_SAMPLE_LIST_OPEN_REPLACE_RAW:GUI_ACTION_SAMPLE_LIST_OPEN_RAW);
}
}
if (buttonSpace<5.0f) {
if (ImGui::MenuItem("save...")) {
doAction(GUI_ACTION_SAMPLE_LIST_SAVE);
}
if (ImGui::MenuItem("save raw...")) {
doAction(GUI_ACTION_SAMPLE_LIST_SAVE_RAW);
}
if (ImGui::MenuItem("save all...")) {
doAction(GUI_ACTION_SAMPLE_LIST_SAVE_ALL);
}
}
if (buttonSpace<8.0f) if (ImGui::MenuItem("folder view",NULL,sampleListDir)) {
doAction(GUI_ACTION_SAMPLE_LIST_DIR_VIEW);
}
if (buttonSpace<(sampleListDir?8.0f:9.0f)) {
if (!sampleListDir) {
if (ImGui::MenuItem("move up")) {
doAction(GUI_ACTION_SAMPLE_LIST_MOVE_UP);
}
if (ImGui::MenuItem("move down")) {
doAction(GUI_ACTION_SAMPLE_LIST_MOVE_DOWN);
}
} else {
if (ImGui::MenuItem("new folder")) {
showError("to be done...");
}
}
}
if (buttonSpace<6.0f) {
if (ImGui::MenuItem("preview")) {
doAction(GUI_ACTION_SAMPLE_LIST_PREVIEW);
}
if (ImGui::MenuItem("stop preview")) {
doAction(GUI_ACTION_SAMPLE_LIST_STOP_PREVIEW);
}
}
if (buttonSpace<4.0f) if (ImGui::MenuItem("delete")) {
doAction(GUI_ACTION_SAMPLE_LIST_DELETE);
}
ImGui::EndPopup();
}
}
ImGui::Separator(); ImGui::Separator();
if (ImGui::BeginTable("SampleListScroll",1,ImGuiTableFlags_ScrollY)) { if (ImGui::BeginTable("SampleListScroll",1,ImGuiTableFlags_ScrollY)) {
actualSampleList(); actualSampleList();