Color options for Lua widget get translated to Lua color flags
To support new color encoding in Lua widgets
This commit is contained in:
@@ -54,7 +54,7 @@ static int8_t getTextVerticalOffset(LcdFlags flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return flags with RGB color value instead of indexed theme color
|
// Return flags with RGB color value instead of indexed theme color
|
||||||
static LcdFlags flagsRGB(LcdFlags flags)
|
LcdFlags flagsRGB(LcdFlags flags)
|
||||||
{
|
{
|
||||||
// RGB or indexed color?
|
// RGB or indexed color?
|
||||||
if (flags & RGB_FLAG)
|
if (flags & RGB_FLAG)
|
||||||
|
|||||||
@@ -39,3 +39,5 @@ constexpr int8_t text_vertical_offset[7] {2,2,0,2,3,3,7};
|
|||||||
|
|
||||||
extern bool luaLcdAllowed;
|
extern bool luaLcdAllowed;
|
||||||
extern BitmapBuffer * luaLcdBuffer;
|
extern BitmapBuffer * luaLcdBuffer;
|
||||||
|
|
||||||
|
LcdFlags flagsRGB(LcdFlags flags);
|
||||||
@@ -177,12 +177,16 @@ ZoneOption * createOptionsArray(int reference, uint8_t maxOptions)
|
|||||||
// TRACE("default signed = %d", option->deflt.signedValue);
|
// TRACE("default signed = %d", option->deflt.signedValue);
|
||||||
}
|
}
|
||||||
else if (option->type == ZoneOption::Source ||
|
else if (option->type == ZoneOption::Source ||
|
||||||
option->type == ZoneOption::TextSize ||
|
option->type == ZoneOption::TextSize) {
|
||||||
option->type == ZoneOption::Color) {
|
|
||||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||||
option->deflt.unsignedValue = lua_tounsigned(lsWidgets, -1);
|
option->deflt.unsignedValue = lua_tounsigned(lsWidgets, -1);
|
||||||
// TRACE("default unsigned = %u", option->deflt.unsignedValue);
|
// TRACE("default unsigned = %u", option->deflt.unsignedValue);
|
||||||
}
|
}
|
||||||
|
else if (option->type == ZoneOption::Color) {
|
||||||
|
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||||
|
option->deflt.unsignedValue = COLOR_VAL(flagsRGB(lua_tounsigned(lsWidgets, -1)));
|
||||||
|
// TRACE("default unsigned = %u", option->deflt.unsignedValue);
|
||||||
|
}
|
||||||
else if (option->type == ZoneOption::Bool) {
|
else if (option->type == ZoneOption::Bool) {
|
||||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||||
option->deflt.boolValue = (lua_tounsigned(lsWidgets, -1) != 0);
|
option->deflt.boolValue = (lua_tounsigned(lsWidgets, -1) != 0);
|
||||||
@@ -418,7 +422,11 @@ void LuaWidget::update()
|
|||||||
lua_newtable(lsWidgets);
|
lua_newtable(lsWidgets);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const ZoneOption * option = getOptions(); option->name; option++, i++) {
|
for (const ZoneOption * option = getOptions(); option->name; option++, i++) {
|
||||||
l_pushtableint(option->name, persistentData->options[i].value.signedValue);
|
int32_t value = persistentData->options[i].value.signedValue;
|
||||||
|
if (option->type == ZoneOption::Color)
|
||||||
|
l_pushtableint(option->name, COLOR2FLAGS(value) | RGB_FLAG);
|
||||||
|
else
|
||||||
|
l_pushtableint(option->name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lua_pcall(lsWidgets, 2, 0, 0) != 0) {
|
if (lua_pcall(lsWidgets, 2, 0, 0) != 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user