feat(color): add FILE type for widget options (#5605)
This commit is contained in:
@@ -3118,6 +3118,7 @@ LROT_BEGIN(etxcst, NULL, 0)
|
||||
LROT_NUMENTRY( SWITCH, ZoneOption::Switch )
|
||||
LROT_NUMENTRY( SLIDER, ZoneOption::Slider )
|
||||
LROT_NUMENTRY( CHOICE, ZoneOption::Choice )
|
||||
LROT_NUMENTRY( FILE, ZoneOption::File )
|
||||
LROT_NUMENTRY( MENU_HEADER_HEIGHT, COLOR2FLAGS(EdgeTxStyles::MENU_HEADER_HEIGHT) )
|
||||
|
||||
// Colors gui/colorlcd/colors.h
|
||||
|
||||
@@ -322,6 +322,7 @@ void LuaWidget::update()
|
||||
auto optVal = getOptionValue(i);
|
||||
switch (option->type) {
|
||||
case ZoneOption::String:
|
||||
case ZoneOption::File:
|
||||
{
|
||||
char str[LEN_ZONE_OPTION_STRING + 1] = {0};
|
||||
strncpy(str, optVal->stringValue, LEN_ZONE_OPTION_STRING);
|
||||
|
||||
@@ -81,7 +81,7 @@ Widget* LuaWidgetFactory::create(Window* parent, const rect_t& rect,
|
||||
lua_newtable(lsWidgets);
|
||||
int i = 0;
|
||||
for (const ZoneOption* option = options; option->name; option++, i++) {
|
||||
if (option->type == ZoneOption::String) {
|
||||
if (option->type == ZoneOption::String || option->type == ZoneOption::File) {
|
||||
lua_pushstring(lsWidgets, option->name);
|
||||
// Zero-terminated string for Lua
|
||||
char str[LEN_ZONE_OPTION_STRING + 1] = {0};
|
||||
|
||||
+14
-20
@@ -134,21 +134,18 @@ ZoneOption *createOptionsArray(int reference, uint8_t maxOptions)
|
||||
luaL_checktype(lsWidgets, -2, LUA_TNUMBER); // key is number
|
||||
switch (field) {
|
||||
case 0:
|
||||
luaL_checktype(lsWidgets, -1, LUA_TSTRING); // value is string
|
||||
option->name = lua_tostring(lsWidgets, -1);
|
||||
option->name = luaL_checkstring(lsWidgets, -1);
|
||||
option->displayName = nullptr;
|
||||
// TRACE("name = %s", option->name);
|
||||
break;
|
||||
case 1:
|
||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||
option->type = (ZoneOption::Type)lua_tointeger(lsWidgets, -1);
|
||||
option->type = (ZoneOption::Type)luaL_checkinteger(lsWidgets, -1);
|
||||
option->deflt.unsignedValue = 0;
|
||||
// set some sensible defaults
|
||||
if (option->type == ZoneOption::Integer) {
|
||||
// set some sensible defaults
|
||||
option->min.signedValue = -100;
|
||||
option->max.signedValue = 100;
|
||||
} else if (option->type == ZoneOption::Switch) {
|
||||
// set some sensible defaults
|
||||
option->min.signedValue = SWSRC_FIRST;
|
||||
option->max.signedValue = SWSRC_LAST;
|
||||
} else if (option->type == ZoneOption::Timer) {
|
||||
@@ -157,7 +154,7 @@ ZoneOption *createOptionsArray(int reference, uint8_t maxOptions)
|
||||
} else if (option->type == ZoneOption::TextSize) {
|
||||
option->min.unsignedValue = FONT_STD_INDEX;
|
||||
option->max.unsignedValue = FONTS_COUNT - 1;
|
||||
} else if (option->type == ZoneOption::String) {
|
||||
} else if (option->type == ZoneOption::String || option->type == ZoneOption::File) {
|
||||
option->deflt.stringValue[0] = 0;
|
||||
} else if (option->type == ZoneOption::Slider) {
|
||||
option->min.unsignedValue = 0;
|
||||
@@ -166,34 +163,31 @@ ZoneOption *createOptionsArray(int reference, uint8_t maxOptions)
|
||||
break;
|
||||
case 2:
|
||||
if (option->type == ZoneOption::Integer || option->type == ZoneOption::Switch) {
|
||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||
option->deflt.signedValue = lua_tointeger(lsWidgets, -1);
|
||||
option->deflt.signedValue = luaL_checkinteger(lsWidgets, -1);
|
||||
} else if (option->type == ZoneOption::Bool) {
|
||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||
option->deflt.boolValue = (lua_tounsigned(lsWidgets, -1) != 0);
|
||||
} else if (option->type == ZoneOption::String) {
|
||||
strncpy(option->deflt.stringValue, lua_tostring(lsWidgets, -1),
|
||||
option->deflt.boolValue = (luaL_checkunsigned(lsWidgets, -1) != 0);
|
||||
} else if (option->type == ZoneOption::String || option->type == ZoneOption::File) {
|
||||
strncpy(option->deflt.stringValue, luaL_checkstring(lsWidgets, -1),
|
||||
LEN_ZONE_OPTION_STRING);
|
||||
} else {
|
||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||
option->deflt.unsignedValue = lua_tounsigned(lsWidgets, -1);
|
||||
option->deflt.unsignedValue = luaL_checkunsigned(lsWidgets, -1);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (option->type == ZoneOption::Integer || option->type == ZoneOption::Switch || option->type == ZoneOption::Slider) {
|
||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||
option->min.signedValue = lua_tointeger(lsWidgets, -1);
|
||||
option->min.signedValue = luaL_checkinteger(lsWidgets, -1);
|
||||
} else if (option->type == ZoneOption::Choice) {
|
||||
luaL_checktype(lsWidgets, -1, LUA_TTABLE); // value is a table
|
||||
for (lua_pushnil(lsWidgets); lua_next(lsWidgets, -2); lua_pop(lsWidgets, 1)) {
|
||||
option->choiceValues.push_back(lua_tostring(lsWidgets, -1));
|
||||
option->choiceValues.push_back(luaL_checkstring(lsWidgets, -1));
|
||||
}
|
||||
} else if (option->type == ZoneOption::File) {
|
||||
option->fileSelectPath = luaL_checkstring(lsWidgets, -1);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (option->type == ZoneOption::Integer || option->type == ZoneOption::Switch || option->type == ZoneOption::Slider) {
|
||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||
option->max.signedValue = lua_tointeger(lsWidgets, -1);
|
||||
option->max.signedValue = luaL_checkinteger(lsWidgets, -1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user