file picker improvements

center window in particular
This commit is contained in:
tildearrow 2025-09-28 03:03:09 -05:00
parent d81d8ff6aa
commit 2fc4288f9f
4 changed files with 52 additions and 17 deletions

View file

@ -355,7 +355,7 @@ void FurnaceGUI::drawDebug() {
);
if (ImGui::Button("Open")) {
newFilePicker->open("New File Picker","/home",fpFlags,
newFilePicker->open("New File Picker","/home","",fpFlags,
{_("songs"), "*.fur *.dmf *.mod *.s3m *.xm *.it *.fc13 *.fc14 *.smod *.fc *.ftm *.0cc *.dnm *.eft *.fub *.tfe",
_("instruments"), "*.fui *.dmp *.tfi *.vgi *.s3i *.sbi *.opli *.opni *.y12 *.bnk *.ff *.gyb *.opm *.wopl *.wopn",
_("audio"), "*.wav",

View file

@ -191,9 +191,9 @@ bool FurnaceGUIFileDialog::openLoad(String header, std::vector<String> filter, S
}
#endif
// TODO: hint, clickCallback, "FileDialog" ID
// TODO: clickCallback
newFilePicker->setHomeDir(getHomeDir());
newFilePicker->open(header+"##FileDialog",path,FP_FLAGS_MODAL|(allowMultiple?FP_FLAGS_MULTI_SELECT:0),filter);
newFilePicker->open(header+"##FileDialog",path,hint,FP_FLAGS_MODAL|(allowMultiple?FP_FLAGS_MULTI_SELECT:0),filter);
}
opened=true;
return true;
@ -276,9 +276,8 @@ bool FurnaceGUIFileDialog::openSave(String header, std::vector<String> filter, S
} else {
hasError=false;
// TODO: hint, clickCallback, "FileDialog" ID
newFilePicker->setHomeDir(getHomeDir());
newFilePicker->open(header+"##FileDialog",path,FP_FLAGS_MODAL|FP_FLAGS_SAVE,filter);
newFilePicker->open(header+"##FileDialog",path,hint,FP_FLAGS_MODAL|FP_FLAGS_SAVE,filter);
}
opened=true;
return true;
@ -325,9 +324,8 @@ bool FurnaceGUIFileDialog::openSelectDir(String header, String path, double dpiS
}
#endif
// TODO: hint, "FileDialog" ID
newFilePicker->setHomeDir(getHomeDir());
newFilePicker->open(header+"##FileDialog",path,FP_FLAGS_MODAL|FP_FLAGS_DIR_SELECT,{});
newFilePicker->open(header+"##FileDialog",path,hint,FP_FLAGS_MODAL|FP_FLAGS_DIR_SELECT,{});
}
opened=true;
return true;
@ -457,7 +455,8 @@ bool FurnaceGUIFileDialog::render(const ImVec2& min, const ImVec2& max) {
return false;
#endif
} else {
return newFilePicker->draw();
newFilePicker->setSizeConstraints(min,max);
return newFilePicker->draw(ImGuiWindowFlags_NoCollapse|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollWithMouse);
}
}

View file

@ -26,6 +26,7 @@
#include "../ta-log.h"
#include <algorithm>
#include <chrono>
#include <imgui.h>
#ifdef _WIN32
#include <windows.h>
#include "../utfutils.h"
@ -369,6 +370,9 @@ void FurnaceFilePicker::readDirectory(String path) {
entries.clear();
chosenEntries.clear();
updateEntryName();
if (!entryNameHint.empty()) {
entryName=entryNameHint;
}
// start new file thread
this->path=normalizePath(path);
@ -548,8 +552,17 @@ bool FurnaceFilePicker::isPathAbsolute(const String& p) {
#endif
}
bool FurnaceFilePicker::draw() {
if (!isOpen) return false;
void FurnaceFilePicker::setSizeConstraints(const ImVec2& min, const ImVec2& max) {
minSize=min;
maxSize=max;
hasSizeConstraints=true;
}
bool FurnaceFilePicker::draw(ImGuiWindowFlags winFlags) {
if (!isOpen) {
hasSizeConstraints=false;
return false;
}
String newDir;
bool acknowledged=false;
@ -561,12 +574,28 @@ bool FurnaceFilePicker::draw() {
began=true;
} else if (isModal) {
ImGui::OpenPopup(windowName.c_str());
began=ImGui::BeginPopupModal(windowName.c_str(),NULL,ImGuiWindowFlags_NoSavedSettings);
if (hasSizeConstraints) ImGui::SetNextWindowSizeConstraints(minSize,maxSize);
began=ImGui::BeginPopupModal(windowName.c_str(),NULL,ImGuiWindowFlags_NoScrollbar|winFlags);
} else {
began=ImGui::Begin(windowName.c_str(),NULL,ImGuiWindowFlags_NoSavedSettings);
if (hasSizeConstraints) ImGui::SetNextWindowSizeConstraints(minSize,maxSize);
began=ImGui::Begin(windowName.c_str(),NULL,ImGuiWindowFlags_NoScrollbar|winFlags);
}
if (began) {
// center the window if it is unmovable
if (winFlags&ImGuiWindowFlags_NoMove) {
ImGui::SetWindowPos(ImVec2(
(ImGui::GetMainViewport()->Size.x-ImGui::GetWindowWidth())*0.5f,
(ImGui::GetMainViewport()->Size.y-ImGui::GetWindowHeight())*0.5f)
);
}
// enforce window constraints if necessary
if (hasSizeConstraints) {
if (ImGui::GetWindowSize().x<minSize.x || ImGui::GetWindowSize().y<minSize.y) {
ImGui::SetWindowSize(minSize,ImGuiCond_Always);
}
}
// header bars
if (ImGui::Button(ICON_FA_PLUS "##MakeDir")) {
mkdirError="";
@ -1116,6 +1145,8 @@ bool FurnaceFilePicker::draw() {
}
}
hasSizeConstraints=false;
if (!newDir.empty() || readDrives) {
// change directory
readDirectory(newDir);
@ -1127,7 +1158,7 @@ bool FurnaceFilePicker::isOpened() {
return isOpen;
}
bool FurnaceFilePicker::open(String name, String pa, int flags, const std::vector<String>& filter) {
bool FurnaceFilePicker::open(String name, String pa, String hint, int flags, const std::vector<String>& filter) {
if (isOpen) return false;
if (filter.size()&1) {
logE("invalid filter data! it should be an even-sized vector with even elements containing names and odd ones being the filters.");
@ -1151,6 +1182,7 @@ bool FurnaceFilePicker::open(String name, String pa, int flags, const std::vecto
readDirectory(pa);
windowName=name;
hint=entryNameHint;
isOpen=true;
return true;
}
@ -1222,6 +1254,7 @@ FurnaceFilePicker::FurnaceFilePicker():
noClose(false),
isModal(false),
isEmbed(false),
hasSizeConstraints(false),
scheduledSort(0),
curFilterType(0),
sortMode(FP_SORT_NAME),

View file

@ -101,10 +101,12 @@ class FurnaceFilePicker {
String failMessage;
String homeDir;
String entryName;
String entryNameHint;
ImGuiListClipper listClipper;
ImVec2 minSize, maxSize;
bool haveFiles, haveStat, stopReading, isOpen, isMobile, sortInvert, multiSelect;
bool confirmOverwrite, dirSelect, noClose, isModal, isEmbed;
int scheduledSort;
bool confirmOverwrite, dirSelect, noClose, isModal, isEmbed, hasSizeConstraints;
int scheduledSort, imguiFlags;
size_t curFilterType;
SortModes sortMode;
FilePickerStatus curStatus;
@ -135,10 +137,11 @@ class FurnaceFilePicker {
const String& getEntryName();
const std::vector<String>& getSelected();
void setMobile(bool val);
bool draw();
void setSizeConstraints(const ImVec2& min, const ImVec2& max);
bool draw(ImGuiWindowFlags winFlags=0);
bool isOpened();
void close();
bool open(String name, String path, int flags, const std::vector<String>& filter);
bool open(String name, String path, String hint, int flags, const std::vector<String>& filter);
void loadSettings(DivConfig& conf);
void saveSettings(DivConfig& conf);
void setTypeStyle(FileType type, ImVec4 color, String icon);