feat(color): additions to LVGL for Lua scripts (#5179)
This commit is contained in:
@@ -66,16 +66,6 @@ static int8_t getTextVerticalOffset(LcdFlags flags)
|
||||
return text_vertical_offset[font_index] - vcenter;
|
||||
}
|
||||
|
||||
// Return flags with RGB color value instead of indexed theme color
|
||||
LcdFlags flagsRGB(LcdFlags flags)
|
||||
{
|
||||
// RGB or indexed color?
|
||||
if (flags & RGB_FLAG)
|
||||
return flags;
|
||||
else
|
||||
return (flags & 0xFFFF) | COLOR(COLOR_VAL(flags)) | RGB_FLAG;
|
||||
}
|
||||
|
||||
/*luadoc
|
||||
@function lcd.refresh()
|
||||
|
||||
@@ -107,7 +97,7 @@ static int luaLcdClear(lua_State * L)
|
||||
{
|
||||
if (luaLcdAllowed && luaLcdBuffer) {
|
||||
LcdFlags flags = luaL_optunsigned(L, 1, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX));
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
luaLcdBuffer->clear(flags);
|
||||
}
|
||||
return 0;
|
||||
@@ -154,7 +144,7 @@ static int luaLcdDrawPoint(lua_State *L)
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
LcdFlags flags = luaL_optunsigned(L, 3, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
// drawPixel uses color value directly; hence COLOR_VAL again
|
||||
luaLcdBuffer->drawPixel(x, y, COLOR_VAL(flags));
|
||||
@@ -191,7 +181,7 @@ static int luaLcdDrawLine(lua_State *L)
|
||||
coord_t y2 = luaL_checkunsigned(L, 4);
|
||||
uint8_t pat = luaL_checkunsigned(L, 5);
|
||||
LcdFlags flags = luaL_optunsigned(L, 6, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
if (x1 > LCD_W || y1 > LCD_H || x2 > LCD_W || y2 > LCD_H)
|
||||
return 0;
|
||||
@@ -230,13 +220,13 @@ static void drawString(lua_State *L, const char * s, LcdFlags flags)
|
||||
|
||||
if (invers) {
|
||||
// Find inverse color or read from optional Lua argument
|
||||
LcdFlags color = flagsRGB(flags);
|
||||
LcdFlags color = colorToRGB(flags);
|
||||
LcdFlags invColor = luaL_optunsigned(L, 5, ~0u); // ~0 is impossible for color flag!
|
||||
if (invColor == ~0u) {
|
||||
RGB_SPLIT(COLOR_VAL(color), r, g, b);
|
||||
invColor = COLOR2FLAGS(RGB_JOIN(31 - r, 63 - g, 31 - b));
|
||||
} else
|
||||
invColor = flagsRGB(invColor);
|
||||
invColor = colorToRGB(invColor);
|
||||
flags = (flags & 0xFFFF) | invColor;
|
||||
|
||||
// Draw color box
|
||||
@@ -254,7 +244,7 @@ static void drawString(lua_State *L, const char * s, LcdFlags flags)
|
||||
return;
|
||||
if (flags & SHADOWED)
|
||||
luaLcdBuffer->drawText(x+1, y+1, s, flags & 0xFFFF); // force black
|
||||
flags = (flags & 0xFFFF) | flagsRGB(flags);
|
||||
flags = (flags & 0xFFFF) | colorToRGB(flags);
|
||||
}
|
||||
|
||||
luaLcdBuffer->drawText(x, y, s, flags);
|
||||
@@ -338,13 +328,13 @@ static int luaLcdDrawTextLines(lua_State *L)
|
||||
|
||||
if (invers) {
|
||||
// Find inverse color or read from optional Lua argument
|
||||
LcdFlags color = flagsRGB(flags);
|
||||
LcdFlags color = colorToRGB(flags);
|
||||
LcdFlags invColor = luaL_optunsigned(L, 7, ~0u); // ~0 is impossible for color flag!
|
||||
if (invColor == ~0u) {
|
||||
RGB_SPLIT(COLOR_VAL(color), r, g, b);
|
||||
invColor = COLOR2FLAGS(RGB_JOIN(31 - r, 63 - g, 31 - b));
|
||||
} else
|
||||
invColor = flagsRGB(invColor);
|
||||
invColor = colorToRGB(invColor);
|
||||
flags = (flags & 0xFFFF) | invColor;
|
||||
|
||||
// Draw color box
|
||||
@@ -354,7 +344,7 @@ static int luaLcdDrawTextLines(lua_State *L)
|
||||
return 0;
|
||||
if (flags & SHADOWED)
|
||||
luaLcdBuffer->drawTextLines(x+1, y+1, w, h, s, flags & 0xFFFF); // force black
|
||||
flags = (flags & 0xFFFF) | flagsRGB(flags);
|
||||
flags = (flags & 0xFFFF) | colorToRGB(flags);
|
||||
}
|
||||
|
||||
luaLcdBuffer->drawTextLines(x, y, w, h, s, flags);
|
||||
@@ -447,7 +437,7 @@ static int luaLcdDrawChannel(lua_State *L)
|
||||
}
|
||||
}
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
getvalue_t value = getValue(channel);
|
||||
luaLcdBuffer->drawSensorCustomValue(x, y, (channel-MIXSRC_FIRST_TELEM)/3, value, flags);
|
||||
|
||||
@@ -477,7 +467,7 @@ static int luaLcdDrawSwitch(lua_State *L)
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int s = luaL_checkinteger(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
luaLcdBuffer->drawSwitch(x, y, s, flags);
|
||||
|
||||
return 0;
|
||||
@@ -505,7 +495,7 @@ static int luaLcdDrawSource(lua_State *L)
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
int s = luaL_checkinteger(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
luaLcdBuffer->drawSource(x, y, s, flags);
|
||||
|
||||
return 0;
|
||||
@@ -759,7 +749,7 @@ static int luaLcdDrawBitmapPattern(lua_State *L)
|
||||
auto x = luaL_checkunsigned(L, 2);
|
||||
auto y = luaL_checkunsigned(L, 3);
|
||||
auto flags = luaL_optunsigned(L, 4, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
luaLcdBuffer->drawBitmapPattern(x, y, reinterpret_cast<const MaskBitmap*>(m), flags);
|
||||
}
|
||||
|
||||
@@ -798,7 +788,7 @@ static int luaLcdDrawBitmapPatternPie(lua_State *L)
|
||||
auto startAngle = luaL_checkinteger(L, 4);
|
||||
auto endAngle = luaL_checkinteger(L, 5);
|
||||
auto flags = luaL_optunsigned(L, 6, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
luaLcdBuffer->drawBitmapPatternPie(x, y, reinterpret_cast<const MaskBitmap*>(m), flags, startAngle, endAngle);
|
||||
}
|
||||
|
||||
@@ -834,7 +824,7 @@ static int luaLcdDrawRectangle(lua_State *L)
|
||||
int h = luaL_checkinteger(L, 4);
|
||||
|
||||
LcdFlags flags = luaL_optunsigned(L, 5, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
unsigned int t = luaL_optunsigned(L, 6, 1);
|
||||
uint8_t opacity = luaL_optunsigned(L, 7, 0) & 0x0F;
|
||||
|
||||
@@ -871,7 +861,7 @@ static int luaLcdDrawFilledRectangle(lua_State *L)
|
||||
int h = luaL_checkinteger(L, 4);
|
||||
|
||||
LcdFlags flags = luaL_optunsigned(L, 5, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
uint8_t opacity = luaL_optunsigned(L, 6, 0) & 0x0F;
|
||||
|
||||
luaLcdBuffer->drawFilledRect(x, y, w, h, SOLID, flags, opacity);
|
||||
@@ -906,7 +896,7 @@ static int luaLcdInvertRect(lua_State *L)
|
||||
int h = luaL_checkinteger(L, 4);
|
||||
|
||||
LcdFlags flags = luaL_optunsigned(L, 5, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->invertRect(x, y, w, h, flags);
|
||||
|
||||
@@ -944,7 +934,7 @@ static int luaLcdDrawGauge(lua_State *L)
|
||||
int num = luaL_checkinteger(L, 5);
|
||||
int den = luaL_checkinteger(L, 6);
|
||||
LcdFlags flags = luaL_optunsigned(L, 7, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawRect(x, y, w, h, 1, 0xff, flags);
|
||||
uint16_t len = limit((uint16_t)1, uint16_t(w*num/den), uint16_t(w));
|
||||
@@ -967,7 +957,7 @@ Please notice that changing theme colors affects not only other Lua widgets, but
|
||||
static int luaLcdSetColor(lua_State *L)
|
||||
{
|
||||
unsigned int index = COLOR_VAL(luaL_checkunsigned(L, 1));
|
||||
uint16_t color = COLOR_VAL(flagsRGB(luaL_checkunsigned(L, 2)));
|
||||
uint16_t color = COLOR_VAL(colorToRGB(luaL_checkunsigned(L, 2)));
|
||||
|
||||
if (index < LCD_COLOR_COUNT && lcdColorTable[index] != color) {
|
||||
lcdColorTable[index] = color;
|
||||
@@ -994,7 +984,7 @@ static int luaLcdGetColor(lua_State *L)
|
||||
{
|
||||
LcdFlags flags = luaL_checkunsigned(L, 1);
|
||||
if ((flags & RGB_FLAG) || (COLOR_VAL(flags) & 0xFF) < LCD_COLOR_COUNT)
|
||||
lua_pushunsigned(L, flagsRGB(flags) & (COLOR_MASK(~0u) | RGB_FLAG));
|
||||
lua_pushunsigned(L, colorToRGB(flags) & (COLOR_MASK(~0u) | RGB_FLAG));
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
@@ -1058,7 +1048,7 @@ static int luaLcdDrawCircle(lua_State *L)
|
||||
coord_t y = luaL_checkunsigned(L, 2);
|
||||
coord_t r = luaL_checkunsigned(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawCircle(x, y, r, flags);
|
||||
|
||||
@@ -1087,7 +1077,7 @@ static int luaLcdDrawFilledCircle(lua_State *L)
|
||||
coord_t y = luaL_checkunsigned(L, 2);
|
||||
coord_t r = luaL_checkunsigned(L, 3);
|
||||
LcdFlags flags = luaL_optunsigned(L, 4, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawFilledCircle(x, y, r, flags);
|
||||
|
||||
@@ -1117,7 +1107,7 @@ static int luaLcdDrawTriangle(lua_State *L)
|
||||
coord_t x3 = luaL_checkunsigned(L, 5);
|
||||
coord_t y3 = luaL_checkunsigned(L, 6);
|
||||
LcdFlags flags = luaL_optunsigned(L, 7, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawLine(x1, y1, x2, y2, SOLID, flags);
|
||||
luaLcdBuffer->drawLine(x2, y2, x3, y3, SOLID, flags);
|
||||
@@ -1149,7 +1139,7 @@ static int luaLcdDrawFilledTriangle(lua_State *L)
|
||||
coord_t x3 = luaL_checkunsigned(L, 5);
|
||||
coord_t y3 = luaL_checkunsigned(L, 6);
|
||||
LcdFlags flags = luaL_optunsigned(L, 7, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawFilledTriangle(x1, y1, x2, y2, x3, y3, flags);
|
||||
|
||||
@@ -1182,7 +1172,7 @@ static int luaLcdDrawArc(lua_State *L)
|
||||
int start = luaL_checkunsigned(L, 4);
|
||||
int end = luaL_checkunsigned(L, 5);
|
||||
LcdFlags flags = luaL_optunsigned(L, 6, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
if (r > 0)
|
||||
luaLcdBuffer->drawAnnulusSector(x, y, r - 1, r, start, end, flags);
|
||||
@@ -1216,7 +1206,7 @@ static int luaLcdDrawPie(lua_State *L)
|
||||
int start = luaL_checkunsigned(L, 4);
|
||||
int end = luaL_checkunsigned(L, 5);
|
||||
LcdFlags flags = luaL_optunsigned(L, 6, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
if (r > 0)
|
||||
luaLcdBuffer->drawAnnulusSector(x, y, 0, r, start, end, flags);
|
||||
@@ -1251,7 +1241,7 @@ static int luaLcdDrawAnnulus(lua_State *L)
|
||||
int start = luaL_checkunsigned(L, 5);
|
||||
int end = luaL_checkunsigned(L, 6);
|
||||
LcdFlags flags = luaL_optunsigned(L, 7, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
luaLcdBuffer->drawAnnulusSector(x, y, r1, r2, start, end, flags);
|
||||
|
||||
@@ -1288,7 +1278,7 @@ static int luaLcdDrawLineWithClipping(lua_State *L)
|
||||
coord_t ymax = luaL_checkunsigned(L, 8);
|
||||
uint8_t pat = luaL_checkunsigned(L, 9);
|
||||
LcdFlags flags = luaL_optunsigned(L, 10, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
// backup clipping rect
|
||||
coord_t dc_xmin; coord_t dc_xmax; coord_t dc_ymin; coord_t dc_ymax;
|
||||
@@ -1393,7 +1383,7 @@ static int luaLcdDrawHudRectangle(lua_State *L)
|
||||
coord_t ymin = luaL_checkunsigned(L, 5);
|
||||
coord_t ymax = luaL_checkunsigned(L, 6);
|
||||
LcdFlags flags = luaL_optunsigned(L, 7, 0);
|
||||
flags = flagsRGB(flags);
|
||||
flags = colorToRGB(flags);
|
||||
|
||||
drawHudRectangle(luaLcdBuffer, pitch, roll, xmin, xmax, ymin, ymax, flags);
|
||||
|
||||
|
||||
@@ -69,6 +69,11 @@ static int luaLvglImage(lua_State *L)
|
||||
return luaLvglObj(L, [=]() { return new LvglWidgetImage(); });
|
||||
}
|
||||
|
||||
static int luaLvglQRCode(lua_State *L)
|
||||
{
|
||||
return luaLvglObj(L, [=]() { return new LvglWidgetQRCode(); });
|
||||
}
|
||||
|
||||
static int luaLvglMeter(lua_State *L)
|
||||
{
|
||||
return luaLvglObj(L, [=]() { return new LvglWidgetMeter(); });
|
||||
@@ -217,6 +222,8 @@ static void buildLvgl(lua_State *L, int srcIndex, int refIndex)
|
||||
lvobj = new LvglWidgetArc();
|
||||
else if (strcasecmp(p.type, "image") == 0)
|
||||
lvobj = new LvglWidgetImage();
|
||||
else if (strcasecmp(p.type, "qrcode") == 0)
|
||||
lvobj = new LvglWidgetQRCode();
|
||||
else if (strcasecmp(p.type, "meter") == 0)
|
||||
lvobj = new LvglWidgetMeter();
|
||||
else if (!luaLvglManager->isWidget()) {
|
||||
@@ -232,6 +239,8 @@ static void buildLvgl(lua_State *L, int srcIndex, int refIndex)
|
||||
lvobj = new LvglWidgetChoice();
|
||||
else if (strcasecmp(p.type, "slider") == 0)
|
||||
lvobj = new LvglWidgetSlider();
|
||||
else if (strcasecmp(p.type, "page") == 0)
|
||||
lvobj = new LvglWidgetPage();
|
||||
}
|
||||
if (lvobj) {
|
||||
lvobj->getParams(L, -1);
|
||||
@@ -278,6 +287,7 @@ LROT_FUNCENTRY(rectangle, luaLvglRectangle)
|
||||
LROT_FUNCENTRY(circle, luaLvglCircle)
|
||||
LROT_FUNCENTRY(arc, luaLvglArc)
|
||||
LROT_FUNCENTRY(image, luaLvglImage)
|
||||
LROT_FUNCENTRY(qrcode, luaLvglQRCode)
|
||||
LROT_FUNCENTRY(meter, luaLvglMeter)
|
||||
LROT_FUNCENTRY(button, luaLvglButton)
|
||||
LROT_FUNCENTRY(toggle, luaLvglToggle)
|
||||
|
||||
@@ -897,7 +897,7 @@ static void luaLoadScripts(bool init, const char * filename = nullptr)
|
||||
StandaloneLuaWindow::setup(true);
|
||||
#endif
|
||||
luaError(lsScripts, sid.state);
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Skip the rest of the loop if we did not get a new script
|
||||
|
||||
@@ -71,8 +71,6 @@ extern LuaWidget* runningFS;
|
||||
class LuaLvglManager;
|
||||
extern LuaLvglManager* luaLvglManager;
|
||||
|
||||
LcdFlags flagsRGB(LcdFlags flags);
|
||||
|
||||
extern lua_State* lsWidgets;
|
||||
extern uint32_t luaExtraMemoryUsage;
|
||||
void luaInitThemesAndWidgets();
|
||||
|
||||
@@ -21,8 +21,10 @@
|
||||
|
||||
#include "lua_widget.h"
|
||||
#include "opentx.h"
|
||||
#include "page.h"
|
||||
#include "slider.h"
|
||||
#include "toggleswitch.h"
|
||||
#include "lua_event.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -200,7 +202,6 @@ void LvglWidgetObject::parseParam(lua_State *L, const char *key)
|
||||
getColorFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
} else {
|
||||
color = luaL_checkunsigned(L, -1);
|
||||
color = flagsRGB(color);
|
||||
}
|
||||
} else if (!strcmp(key, "visible")) {
|
||||
getVisibleFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
@@ -278,12 +279,17 @@ void LvglWidgetBorderedObject::setColor(LcdFlags color)
|
||||
{
|
||||
if (color != currentColor) {
|
||||
currentColor = color;
|
||||
if (filled)
|
||||
lv_obj_set_style_bg_color(window->getLvObj(),
|
||||
makeLvColor(flagsRGB(color)), LV_PART_MAIN);
|
||||
else
|
||||
lv_obj_set_style_border_color(window->getLvObj(),
|
||||
makeLvColor(flagsRGB(color)), LV_PART_MAIN);
|
||||
if (filled) {
|
||||
etx_bg_color_from_flags(window->getLvObj(), color);
|
||||
} else {
|
||||
if (color & RGB_FLAG) {
|
||||
etx_remove_border_color(window->getLvObj());
|
||||
lv_obj_set_style_border_color(window->getLvObj(),
|
||||
makeLvColor(colorToRGB(color)), LV_PART_MAIN);
|
||||
} else {
|
||||
etx_border_color(window->getLvObj(), (LcdColorIndex)COLOR_VAL(color));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,8 +413,13 @@ void LvglWidgetLabel::setColor(LcdFlags color)
|
||||
{
|
||||
if (color != currentColor) {
|
||||
currentColor = color;
|
||||
lv_obj_set_style_text_color(window->getLvObj(),
|
||||
makeLvColor(flagsRGB(color)), LV_PART_MAIN);
|
||||
if (color & RGB_FLAG) {
|
||||
etx_remove_txt_color(window->getLvObj());
|
||||
lv_obj_set_style_text_color(window->getLvObj(),
|
||||
makeLvColor(colorToRGB(color)), LV_PART_MAIN);
|
||||
} else {
|
||||
etx_txt_color(window->getLvObj(), (LcdColorIndex)COLOR_VAL(color));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,8 +499,13 @@ void LvglWidgetArc::setColor(LcdFlags color)
|
||||
{
|
||||
if (color != currentColor) {
|
||||
currentColor = color;
|
||||
lv_obj_set_style_arc_color(window->getLvObj(), makeLvColor(flagsRGB(color)),
|
||||
LV_PART_INDICATOR);
|
||||
if (color & RGB_FLAG) {
|
||||
etx_remove_arc_color(window->getLvObj());
|
||||
lv_obj_set_style_arc_color(window->getLvObj(), makeLvColor(colorToRGB(color)),
|
||||
LV_PART_INDICATOR);
|
||||
} else {
|
||||
etx_arc_color(window->getLvObj(), (LcdColorIndex)COLOR_VAL(color), LV_PART_INDICATOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,6 +581,24 @@ void LvglWidgetImage::build(lua_State *L)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void LvglWidgetQRCode::parseParam(lua_State *L, const char *key)
|
||||
{
|
||||
if (!strcmp(key, "data")) {
|
||||
data = luaL_checkstring(L, -1);
|
||||
} else if (!strcmp(key, "bgColor")) {
|
||||
bgColor = luaL_checkunsigned(L, -1);
|
||||
} else {
|
||||
LvglWidgetObject::parseParam(L, key);
|
||||
}
|
||||
}
|
||||
|
||||
void LvglWidgetQRCode::build(lua_State *L)
|
||||
{
|
||||
window = new QRCode(lvglManager->getCurrentParent(), x, y, w, data, colorToRGB(color), colorToRGB(bgColor));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class LvglWidgetScaleIndicator : public LvglWidgetObjectBase
|
||||
{
|
||||
public:
|
||||
@@ -606,7 +640,7 @@ class LvglWidgetScaleArc : public LvglWidgetScaleIndicator
|
||||
meter = parent;
|
||||
|
||||
indic =
|
||||
lv_meter_add_arc(meter, scale, w, makeLvColor(flagsRGB(color)), rmod);
|
||||
lv_meter_add_arc(meter, scale, w, makeLvColor(colorToRGB(color)), rmod);
|
||||
if (hasStart) lv_meter_set_indicator_start_value(meter, indic, startPos);
|
||||
if (hasEnd) lv_meter_set_indicator_end_value(meter, indic, endPos);
|
||||
}
|
||||
@@ -614,7 +648,7 @@ class LvglWidgetScaleArc : public LvglWidgetScaleIndicator
|
||||
protected:
|
||||
uint8_t w = 0;
|
||||
int8_t rmod = 0;
|
||||
LcdFlags color = COLOR_THEME_PRIMARY1;
|
||||
LcdFlags color = COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX);
|
||||
bool hasStart = false, hasEnd = false;
|
||||
int16_t startPos = 0, endPos = 0;
|
||||
|
||||
@@ -676,15 +710,16 @@ class LvglWidgetScaleLines : public LvglWidgetScaleIndicator
|
||||
meter = parent;
|
||||
|
||||
indic = lv_meter_add_scale_lines(
|
||||
meter, scale, makeLvColor(flagsRGB(startColor)),
|
||||
makeLvColor(flagsRGB(endColor)), localFade, wmod);
|
||||
meter, scale, makeLvColor(colorToRGB(startColor)),
|
||||
makeLvColor(colorToRGB(endColor)), localFade, wmod);
|
||||
if (hasStart) lv_meter_set_indicator_start_value(meter, indic, startPos);
|
||||
if (hasEnd) lv_meter_set_indicator_end_value(meter, indic, endPos);
|
||||
}
|
||||
|
||||
protected:
|
||||
int8_t wmod = 0;
|
||||
LcdFlags startColor = COLOR_THEME_PRIMARY1, endColor = COLOR_THEME_PRIMARY1;
|
||||
LcdFlags startColor = COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX);
|
||||
LcdFlags endColor = COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX);
|
||||
bool hasStart = false, hasEnd = false;
|
||||
int16_t startPos = 0, endPos = 0;
|
||||
bool localFade = false;
|
||||
@@ -741,13 +776,13 @@ class LvglWidgetScaleNeedle : public LvglWidgetScaleIndicator
|
||||
meter = parent;
|
||||
|
||||
indic = lv_meter_add_needle_line(meter, scale, w,
|
||||
makeLvColor(flagsRGB(color)), rmod);
|
||||
makeLvColor(colorToRGB(color)), rmod);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t w = 0;
|
||||
int8_t rmod = 0;
|
||||
LcdFlags color = COLOR_THEME_PRIMARY1;
|
||||
LcdFlags color = COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX);
|
||||
|
||||
int getPosFunction = 0;
|
||||
|
||||
@@ -792,11 +827,11 @@ class LvglWidgetMeterScale : public LvglWidgetObjectBase
|
||||
|
||||
if (ticks) {
|
||||
lv_meter_set_scale_ticks(meter, scale, ticks, tickWidth, tickLen,
|
||||
makeLvColor(flagsRGB(tickColor)));
|
||||
makeLvColor(colorToRGB(tickColor)));
|
||||
if (majorNth)
|
||||
lv_meter_set_scale_major_ticks(
|
||||
meter, scale, majorNth, majorWidth, majorLen,
|
||||
makeLvColor(flagsRGB(majorColor)), labelGap);
|
||||
makeLvColor(colorToRGB(majorColor)), labelGap);
|
||||
}
|
||||
|
||||
lv_meter_set_scale_range(meter, scale, scaleMin, scaleMax, scaleAngle,
|
||||
@@ -804,8 +839,7 @@ class LvglWidgetMeterScale : public LvglWidgetObjectBase
|
||||
|
||||
if (centerDotSize > 0) {
|
||||
lv_obj_set_style_size(meter, centerDotSize, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_bg_color(meter, makeLvColor(flagsRGB(centerDotColor)),
|
||||
LV_PART_INDICATOR);
|
||||
etx_bg_color_from_flags(meter, centerDotColor, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_bg_opa(meter, LV_OPA_COVER, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_radius(meter, LV_RADIUS_CIRCLE, LV_PART_INDICATOR);
|
||||
}
|
||||
@@ -823,9 +857,10 @@ class LvglWidgetMeterScale : public LvglWidgetObjectBase
|
||||
uint8_t ticks = 0, majorNth = 0;
|
||||
uint8_t tickWidth = 0, majorWidth = 0;
|
||||
uint8_t tickLen = 0, majorLen = 0;
|
||||
LcdFlags tickColor = COLOR_THEME_PRIMARY1, majorColor = COLOR_THEME_PRIMARY1;
|
||||
LcdFlags tickColor = COLOR2FLAGS(COLOR_THEME_PRIMARY1);
|
||||
LcdFlags majorColor = COLOR2FLAGS(COLOR_THEME_PRIMARY1);
|
||||
uint8_t labelGap = 0, centerDotSize = 0;
|
||||
LcdFlags centerDotColor = COLOR_THEME_PRIMARY1;
|
||||
LcdFlags centerDotColor = COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX);
|
||||
|
||||
void parseParam(lua_State *L, const char *key) override
|
||||
{
|
||||
@@ -952,6 +987,7 @@ void LvglWidgetTextButton::setText(const char *s)
|
||||
|
||||
void LvglWidgetTextButton::build(lua_State *L)
|
||||
{
|
||||
if (h == LV_SIZE_CONTENT) h = 0;
|
||||
window =
|
||||
new TextButton(lvglManager->getCurrentParent(), {x, y, w, h}, txt, [=]() {
|
||||
pcallSimpleFunc(L, pressFunction);
|
||||
@@ -1158,6 +1194,7 @@ void LvglWidgetChoice::clearRefs(lua_State *L)
|
||||
|
||||
void LvglWidgetChoice::build(lua_State *L)
|
||||
{
|
||||
if (h == LV_SIZE_CONTENT) h = 0;
|
||||
window = new Choice(
|
||||
lvglManager->getCurrentParent(), {x, y, w, h}, values, 0,
|
||||
values.size() - 1, [=]() { return pcallGetIntVal(L, getFunction) - 1; },
|
||||
@@ -1198,3 +1235,86 @@ void LvglWidgetSlider::build(lua_State *L)
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class WidgetPage : public NavWindow, public LuaEventHandler
|
||||
{
|
||||
public:
|
||||
WidgetPage(Window *parent, std::function<void()> backAction,
|
||||
std::string title, std::string subtitle, std::string iconFile) :
|
||||
NavWindow(parent, {0, 0, LCD_W, LCD_H}), backAction(std::move(backAction))
|
||||
{
|
||||
if (iconFile.empty())
|
||||
header = new PageHeader(this, ICON_EDGETX);
|
||||
else
|
||||
header = new PageHeader(this, iconFile.c_str());
|
||||
|
||||
body = new Window(
|
||||
this, {0, EdgeTxStyles::MENU_HEADER_HEIGHT, LCD_W, LCD_H - EdgeTxStyles::MENU_HEADER_HEIGHT});
|
||||
body->setWindowFlag(NO_FOCUS);
|
||||
|
||||
header->setTitle(title);
|
||||
header->setTitle2(subtitle);
|
||||
|
||||
etx_solid_bg(lvobj);
|
||||
lv_obj_set_style_max_height(body->getLvObj(), LCD_H - EdgeTxStyles::MENU_HEADER_HEIGHT,
|
||||
LV_PART_MAIN);
|
||||
etx_scrollbar(body->getLvObj());
|
||||
|
||||
body->padAll(PAD_ZERO);
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
addBackButton();
|
||||
#endif
|
||||
}
|
||||
|
||||
Window *getBody() { return body; }
|
||||
|
||||
protected:
|
||||
std::function<void()> backAction;
|
||||
PageHeader *header = nullptr;
|
||||
Window *body = nullptr;
|
||||
|
||||
bool bubbleEvents() override { return true; }
|
||||
|
||||
void onClicked() override { Keyboard::hide(false); LuaEventHandler::onClicked(); }
|
||||
|
||||
void onCancel() override { backAction(); }
|
||||
|
||||
void onEvent(event_t evt) override
|
||||
{
|
||||
LuaEventHandler::onEvent(evt);
|
||||
}
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
void LvglWidgetPage::parseParam(lua_State *L, const char *key)
|
||||
{
|
||||
if (!strcmp(key, "back")) {
|
||||
backActionFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
} else if (!strcmp(key, "title")) {
|
||||
title = luaL_checkstring(L, -1);
|
||||
} else if (!strcmp(key, "subtitle")) {
|
||||
subtitle = luaL_checkstring(L, -1);
|
||||
} else if (!strcmp(key, "icon")) {
|
||||
iconFile = luaL_checkstring(L, -1);
|
||||
} else {
|
||||
LvglWidgetObject::parseParam(L, key);
|
||||
}
|
||||
}
|
||||
|
||||
void LvglWidgetPage::clearRefs(lua_State *L)
|
||||
{
|
||||
clearRef(L, backActionFunction);
|
||||
LvglWidgetObject::clearRefs(L);
|
||||
}
|
||||
|
||||
void LvglWidgetPage::build(lua_State *L)
|
||||
{
|
||||
auto page = new WidgetPage(
|
||||
lvglManager->getCurrentParent(),
|
||||
[=]() { pcallSimpleFunc(L, backActionFunction); }, title, subtitle, iconFile);
|
||||
window = page->getBody();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -87,7 +87,7 @@ class LvglWidgetObject : public LvglWidgetObjectBase
|
||||
LcdFlags currentColor = -1;
|
||||
|
||||
coord_t x = 0, y = 0, w = LV_SIZE_CONTENT, h = LV_SIZE_CONTENT;
|
||||
LcdFlags color = COLOR_THEME_SECONDARY1;
|
||||
LcdFlags color = COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX);
|
||||
int getColorFunction = 0;
|
||||
int getVisibleFunction = 0;
|
||||
int getSizeFunction = 0;
|
||||
@@ -248,6 +248,22 @@ class LvglWidgetImage : public LvglWidgetObject
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class LvglWidgetQRCode : public LvglWidgetObject
|
||||
{
|
||||
public:
|
||||
LvglWidgetQRCode() : LvglWidgetObject() {}
|
||||
|
||||
void build(lua_State *L) override;
|
||||
|
||||
protected:
|
||||
std::string data;
|
||||
LcdFlags bgColor = COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX);
|
||||
|
||||
void parseParam(lua_State *L, const char *key) override;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class LvglWidgetMeterScale;
|
||||
|
||||
class LvglWidgetMeter : public LvglWidgetRoundObject
|
||||
@@ -403,3 +419,22 @@ class LvglWidgetSlider : public LvglWidgetObject
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class LvglWidgetPage : public LvglWidgetObject
|
||||
{
|
||||
public:
|
||||
LvglWidgetPage() : LvglWidgetObject() {}
|
||||
|
||||
void build(lua_State *L) override;
|
||||
void clearRefs(lua_State *L) override;
|
||||
|
||||
protected:
|
||||
int backActionFunction = 0;
|
||||
std::string title;
|
||||
std::string subtitle;
|
||||
std::string iconFile;
|
||||
|
||||
void parseParam(lua_State *L, const char *key) override;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -330,8 +330,8 @@ void LuaWidget::update()
|
||||
lua_pushstring(lsWidgets, &str[0]);
|
||||
lua_settable(lsWidgets, -3);
|
||||
} else if (option->type == ZoneOption::Color) {
|
||||
int32_t value = persistentData->options[i].value.signedValue;
|
||||
l_pushtableint(option->name, COLOR2FLAGS(value) | RGB_FLAG);
|
||||
int32_t value = persistentData->options[i].value.unsignedValue;
|
||||
l_pushtableint(option->name, value);
|
||||
} else {
|
||||
int32_t value = persistentData->options[i].value.signedValue;
|
||||
l_pushtableint(option->name, value);
|
||||
|
||||
@@ -96,8 +96,8 @@ Widget* LuaWidgetFactory::create(Window* parent, const rect_t& rect,
|
||||
lua_pushstring(lsWidgets, &str[0]);
|
||||
lua_settable(lsWidgets, -3);
|
||||
} else if (option->type == ZoneOption::Color) {
|
||||
int32_t value = persistentData->options[i].value.signedValue;
|
||||
l_pushtableint(option->name, COLOR2FLAGS(value) | RGB_FLAG);
|
||||
int32_t value = persistentData->options[i].value.unsignedValue;
|
||||
l_pushtableint(option->name, value);
|
||||
} else {
|
||||
int32_t value = persistentData->options[i].value.signedValue;
|
||||
l_pushtableint(option->name, value);
|
||||
|
||||
@@ -185,8 +185,7 @@ ZoneOption *createOptionsArray(int reference, uint8_t maxOptions)
|
||||
// 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)));
|
||||
option->deflt.unsignedValue = lua_tounsigned(lsWidgets, -1);
|
||||
// TRACE("default unsigned = %u", option->deflt.unsignedValue);
|
||||
} else if (option->type == ZoneOption::Bool) {
|
||||
luaL_checktype(lsWidgets, -1, LUA_TNUMBER); // value is number
|
||||
|
||||
Reference in New Issue
Block a user