Merge pull request #653 from jfrickmann/LuaWidgetErrorMsg

Show error message in Lua widgets instead of "disabled"
This commit is contained in:
Peter Feerick
2021-08-30 09:44:11 +10:00
committed by GitHub
3 changed files with 31 additions and 5 deletions
+25
View File
@@ -503,3 +503,28 @@ void drawHexNumber(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t val, LcdFla
x = dc->drawSizedText(x, y, &c, 1, flags);
}
}
void drawTextLines(BitmapBuffer * dc, coord_t left, coord_t top, coord_t width, coord_t height, char * str, LcdFlags flags)
{
coord_t x = left;
coord_t y = top;
coord_t line = getFontHeight(flags & 0xFFFF);
coord_t space = getTextWidth(" ", 1, flags);
coord_t word;
char * eos = str + strlen(str);
char * nxt;
while (str < eos) {
nxt = strstr(str, " ");
if (!nxt) nxt = eos;
word = getTextWidth(str, nxt - str, flags);
if (x + word > left + width && x > left) {
x = left;
y += line;
}
if (y + line > top + height) break;
dc->drawSizedText(x, y, str, nxt - str, flags);
str = nxt + 1;
x += word + space;
}
}
+1
View File
@@ -72,6 +72,7 @@ void drawGPSPosition(BitmapBuffer * dc, coord_t x, coord_t y, int32_t longitude,
void drawDate(BitmapBuffer * dc, coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags flags = 0);
void drawValueWithUnit(BitmapBuffer * dc, coord_t x, coord_t y, int val, uint8_t unit, LcdFlags flags = 0);
void drawHexNumber(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t val, LcdFlags flags = 0);
void drawTextLines(BitmapBuffer * dc, coord_t left, coord_t top, coord_t width, coord_t height, char * str, LcdFlags flags);
inline void drawChn(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t idx, LcdFlags flags)
{
drawSource(dc, x, y, MIXSRC_CH1 + idx - 1, flags);
+5 -5
View File
@@ -442,10 +442,11 @@ void LuaWidget::setErrorMessage(const char * funcName)
{
TRACE("Error in widget %s %s function: %s", factory->getName(), funcName, lua_tostring(lsWidgets, -1));
TRACE("Widget disabled");
size_t needed = snprintf(NULL, 0, "%s: %s", funcName, lua_tostring(lsWidgets, -1)) + 1;
errorMessage = (char *)malloc(needed);
size_t needed = snprintf(NULL, 0, "ERROR in %s: %s", funcName, lua_tostring(lsWidgets, -1)) + 1;
errorMessage = (char *)malloc(needed + 1);
if (errorMessage) {
snprintf(errorMessage, needed, "%s: %s", funcName, lua_tostring(lsWidgets, -1));
snprintf(errorMessage, needed, "ERROR in %s: %s", funcName, lua_tostring(lsWidgets, -1));
errorMessage[needed] = '\0';
}
}
@@ -459,8 +460,7 @@ void LuaWidget::refresh(BitmapBuffer* dc)
if (lsWidgets == 0) return;
if (errorMessage) {
lcdSetColor(RED);
dc->drawText(0, 0, "Disabled", FONT(XS) | CUSTOM_COLOR);
drawTextLines(dc, 0, 0, fullscreen ? LCD_W : rect.w, fullscreen ? LCD_H : rect.h, errorMessage, FONT(XS) | COLOR_THEME_WARNING);
return;
}