fix(color): file picker may not work in Lua scripts (#6828)

This commit is contained in:
philmoz
2025-11-28 12:59:28 +10:00
committed by GitHub
parent b05fb4a439
commit 9414308ebd
4 changed files with 12 additions and 11 deletions
+6 -6
View File
@@ -92,8 +92,8 @@ class FileChoiceMenuToolbar : public MenuToolbar
protected: protected:
}; };
FileChoice::FileChoice(Window *parent, const rect_t &rect, std::string folder, FileChoice::FileChoice(Window *parent, const rect_t &rect, const std::string folder,
const char *extension, int maxlen, const std::string extension, int maxlen,
std::function<std::string()> getValue, std::function<std::string()> getValue,
std::function<void(std::string)> setValue, std::function<void(std::string)> setValue,
bool stripExtension, const char *title) : bool stripExtension, const char *title) :
@@ -101,7 +101,7 @@ FileChoice::FileChoice(Window *parent, const rect_t &rect, std::string folder,
parent, rect, 0, 0, [=]() { return selectedIdx; }, parent, rect, 0, 0, [=]() { return selectedIdx; },
[=](int val) { setValue(getString(val)); selectedIdx = val; }, title, CHOICE_TYPE_FOLDER), [=](int val) { setValue(getString(val)); selectedIdx = val; }, title, CHOICE_TYPE_FOLDER),
folder(std::move(folder)), folder(std::move(folder)),
extension(extension), extension(std::move(extension)),
maxlen(maxlen), maxlen(maxlen),
getValue(std::move(getValue)), getValue(std::move(getValue)),
stripExtension(stripExtension) stripExtension(stripExtension)
@@ -113,9 +113,9 @@ std::string FileChoice::getLabelText() { return getValue(); }
void FileChoice::loadFiles() void FileChoice::loadFiles()
{ {
if (loaded) return; if (filesLoaded) return;
loaded = true; filesLoaded = true;
FILINFO fno; FILINFO fno;
DIR dir; DIR dir;
@@ -137,7 +137,7 @@ void FileChoice::loadFiles()
fnExt = getFileExtension(fno.fname, 0, 0, &fnLen, &extLen); fnExt = getFileExtension(fno.fname, 0, 0, &fnLen, &extLen);
if (extension && (!fnExt || !isExtensionMatching(fnExt, extension))) if (!extension.empty() && (!fnExt || !isExtensionMatching(fnExt, extension.c_str())))
continue; // wrong extension continue; // wrong extension
if (stripExtension) fnLen -= extLen; if (stripExtension) fnLen -= extLen;
+4 -3
View File
@@ -24,8 +24,8 @@
class FileChoice : public Choice class FileChoice : public Choice
{ {
public: public:
FileChoice(Window* parent, const rect_t& rect, std::string folder, FileChoice(Window* parent, const rect_t& rect, const std::string folder,
const char* extension, int maxlen, const std::string extension, int maxlen,
std::function<std::string()> getValue, std::function<std::string()> getValue,
std::function<void(std::string)> setValue, std::function<void(std::string)> setValue,
bool stripExtension = false, bool stripExtension = false,
@@ -36,12 +36,13 @@ public:
#endif #endif
protected: protected:
bool filesLoaded = false;
int fileCount = 0; int fileCount = 0;
int selectedIdx = -1; int selectedIdx = -1;
Menu* menu = nullptr; Menu* menu = nullptr;
std::string getLabelText() override; std::string getLabelText() override;
std::string folder; std::string folder;
const char* extension; std::string extension;
int maxlen; int maxlen;
std::function<std::string()> getValue; std::function<std::string()> getValue;
bool stripExtension; bool stripExtension;
@@ -198,7 +198,7 @@ WidgetSettings::WidgetSettings(Widget* w) :
break; break;
case WidgetOption::File: case WidgetOption::File:
new FileChoice(line, rect_t{}, opt->fileSelectPath, nullptr, FF_MAX_LFN, new FileChoice(line, rect_t{}, opt->fileSelectPath, "", FF_MAX_LFN,
[=]() { [=]() {
return widgetData->getString(optIdx); return widgetData->getString(optIdx);
}, },
+1 -1
View File
@@ -2690,7 +2690,7 @@ void LvglWidgetFilePicker::build(lua_State *L)
if (h == LV_SIZE_CONTENT) h = 0; if (h == LV_SIZE_CONTENT) h = 0;
auto c = new FileChoice( auto c = new FileChoice(
lvglManager->getCurrentParent(), {x, y, w, h}, lvglManager->getCurrentParent(), {x, y, w, h},
folder.c_str(), extension.c_str(), maxLen, folder, extension, maxLen,
[=]() { return pcallGetStringVal(L, getFunction); }, [=]() { return pcallGetStringVal(L, getFunction); },
[=](std::string val) { pcallSetStringVal(L, setFunction, val.c_str()); }, [=](std::string val) { pcallSetStringVal(L, setFunction, val.c_str()); },
hideExtension, title.txt.c_str()); hideExtension, title.txt.c_str());