feat(color): additions to LVGL for Lua scripts (#5179)

This commit is contained in:
philmoz
2024-07-01 09:07:18 +10:00
committed by GitHub
parent 15b0878a68
commit 4d29d5dbae
54 changed files with 653 additions and 404 deletions
+14 -28
View File
@@ -173,29 +173,13 @@ static void keyboardDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
}
}
static void copy_ts_to_indev_data(const TouchState &st, lv_indev_data_t *data)
{
data->point.x = st.x;
data->point.y = st.y;
}
static lv_indev_data_t touch_data_backup;
static void backup_touch_data(lv_indev_data_t* data)
{
memcpy(&touch_data_backup, data, sizeof(lv_indev_data_t));
}
static void copy_touch_data_backup(lv_indev_data_t* data)
{
memcpy(data, &touch_data_backup, sizeof(lv_indev_data_t));
}
extern "C" void touchDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
{
#if defined(HARDWARE_TOUCH)
static lv_indev_data_t touch_data_backup;
if(!touchPanelEventOccured()) {
copy_touch_data_backup(data);
memcpy(data, &touch_data_backup, sizeof(lv_indev_data_t));
return;
}
@@ -218,14 +202,16 @@ extern "C" void touchDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
if(st.event == TE_NONE) {
TRACE("TE_NONE");
} else if(st.event == TE_DOWN || st.event == TE_SLIDE) {
TRACE("INDEV_STATE_PRESSED");
data->state = LV_INDEV_STATE_PRESSED;
copy_ts_to_indev_data(st, data);
} else {
TRACE("INDEV_STATE_RELEASED");
data->state = LV_INDEV_STATE_RELEASED;
copy_ts_to_indev_data(st, data);
if(st.event == TE_DOWN || st.event == TE_SLIDE) {
TRACE("TE_PRESSED");
data->state = LV_INDEV_STATE_PRESSED;
} else {
TRACE("TE_RELEASED");
data->state = LV_INDEV_STATE_RELEASED;
}
data->point.x = st.x;
data->point.y = st.y;
}
static bool onebeep=true; // TODO... This probably needs to be fixed in the driver it's sending two events
@@ -237,8 +223,8 @@ extern "C" void touchDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)
} else {
onebeep = true;
}
backup_touch_data(data);
memcpy(&touch_data_backup, data, sizeof(lv_indev_data_t));
#endif
}
+10 -7
View File
@@ -45,7 +45,7 @@ class ColorBar : public FormField
nullptr);
etx_std_style(lvobj, LV_PART_MAIN, PAD_ZERO);
etx_obj_add_style(lvobj, styles->border_color_edit, LV_PART_MAIN | LV_STATE_EDITED);
etx_obj_add_style(lvobj, styles->border_color[COLOR_THEME_EDIT_INDEX], LV_PART_MAIN | LV_STATE_EDITED);
etx_obj_add_style(lvobj, styles->outline_color_edit, LV_PART_MAIN | LV_STATE_EDITED);
}
@@ -289,7 +289,9 @@ class HSVColorType : public BarColorType
public:
HSVColorType(Window* parent, uint32_t color) : BarColorType(parent)
{
auto r = GET_RED(color), g = GET_GREEN(color), b = GET_BLUE(color);
auto rgb = COLOR_VAL(colorToRGB(color));
auto r = GET_RED(rgb), g = GET_GREEN(rgb), b = GET_BLUE(rgb);
float values[MAX_BARS];
RGBtoHSV(r, g, b, values[0], values[1], values[2]);
values[1] *= MAX_SATURATION; // convert the proper base
@@ -322,7 +324,7 @@ class HSVColorType : public BarColorType
uint32_t getRGB() override
{
return HSVtoRGB(bars[0]->value, bars[1]->value, bars[2]->value);
return COLOR2FLAGS(HSVtoRGB(bars[0]->value, bars[1]->value, bars[2]->value)) | RGB_FLAG;
}
protected:
@@ -335,7 +337,9 @@ class RGBColorType : public BarColorType
public:
RGBColorType(Window* parent, uint32_t color) : BarColorType(parent)
{
auto r = GET_RED(color), g = GET_GREEN(color), b = GET_BLUE(color);
auto rgb = COLOR_VAL(colorToRGB(color));
auto r = GET_RED(rgb), g = GET_GREEN(rgb), b = GET_BLUE(rgb);
float values[MAX_BARS];
values[0] = r;
values[1] = g;
@@ -354,7 +358,7 @@ class RGBColorType : public BarColorType
uint32_t getRGB() override
{
return RGB(bars[0]->value, bars[1]->value, bars[2]->value);
return RGB2FLAGS(bars[0]->value, bars[1]->value, bars[2]->value);
}
protected:
@@ -392,8 +396,7 @@ class ThemeColorType : public ColorType
auto btn = new TextButton(parent, rect_t{}, " ");
etx_bg_color(btn->getLvObj(), (LcdColorIndex)color);
btn->setPressHandler([=]() {
auto cv = lcdColorTable[color];
m_color = RGB(GET_RED(cv), GET_GREEN(cv), GET_BLUE(cv));
m_color = COLOR2FLAGS(color);
lv_event_send(parent->getParent()->getParent()->getLvObj(),
LV_EVENT_VALUE_CHANGED, nullptr);
return 0;
+1 -1
View File
@@ -78,7 +78,7 @@ static void color_swatch_constructor(const lv_obj_class_t *class_p,
{
etx_obj_add_style(obj, styles->bg_opacity_cover, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_thin, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color_black, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color[COLOR_BLACK_INDEX], LV_PART_MAIN);
}
static const lv_obj_class_t color_swatch_class = {
+8 -4
View File
@@ -48,7 +48,10 @@ class ColorEditorPopup : public BaseDialog
void updateColor(uint32_t c)
{
m_color = c;
uint8_t r = GET_RED(c), g = GET_GREEN(c), b = GET_BLUE(c);
auto rgb = COLOR_VAL(colorToRGB(m_color));
uint8_t r = GET_RED(rgb), g = GET_GREEN(rgb), b = GET_BLUE(rgb);
colorPad->setColor(r, g, b);
@@ -157,8 +160,8 @@ class ColorEditorPopup : public BaseDialog
};
ColorPicker::ColorPicker(Window* parent, const rect_t& rect,
std::function<uint16_t()> getValue,
std::function<void(uint16_t)> setValue) :
std::function<uint32_t()> getValue,
std::function<void(uint32_t)> setValue) :
Button(parent, {rect.x, rect.y, ColorEditorPopup::COLOR_PAD_WIDTH, ColorEditorPopup::COLOR_PAD_HEIGHT}),
setValue(std::move(setValue))
{
@@ -180,7 +183,8 @@ void ColorPicker::updateColor(uint32_t c)
{
color = c;
auto rgb = COLOR_VAL(colorToRGB(color));
auto lvcolor =
lv_color_make(GET_RED(color), GET_GREEN(color), GET_BLUE(color));
lv_color_make(GET_RED(rgb), GET_GREEN(rgb), GET_BLUE(rgb));
lv_obj_set_style_bg_color(lvobj, lvcolor, LV_PART_MAIN);
}
+3 -3
View File
@@ -26,14 +26,14 @@
class ColorPicker : public Button
{
uint32_t color;
std::function<void(uint16_t)> setValue;
std::function<void(uint32_t)> setValue;
void updateColor(uint32_t c);
public:
ColorPicker(Window* parent, const rect_t& rect,
std::function<uint16_t()> getValue,
std::function<void(uint16_t)> setValue = nullptr);
std::function<uint32_t()> getValue,
std::function<void(uint32_t)> setValue = nullptr);
void setColor(uint32_t c);
uint32_t getColor() const { return color; }
+10
View File
@@ -142,6 +142,16 @@ LcdColorIndex indexFromColor(uint32_t lcdFlags)
return CUSTOM_COLOR_INDEX;
}
// Return flags with RGB color value instead of indexed theme color
LcdFlags colorToRGB(LcdFlags colorFlags)
{
// RGB or indexed color?
if (colorFlags & RGB_FLAG)
return colorFlags;
return (colorFlags & 0xFFFF) | COLOR(COLOR_VAL(colorFlags)) | RGB_FLAG;
}
/**
* Helper function to translate a colorFlags value to a lv_color_t suitable
* for passing to an lv_obj function
+2
View File
@@ -139,4 +139,6 @@ extern uint32_t HSVtoRGB(float H, float S, float V);
extern void RGBtoHSV(uint8_t R, uint8_t G, uint8_t B, float& fH, float& fS,
float& fV);
LcdFlags colorToRGB(LcdFlags colorFlags);
lv_color_t makeLvColor(uint32_t colorFlags);
+2 -2
View File
@@ -153,7 +153,7 @@ Curve::Curve(Window* parent, const rect_t& rect,
etx_solid_bg(p, COLOR_THEME_PRIMARY2_INDEX);
etx_obj_add_style(p, styles->circle, LV_PART_MAIN);
etx_obj_add_style(p, styles->border, LV_PART_MAIN);
etx_obj_add_style(p, styles->border_color_dark, LV_PART_MAIN);
etx_obj_add_style(p, styles->border_color[COLOR_THEME_SECONDARY1_INDEX], LV_PART_MAIN);
lv_obj_set_size(p, 9, 9);
lv_obj_add_flag(p, LV_OBJ_FLAG_HIDDEN);
pointDots[i] = p;
@@ -174,7 +174,7 @@ Curve::Curve(Window* parent, const rect_t& rect,
etx_solid_bg(posPoint, COLOR_THEME_PRIMARY2_INDEX);
etx_obj_add_style(posPoint, styles->circle, LV_PART_MAIN);
etx_obj_add_style(posPoint, styles->border, LV_PART_MAIN);
etx_obj_add_style(posPoint, styles->border_color_active, LV_PART_MAIN);
etx_obj_add_style(posPoint, styles->border_color[COLOR_THEME_ACTIVE_INDEX], LV_PART_MAIN);
lv_obj_set_size(posPoint, 9, 9);
updatePosition();
+1 -1
View File
@@ -34,7 +34,7 @@ class ChannelFailsafeBargraph : public Window
Window(parent, rect), channel(channel)
{
etx_obj_add_style(lvobj, styles->border_thin, LV_PART_MAIN);
etx_obj_add_style(lvobj, styles->border_color_black, LV_PART_MAIN);
etx_obj_add_style(lvobj, styles->border_color[COLOR_BLACK_INDEX], LV_PART_MAIN);
outputsBar = new OutputChannelBar(this, {0, 1, width() - 2, ChannelBar::BAR_HEIGHT},
channel, false, false);
+4 -13
View File
@@ -25,9 +25,9 @@
const ZoneOption OPTIONS_LAYOUT_2x4[] = {
LAYOUT_COMMON_OPTIONS,
{"Panel1 background", ZoneOption::Bool, OPTION_VALUE_BOOL(true)},
{" Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(RGB(77, 112, 203))},
{" Color", ZoneOption::Color, RGB2FLAGS(77, 112, 203)},
{"Panel2 background", ZoneOption::Bool, OPTION_VALUE_BOOL(true)},
{" Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(RGB(77, 112, 203))},
{" Color", ZoneOption::Color, RGB2FLAGS(77, 112, 203)},
LAYOUT_OPTIONS_END};
class Layout2x4 : public Layout
@@ -92,17 +92,8 @@ class Layout2x4 : public Layout
lv_obj_add_flag(panel2, LV_OBJ_FLAG_HIDDEN);
}
LcdFlags color =
COLOR2FLAGS(getOptionValue(OPTION_PANEL1_COLOR)->unsignedValue);
if (color != panel1Color) {
panel1Color = color;
lv_obj_set_style_bg_color(panel1, makeLvColor(panel1Color), LV_PART_MAIN);
}
color = COLOR2FLAGS(getOptionValue(OPTION_PANEL2_COLOR)->unsignedValue);
if (color != panel2Color) {
panel2Color = color;
lv_obj_set_style_bg_color(panel2, makeLvColor(panel2Color), LV_PART_MAIN);
}
etx_bg_color_from_flags(panel1, getOptionValue(OPTION_PANEL1_COLOR)->unsignedValue);
etx_bg_color_from_flags(panel2, getOptionValue(OPTION_PANEL2_COLOR)->unsignedValue);
}
};
+17 -3
View File
@@ -25,9 +25,8 @@
#include "themes/etx_lv_theme.h"
#include "view_main.h"
PageHeader::PageHeader(Page* parent, EdgeTxIcon icon) :
Window(parent, {0, 0, LCD_W, EdgeTxStyles::MENU_HEADER_HEIGHT}),
icon(icon)
PageHeader::PageHeader(Window* parent, EdgeTxIcon icon) :
Window(parent, {0, 0, LCD_W, EdgeTxStyles::MENU_HEADER_HEIGHT})
{
setWindowFlag(NO_FOCUS | OPAQUE);
@@ -41,6 +40,21 @@ PageHeader::PageHeader(Page* parent, EdgeTxIcon icon) :
"", COLOR_THEME_PRIMARY2);
}
PageHeader::PageHeader(Window* parent, const char* iconFile) :
Window(parent, {0, 0, LCD_W, EdgeTxStyles::MENU_HEADER_HEIGHT})
{
setWindowFlag(NO_FOCUS | OPAQUE);
etx_solid_bg(lvobj, COLOR_THEME_SECONDARY1_INDEX);
new HeaderIcon(this, iconFile);
title = new StaticText(this,
{PAGE_TITLE_LEFT, PAGE_TITLE_TOP,
LCD_W - PAGE_TITLE_LEFT, EdgeTxStyles::PAGE_LINE_HEIGHT},
"", COLOR_THEME_PRIMARY2);
}
StaticText* PageHeader::setTitle2(std::string txt)
{
if (title2 == nullptr) {
+2 -2
View File
@@ -30,7 +30,8 @@ class Page;
class PageHeader : public Window
{
public:
PageHeader(Page* parent, EdgeTxIcon icon);
PageHeader(Window* parent, EdgeTxIcon icon);
PageHeader(Window* parent, const char* iconFile);
void setTitle(std::string txt) { title->setText(std::move(txt)); }
StaticText* setTitle2(std::string txt);
@@ -39,7 +40,6 @@ class PageHeader : public Window
static constexpr coord_t PAGE_TITLE_TOP = 2;
protected:
EdgeTxIcon icon;
StaticText* title;
StaticText* title2 = nullptr;
};
+1 -1
View File
@@ -126,7 +126,7 @@ static void bubble_popup_constructor(const lv_obj_class_t* class_p, lv_obj_t* ob
etx_obj_add_style(obj, bubble_popup, LV_PART_MAIN);
etx_bg_color(obj, COLOR_WHITE_INDEX, LV_PART_MAIN);
etx_txt_color(obj, COLOR_BLACK_INDEX, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color_black, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color[COLOR_BLACK_INDEX], LV_PART_MAIN);
}
static const lv_obj_class_t bubble_popup_class = {
@@ -34,7 +34,7 @@ static void etx_quick_button_constructor(const lv_obj_class_t* class_p,
etx_obj_add_style(obj, styles->pad_medium, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border, LV_PART_MAIN | LV_STATE_FOCUSED);
etx_obj_add_style(obj, styles->border_color_white,
etx_obj_add_style(obj, styles->border_color[COLOR_WHITE_INDEX],
LV_PART_MAIN | LV_STATE_FOCUSED);
}
@@ -60,7 +60,7 @@ static void etx_quick_icon_constructor(const lv_obj_class_t* class_p,
lv_obj_t* obj)
{
etx_obj_add_style(obj, styles->border, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color_white, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color[COLOR_WHITE_INDEX], LV_PART_MAIN);
etx_obj_add_style(obj, styles->outline, LV_PART_MAIN);
lv_obj_set_style_outline_color(obj, lv_color_black(), LV_PART_MAIN);
etx_obj_add_style(obj, styles->circle, LV_PART_MAIN);
+1 -1
View File
@@ -53,7 +53,7 @@ static void sf_enable_state_constructor(const lv_obj_class_t *class_p,
etx_obj_add_style(obj, sf_enable_state_style, LV_PART_MAIN);
etx_obj_add_style(obj, styles->outline_color_light, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color_dark, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_SECONDARY1_INDEX], LV_PART_MAIN);
etx_obj_add_style(obj, styles->bg_opacity_cover, LV_PART_MAIN);
etx_bg_color(obj, COLOR_THEME_ACTIVE_INDEX, LV_STATE_CHECKED);
}
+46 -62
View File
@@ -23,31 +23,7 @@
#include "translations.h"
#include "view_main.h"
constexpr uint32_t FIELD_PADDING_LEFT = 3;
constexpr coord_t POPUP_HEADER_HEIGHT = 30;
extern BitmapBuffer* luaLcdBuffer;
void LuaPopup::paint(BitmapBuffer* dc, uint8_t type, const char* text,
const char* info)
{
// popup background
dc->drawSolidFilledRect(0, 0, rect.w, POPUP_HEADER_HEIGHT, COLOR_THEME_FOCUS);
const char* title = text; // TODO: based on 'type'
// title bar
dc->drawText(FIELD_PADDING_LEFT,
(POPUP_HEADER_HEIGHT - getFontHeight(FONT(STD))) / 2, title,
COLOR_THEME_PRIMARY2);
dc->drawSolidFilledRect(0, POPUP_HEADER_HEIGHT, rect.w,
rect.h - POPUP_HEADER_HEIGHT, COLOR_THEME_SECONDARY3);
dc->drawText(FIELD_PADDING_LEFT, POPUP_HEADER_HEIGHT + EdgeTxStyles::PAGE_LINE_HEIGHT, info,
COLOR_THEME_SECONDARY1);
}
#include "dma2d.h"
void StandaloneLuaWindow::redraw_cb(lv_event_t* e)
{
@@ -59,26 +35,15 @@ void StandaloneLuaWindow::redraw_cb(lv_event_t* e)
if (widget) {
lv_draw_ctx_t* draw_ctx = lv_event_get_draw_ctx(e);
lv_area_t a, clipping, obj_coords;
lv_area_copy(&a, draw_ctx->buf_area);
lv_area_copy(&clipping, draw_ctx->clip_area);
lv_obj_get_coords(target, &obj_coords);
auto w = a.x2 - a.x1 + 1;
auto h = a.y2 - a.y1 + 1;
auto w = draw_ctx->buf_area->x2 - draw_ctx->buf_area->x1 + 1;
auto h = draw_ctx->buf_area->y2 - draw_ctx->buf_area->y1 + 1;
TRACE_WINDOWS("Draw %s", widget->getWindowDebugString().c_str());
BitmapBuffer buf = {BMP_RGB565, (uint16_t)w, (uint16_t)h,
(uint16_t*)draw_ctx->buf};
buf.setDrawCtx(draw_ctx);
buf.setOffset(obj_coords.x1 - a.x1, obj_coords.y1 - a.y1);
buf.setClippingRect(clipping.x1 - a.x1, clipping.x2 + 1 - a.x1,
clipping.y1 - a.y1, clipping.y2 + 1 - a.y1);
buf.drawBitmap(0 - buf.getOffsetX(), 0 - buf.getOffsetY(), &widget->lcdBuffer);
// Standalone script always redraws full screen
DMAWait();
DMACopyBitmap((uint16_t*)draw_ctx->buf, w, h, 0, 0,
widget->lcdBuffer->getData(), w, h, 0, 0, w, h);
}
}
@@ -87,9 +52,7 @@ StandaloneLuaWindow* StandaloneLuaWindow::_instance;
StandaloneLuaWindow::StandaloneLuaWindow(bool useLvgl) :
Window(MainWindow::instance(), {0, 0, LCD_W, LCD_H}),
useLvgl(useLvgl),
lcdBuffer(BMP_RGB565, LCD_W, LCD_H),
popup({50, 73, LCD_W - 100, LCD_H - 146})
useLvgl(useLvgl)
{
setWindowFlag(OPAQUE);
@@ -98,6 +61,7 @@ StandaloneLuaWindow::StandaloneLuaWindow(bool useLvgl) :
if (useLvglLayout()) {
padAll(PAD_ZERO);
etx_scrollbar(lvobj);
lv_obj_t* lbl = lv_label_create(lvobj);
lv_obj_set_pos(lbl, 0, 0);
lv_obj_set_size(lbl, LCD_W, LCD_H);
@@ -109,8 +73,10 @@ StandaloneLuaWindow::StandaloneLuaWindow(bool useLvgl) :
luaLvglManager = this;
} else {
lcdBuffer.clear();
lcdBuffer.drawText(LCD_W / 2, LCD_H / 2 - 20, STR_LOADING,
lcdBuffer = new BitmapBuffer(BMP_RGB565, LCD_W, LCD_H);
lcdBuffer->clear();
lcdBuffer->drawText(LCD_W / 2, LCD_H / 2 - 20, STR_LOADING,
FONT(L) | COLOR_THEME_PRIMARY2 | CENTERED);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
@@ -155,6 +121,9 @@ void StandaloneLuaWindow::deleteLater(bool detach, bool trash)
{
if (_deleted) return;
if (lcdBuffer) delete lcdBuffer;
lcdBuffer = nullptr;
luaLvglManager = nullptr;
Layer::pop(this);
@@ -176,14 +145,13 @@ void StandaloneLuaWindow::checkEvents()
Window::checkEvents();
// Set global LUA LCD buffer
luaLcdBuffer = &lcdBuffer;
luaLcdBuffer = lcdBuffer;
if (luaState != INTERPRETER_RELOAD_PERMANENT_SCRIPTS) {
// if LUA finished a full cycle,
// invalidate to display the screen buffer
bool useLvgl = useLvglLayout();
if (luaTask(true)) {
if (useLvgl && !hasError) {
if (useLvglLayout() && !hasError) {
// if LUA finished a full cycle,
// call update functions
PROTECT_LUA() {
if (!callRefs(lsScripts)) {
luaShowError();
@@ -193,6 +161,8 @@ void StandaloneLuaWindow::checkEvents()
}
UNPROTECT_LUA();
} else {
// if LUA finished a full cycle,
// invalidate to display the screen buffer
invalidate();
}
}
@@ -217,23 +187,37 @@ void StandaloneLuaWindow::onEvent(event_t evt)
LuaEventHandler::onEvent(evt);
}
void StandaloneLuaWindow::popupPaint(BitmapBuffer* dc, coord_t x, coord_t y, coord_t w, coord_t h,
const char* text, const char* info)
{
// popup background
dc->drawSolidFilledRect(x, y, w, POPUP_HEADER_HEIGHT, COLOR_THEME_FOCUS);
// title bar
dc->drawText(x + PAD_SMALL,
y + (POPUP_HEADER_HEIGHT - getFontHeight(FONT(STD))) / 2, text,
COLOR_THEME_PRIMARY2);
dc->drawSolidFilledRect(x, y + POPUP_HEADER_HEIGHT, w,
h - POPUP_HEADER_HEIGHT, COLOR_THEME_SECONDARY3);
dc->drawText(x + PAD_SMALL, y + POPUP_HEADER_HEIGHT + EdgeTxStyles::PAGE_LINE_HEIGHT, info,
COLOR_THEME_SECONDARY1);
}
bool StandaloneLuaWindow::displayPopup(event_t event, uint8_t type,
const char* text, const char* info,
bool& result)
{
if (useLvgl) return true;
// transparent background
lcdBuffer.drawFilledRect(0, 0, LCD_W, LCD_H, SOLID, COLOR_THEME_PRIMARY1,
OPACITY(5));
lcdBuffer->drawFilledRect(0, 0, LCD_W, LCD_H, SOLID, COLOR_THEME_PRIMARY1,
OPACITY(5));
// center pop-up
lcdBuffer.setOffset(LCD_W / 2 - popup.rect.w / 2,
LCD_H / 2 - popup.rect.h / 2);
popupPaint(lcdBuffer, POPUP_X, POPUP_Y, LCD_W - POPUP_X * 2, LCD_H - POPUP_Y * 2, text, info);
// draw it, then clear the offset
popup.paint(&lcdBuffer, type, text, info);
lcdBuffer.clearOffset();
TRACE("displayPopup(event = 0x%x)", event);
// TRACE("displayPopup(event = 0x%x)", event);
if (event == EVT_KEY_BREAK(KEY_EXIT)) {
result = false;
return true;
+7 -9
View File
@@ -26,13 +26,6 @@
#include "lua/lua_api.h"
#include "lua/lua_widget.h"
struct LuaPopup
{
rect_t rect;
LuaPopup(rect_t r) : rect(r) {}
void paint(BitmapBuffer* dc, uint8_t type, const char* text, const char* info);
};
class StandaloneLuaWindow : public Window, public LuaEventHandler, public LuaLvglManager
{
static StandaloneLuaWindow* _instance;
@@ -64,6 +57,10 @@ public:
bool isWidget() override { return false; }
static LAYOUT_VAL(POPUP_HEADER_HEIGHT, 30, 30);
static LAYOUT_VAL(POPUP_X, 50, 40);
static LAYOUT_VAL(POPUP_Y, 70, 110);
protected:
lv_obj_t* prevScreen = nullptr;
lv_obj_t* errorModal = nullptr;
@@ -73,10 +70,11 @@ protected:
bool useLvgl = false;
// GFX
BitmapBuffer lcdBuffer;
BitmapBuffer *lcdBuffer = nullptr;
// pop-ups
LuaPopup popup;
void popupPaint(BitmapBuffer* dc, coord_t x, coord_t y, coord_t w, coord_t h,
const char* text, const char* info);
// run LUA code
void runLua(event_t evt);
+13 -4
View File
@@ -509,6 +509,9 @@ HeaderDateTime::HeaderDateTime(Window* parent, coord_t x, coord_t y) :
etx_txt_color(time, COLOR_THEME_PRIMARY2_INDEX);
etx_font(time, FONT_XS_INDEX);
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICKABLE);
checkEvents();
}
@@ -534,10 +537,10 @@ void HeaderDateTime::checkEvents()
}
}
void HeaderDateTime::setColor(uint32_t color)
void HeaderDateTime::setColor(LcdFlags color)
{
lv_obj_set_style_text_color(date, makeLvColor(color), LV_PART_MAIN);
lv_obj_set_style_text_color(time, makeLvColor(color), LV_PART_MAIN);
etx_txt_color_from_flags(date, color);
etx_txt_color_from_flags(time, color);
}
HeaderIcon::HeaderIcon(Window* parent, EdgeTxIcon icon) :
@@ -546,13 +549,19 @@ HeaderIcon::HeaderIcon(Window* parent, EdgeTxIcon icon) :
(new StaticIcon(this, 0, 0, icon, COLOR_THEME_PRIMARY2))->center(width(), height());
}
HeaderIcon::HeaderIcon(Window* parent, const char* iconFile) :
StaticIcon(parent, 0, 0, ICON_TOPLEFT_BG, COLOR_THEME_FOCUS)
{
(new StaticIcon(this, 0, 0, iconFile, COLOR_THEME_PRIMARY2))->center(width(), height());
}
UsbSDConnected::UsbSDConnected() :
Window(MainWindow::instance(), {0, 0, LCD_W, LCD_H})
{
setWindowFlag(OPAQUE);
etx_solid_bg(lvobj, COLOR_THEME_PRIMARY1_INDEX);
dateTime = new HeaderDateTime(this, LCD_W - TopBar::HDR_DATE_XO, HDR_DATE_Y);
new HeaderDateTime(this, LCD_W - TopBar::HDR_DATE_XO, HDR_DATE_Y);
auto icon = new StaticIcon(this, 0, 0, ICON_USB_PLUGGED, COLOR_THEME_PRIMARY2);
lv_obj_center(icon->getLvObj());
+2 -4
View File
@@ -163,7 +163,7 @@ class HeaderDateTime : public Window
public:
HeaderDateTime(Window* parent, int x, int y);
void setColor(uint32_t color);
void setColor(LcdFlags color);
static LAYOUT_VAL(HDR_DATE_WIDTH, 45, 45)
static LAYOUT_VAL(HDR_DATE_HEIGHT, 12, 12)
@@ -181,6 +181,7 @@ class HeaderIcon : public StaticIcon
{
public:
HeaderIcon(Window *parent, EdgeTxIcon icon);
HeaderIcon(Window *parent, const char* iconFile);
};
class UsbSDConnected : public Window
@@ -189,7 +190,4 @@ class UsbSDConnected : public Window
UsbSDConnected();
static LAYOUT_VAL(HDR_DATE_Y, 6, 6)
protected:
HeaderDateTime* dateTime = nullptr;
};
+85 -38
View File
@@ -234,17 +234,13 @@ EdgeTxStyles::EdgeTxStyles()
lv_style_init(&txt_color[i]);
lv_style_init(&img_color[i]);
lv_style_set_img_recolor_opa(&img_color[i], LV_OPA_COVER);
lv_style_init(&border_color[i]);
lv_style_init(&arc_color[i]);
}
lv_style_init(&border_color_dark);
lv_style_init(&border_color_normal);
lv_style_init(&border_color_focus);
lv_style_init(&border_color_active);
lv_style_init(&border_color_edit);
lv_style_init(&outline_color_light);
lv_style_init(&outline_color_normal);
lv_style_init(&outline_color_focus);
lv_style_init(&outline_color_edit);
lv_style_init(&arc_color);
lv_style_init(&graph_border);
lv_style_init(&graph_dashed);
lv_style_init(&graph_line);
@@ -281,13 +277,6 @@ EdgeTxStyles::EdgeTxStyles()
lv_style_set_line_width(&div_line_white, 1);
lv_style_set_line_opa(&div_line_white, LV_OPA_COVER);
lv_style_init(&bg_color_grey);
lv_style_set_bg_color(&bg_color_grey, lv_palette_main(LV_PALETTE_GREY));
lv_style_init(&border_color_black);
lv_style_set_border_color(&border_color_black, lv_color_black());
lv_style_init(&border_color_white);
lv_style_set_border_color(&border_color_white, lv_color_white());
// Fonts
for (int i = FONT_STD_INDEX; i < FONTS_COUNT; i += 1) {
lv_style_init(&font[i]);
@@ -315,9 +304,12 @@ void EdgeTxStyles::applyColors()
// Always update colors in case theme changes
for (int i = 0; i < TOTAL_COLOR_COUNT; i += 1) {
lv_style_set_bg_color(&bg_color[i], makeLvColor(COLOR(i)));
lv_style_set_text_color(&txt_color[i], makeLvColor(COLOR(i)));
lv_style_set_img_recolor(&img_color[i], makeLvColor(COLOR(i)));
auto c = makeLvColor(COLOR(i));
lv_style_set_bg_color(&bg_color[i], c);
lv_style_set_text_color(&txt_color[i], c);
lv_style_set_img_recolor(&img_color[i], c);
lv_style_set_border_color(&border_color[i], c);
lv_style_set_arc_color(&arc_color[i], c);
}
lv_style_set_line_color(&graph_border, makeLvColor(COLOR_THEME_SECONDARY2));
@@ -330,17 +322,6 @@ void EdgeTxStyles::applyColors()
lv_style_set_line_color(&div_line_black, makeLvColor(COLOR_THEME_PRIMARY1));
lv_style_set_line_color(&div_line_white, makeLvColor(COLOR_THEME_PRIMARY2));
lv_style_set_border_color(&border_color_dark,
makeLvColor(COLOR_THEME_SECONDARY1));
lv_style_set_border_color(&border_color_normal,
makeLvColor(COLOR_THEME_SECONDARY2));
lv_style_set_border_color(&border_color_focus,
makeLvColor(COLOR_THEME_FOCUS));
lv_style_set_border_color(&border_color_active,
makeLvColor(COLOR_THEME_ACTIVE));
lv_style_set_border_color(&border_color_edit,
makeLvColor(COLOR_THEME_EDIT));
lv_style_set_outline_color(&outline_color_light,
makeLvColor(COLOR_THEME_SECONDARY3));
lv_style_set_outline_color(&outline_color_normal,
@@ -349,11 +330,9 @@ void EdgeTxStyles::applyColors()
makeLvColor(COLOR_THEME_FOCUS));
lv_style_set_outline_color(&outline_color_edit,
makeLvColor(COLOR_THEME_EDIT));
lv_style_set_arc_color(&arc_color, makeLvColor(COLOR_THEME_SECONDARY1));
}
static EdgeTxStyles *mainStyles = nullptr;
static EdgeTxStyles* mainStyles = nullptr;
static EdgeTxStyles* previewStyles = nullptr;
EdgeTxStyles* styles = nullptr;
@@ -401,24 +380,92 @@ void etx_font(lv_obj_t* obj, FontIndex fontIdx, lv_style_selector_t selector)
etx_obj_add_style(obj, styles->font[fontIdx], selector);
}
void etx_remove_bg_color(lv_obj_t* obj, lv_style_selector_t selector)
{
// Remove styles
for (int i = 0; i < TOTAL_COLOR_COUNT; i += 1)
lv_obj_remove_style(obj, &styles->bg_color[i], selector);
}
void etx_bg_color(lv_obj_t* obj, LcdColorIndex colorIdx,
lv_style_selector_t selector)
{
// Remove old style first
for (int i = 0; i < TOTAL_COLOR_COUNT; i += 1)
lv_obj_remove_style(obj, &styles->bg_color[i], selector);
etx_remove_bg_color(obj, selector);
etx_obj_add_style(obj, styles->bg_color[colorIdx], selector);
}
void etx_bg_color_from_flags(lv_obj_t* obj, LcdFlags colorFlags,
lv_style_selector_t selector)
{
if (colorFlags & RGB_FLAG) {
etx_remove_bg_color(obj, selector);
lv_obj_set_style_bg_color(obj,
makeLvColor(colorToRGB(colorFlags)), selector);
} else {
lv_obj_remove_local_style_prop(obj, LV_STYLE_BG_COLOR, selector);
etx_bg_color(obj, (LcdColorIndex)COLOR_VAL(colorFlags), selector);
}
}
void etx_remove_txt_color(lv_obj_t* obj, lv_style_selector_t selector)
{
// Remove styles
for (int i = 0; i < TOTAL_COLOR_COUNT; i += 1)
lv_obj_remove_style(obj, &styles->txt_color[i], selector);
}
void etx_txt_color(lv_obj_t* obj, LcdColorIndex colorIdx,
lv_style_selector_t selector)
{
// Remove old style first
for (int i = 0; i < TOTAL_COLOR_COUNT; i += 1)
lv_obj_remove_style(obj, &styles->txt_color[i], selector);
etx_remove_txt_color(obj, selector);
etx_obj_add_style(obj, styles->txt_color[colorIdx], selector);
}
void etx_txt_color_from_flags(lv_obj_t* obj, LcdFlags colorFlags,
lv_style_selector_t selector)
{
if (colorFlags & RGB_FLAG) {
etx_remove_txt_color(obj, selector);
lv_obj_set_style_text_color(obj,
makeLvColor(colorToRGB(colorFlags)), selector);
} else {
lv_obj_remove_local_style_prop(obj, LV_STYLE_TEXT_COLOR, selector);
etx_txt_color(obj, (LcdColorIndex)COLOR_VAL(colorFlags), selector);
}
}
void etx_remove_border_color(lv_obj_t* obj, lv_style_selector_t selector)
{
// Remove styles
for (int i = 0; i < TOTAL_COLOR_COUNT; i += 1)
lv_obj_remove_style(obj, &styles->border_color[i], selector);
}
void etx_border_color(lv_obj_t* obj, LcdColorIndex colorIdx,
lv_style_selector_t selector)
{
// Remove old style first
etx_remove_border_color(obj, selector);
etx_obj_add_style(obj, styles->border_color[colorIdx], selector);
}
void etx_remove_arc_color(lv_obj_t* obj, lv_style_selector_t selector)
{
// Remove styles
for (int i = 0; i < TOTAL_COLOR_COUNT; i += 1)
lv_obj_remove_style(obj, &styles->arc_color[i], selector);
}
void etx_arc_color(lv_obj_t* obj, LcdColorIndex colorIdx,
lv_style_selector_t selector)
{
// Remove old style first
etx_remove_arc_color(obj, selector);
etx_obj_add_style(obj, styles->arc_color[colorIdx], selector);
}
void etx_img_color(lv_obj_t* obj, LcdColorIndex colorIdx,
lv_style_selector_t selector)
{
@@ -433,7 +480,7 @@ void etx_std_ctrl_colors(lv_obj_t* obj, lv_style_selector_t selector)
etx_solid_bg(obj, COLOR_THEME_PRIMARY2_INDEX, selector);
etx_txt_color(obj, COLOR_THEME_SECONDARY1_INDEX, selector);
etx_obj_add_style(obj, styles->border_color_focus,
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_FOCUS_INDEX],
selector | LV_STATE_FOCUSED);
etx_bg_color(obj, COLOR_THEME_ACTIVE_INDEX, selector | LV_STATE_CHECKED);
@@ -446,7 +493,7 @@ void etx_std_ctrl_colors(lv_obj_t* obj, lv_style_selector_t selector)
void etx_std_settings(lv_obj_t* obj, lv_style_selector_t selector)
{
etx_obj_add_style(obj, styles->border, selector);
etx_obj_add_style(obj, styles->border_color_normal, selector);
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_SECONDARY2_INDEX], selector);
etx_obj_add_style(obj, styles->rounded, selector);
etx_obj_add_style(obj, styles->outline, selector | LV_STATE_FOCUSED);
@@ -500,7 +547,7 @@ void etx_std_style(lv_obj_t* obj, lv_style_selector_t selector,
void etx_scrollbar(lv_obj_t* obj)
{
etx_obj_add_style(obj, styles->scrollbar, LV_PART_SCROLLBAR);
etx_obj_add_style(obj, styles->bg_color_grey, LV_PART_SCROLLBAR);
etx_obj_add_style(obj, styles->bg_color[COLOR_GREY_INDEX], LV_PART_SCROLLBAR);
etx_obj_add_style(obj, styles->bg_opacity_cover,
LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_AUTO);
@@ -519,7 +566,7 @@ lv_obj_t* etx_create(const lv_obj_class_t* class_p, lv_obj_t* parent)
static void textarea_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
{
etx_obj_add_style(obj, styles->border, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color_normal, LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_SECONDARY2_INDEX], LV_PART_MAIN);
etx_obj_add_style(obj, styles->rounded, LV_PART_MAIN);
etx_std_ctrl_colors(obj, LV_PART_MAIN);
etx_obj_add_style(obj, styles->pad_textarea, LV_PART_MAIN);
+16 -9
View File
@@ -84,11 +84,25 @@ void etx_solid_bg(lv_obj_t* obj,
void etx_font(lv_obj_t* obj, FontIndex fontIdx,
lv_style_selector_t selector = LV_PART_MAIN);
void etx_remove_bg_color(lv_obj_t* obj, lv_style_selector_t selector = LV_PART_MAIN);
void etx_bg_color(lv_obj_t* obj, LcdColorIndex colorIdx,
lv_style_selector_t selector = LV_PART_MAIN);
void etx_bg_color_from_flags(lv_obj_t* obj, LcdFlags colorFlags,
lv_style_selector_t selector = LV_PART_MAIN);
void etx_remove_txt_color(lv_obj_t* obj, lv_style_selector_t selector = LV_PART_MAIN);
void etx_txt_color(lv_obj_t* obj, LcdColorIndex colorIdx,
lv_style_selector_t selector = LV_PART_MAIN);
void etx_txt_color_from_flags(lv_obj_t* obj, LcdFlags colorFlags,
lv_style_selector_t selector = LV_PART_MAIN);
void etx_remove_border_color(lv_obj_t* obj, lv_style_selector_t selector = LV_PART_MAIN);
void etx_border_color(lv_obj_t* obj, LcdColorIndex colorIdx,
lv_style_selector_t selector = LV_PART_MAIN);
void etx_remove_arc_color(lv_obj_t* obj, lv_style_selector_t selector = LV_PART_MAIN);
void etx_arc_color(lv_obj_t* obj, LcdColorIndex colorIdx,
lv_style_selector_t selector = LV_PART_MAIN);
void etx_img_color(lv_obj_t* obj, LcdColorIndex colorIdx,
lv_style_selector_t selector = LV_PART_MAIN);
@@ -122,19 +136,12 @@ class EdgeTxStyles
lv_style_t bg_color[TOTAL_COLOR_COUNT];
lv_style_t txt_color[TOTAL_COLOR_COUNT];
lv_style_t img_color[TOTAL_COLOR_COUNT];
lv_style_t border_color_dark;
lv_style_t border_color_normal;
lv_style_t border_color_black;
lv_style_t border_color_white;
lv_style_t border_color_focus;
lv_style_t border_color_active;
lv_style_t border_color_edit;
lv_style_t border_color[TOTAL_COLOR_COUNT];
lv_style_t arc_color[TOTAL_COLOR_COUNT];
lv_style_t outline_color_light;
lv_style_t outline_color_normal;
lv_style_t outline_color_focus;
lv_style_t outline_color_edit;
lv_style_t bg_color_grey;
lv_style_t arc_color;
lv_style_t graph_border;
lv_style_t graph_dashed;
lv_style_t graph_line;
+4 -7
View File
@@ -41,14 +41,11 @@ const std::string edgetx_url = "https://edgetx.org";
AboutUs::AboutUs() :
BaseDialog(MainWindow::instance(), STR_ABOUT_US, true, 220, LV_SIZE_CONTENT)
{
new StaticText(form, rect_t{0, 0, LV_PCT(100), LV_SIZE_CONTENT},
new StaticText(form, {0, 0, LV_PCT(100), LV_SIZE_CONTENT},
about_str + "\n" + copyright_str,
COLOR_THEME_SECONDARY1 | CENTERED);
auto qrBox = new Window(form, {0, 0, LV_PCT(100), 160});
auto qr = lv_qrcode_create(qrBox->getLvObj(), 150,
makeLvColor(COLOR_THEME_SECONDARY1),
makeLvColor(COLOR_THEME_SECONDARY3));
lv_qrcode_update(qr, edgetx_url.c_str(), edgetx_url.length());
lv_obj_center(qr);
auto qrBox = new Window(form, {0, 0, LV_PCT(100), QR_SZ});
auto qr = new QRCode(qrBox, 0, 0, QR_SZ, edgetx_url);
lv_obj_center(qr->getLvObj());
}
+2
View File
@@ -25,4 +25,6 @@ class AboutUs : public BaseDialog
{
public:
AboutUs();
static LAYOUT_VAL(QR_SZ, 150, 150)
};
-12
View File
@@ -262,24 +262,12 @@ void WidgetFactory::initPersistentData(Widget::PersistentData* persistentData,
for (const ZoneOption* option = options; option->name; option++, i++) {
TRACE("WidgetFactory::initPersistentData() setting option '%s'",
option->name);
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] =
// option->deflt;
auto optVal = &persistentData->options[i];
auto optType = zoneValueEnumFromType(option->type);
if (setDefault || optVal->type != optType) {
// reset to default value
memcpy(&optVal->value, &option->deflt, sizeof(ZoneOptionValue));
optVal->type = optType;
if (option->type == ZoneOption::Color) {
// If color value is in defaultColors - change it to current theme
// color
for (int i = 1; i < LCD_COLOR_COUNT - 1; i += 1) {
if (optVal->value.unsignedValue == defaultColors[i]) {
optVal->value.unsignedValue = lcdColorTable[i];
break;
}
}
}
}
}
}
+4 -5
View File
@@ -168,12 +168,11 @@ WidgetSettings::WidgetSettings(Window* parent, Widget* w) :
case ZoneOption::Color:
new ColorPicker(
line, rect_t{},
[=]() -> int { // getValue
return (int)widget->getOptionValue(optIdx)->unsignedValue;
[=]() -> uint32_t { // getValue
return widget->getOptionValue(optIdx)->unsignedValue;
},
[=](int newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue =
(uint32_t)newValue;
[=](uint32_t newValue) { // setValue
widget->getOptionValue(optIdx)->unsignedValue = newValue;
SET_DIRTY();
});
break;
+3 -10
View File
@@ -39,9 +39,6 @@ class GaugeWidget : public Widget
etx_obj_add_style(valueText->getLvObj(), styles->text_align_right,
LV_STATE_USER_1);
lv_style_init(&style);
lv_style_set_bg_opa(&style, LV_OPA_COVER);
auto box = lv_obj_create(lvobj);
lv_obj_set_pos(box, 0, 16);
lv_obj_set_size(box, lv_pct(100), 16);
@@ -51,7 +48,7 @@ class GaugeWidget : public Widget
bar = lv_obj_create(box);
lv_obj_set_pos(bar, 0, 0);
lv_obj_clear_flag(bar, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_style(bar, &style, LV_PART_MAIN);
etx_obj_add_style(bar, styles->bg_opacity_cover, LV_PART_MAIN);
update();
}
@@ -84,9 +81,7 @@ class GaugeWidget : public Widget
else
lv_obj_clear_state(valueText->getLvObj(), LV_STATE_USER_1);
lv_color_t color;
color.full = persistentData->options[3].value.unsignedValue;
lv_style_set_bg_color(&style, color);
etx_bg_color_from_flags(bar, persistentData->options[3].value.unsignedValue);
}
static const ZoneOption options[];
@@ -96,7 +91,6 @@ class GaugeWidget : public Widget
StaticText* sourceText = nullptr;
DynamicNumber<int16_t>* valueText = nullptr;
lv_obj_t* bar = nullptr;
lv_style_t style;
void checkEvents() override
{
@@ -118,8 +112,7 @@ const ZoneOption GaugeWidget::options[] = {
OPTION_VALUE_SIGNED(-RESX), OPTION_VALUE_SIGNED(RESX)},
{STR_MAX, ZoneOption::Integer, OPTION_VALUE_SIGNED(RESX),
OPTION_VALUE_SIGNED(-RESX), OPTION_VALUE_SIGNED(RESX)},
{STR_COLOR, ZoneOption::Color,
OPTION_VALUE_UNSIGNED(COLOR_THEME_WARNING >> 16)},
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_WARNING_INDEX)},
{nullptr, ZoneOption::Bool}};
BaseWidgetFactory<GaugeWidget> gaugeWidget("Gauge", GaugeWidget::options,
+5 -15
View File
@@ -34,9 +34,6 @@ class ModelBitmapWidget : public Widget
Widget::PersistentData* persistentData) :
Widget(factory, parent, rect, persistentData)
{
lv_style_init(&style);
lv_obj_add_style(lvobj, &style, LV_PART_MAIN);
etx_obj_add_style(lvobj, styles->bg_opacity_transparent, LV_PART_MAIN);
etx_obj_add_style(lvobj, styles->bg_opacity_cover,
LV_PART_MAIN | ETX_STATE_BG_FILL);
@@ -66,8 +63,6 @@ class ModelBitmapWidget : public Widget
void update() override
{
lv_color_t color;
isLarge = rect.h >= 96 && rect.w >= 120;
// get font size from options[1]
@@ -79,8 +74,7 @@ class ModelBitmapWidget : public Widget
etx_txt_color(label->getLvObj(), COLOR_THEME_SECONDARY1_INDEX,
LV_PART_MAIN);
} else {
color.full = persistentData->options[0].value.unsignedValue;
lv_obj_set_style_text_color(label->getLvObj(), color, LV_PART_MAIN);
etx_txt_color_from_flags(label->getLvObj(), persistentData->options[0].value.unsignedValue);
}
// Set label position
@@ -89,9 +83,8 @@ class ModelBitmapWidget : public Widget
else
lv_obj_set_pos(label->getLvObj(), 0, 0);
// get font color from options[3]
color.full = persistentData->options[3].value.unsignedValue;
lv_style_set_bg_color(&style, color);
// get fill color from options[3]
etx_bg_color_from_flags(lvobj, persistentData->options[3].value.unsignedValue);
// Set background opacity from options[2]
if (persistentData->options[2].value.boolValue)
@@ -127,7 +120,6 @@ class ModelBitmapWidget : public Widget
bool isLarge = false;
// std::unique_ptr<BitmapBuffer> buffer;
uint32_t deps_hash = 0;
lv_style_t style;
StaticText* label = nullptr;
StaticImage* image = nullptr;
@@ -135,12 +127,10 @@ class ModelBitmapWidget : public Widget
};
const ZoneOption ModelBitmapWidget::options[] = {
{STR_COLOR, ZoneOption::Color,
OPTION_VALUE_UNSIGNED(COLOR_THEME_SECONDARY1 >> 16)},
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX)},
{STR_SIZE, ZoneOption::TextSize, OPTION_VALUE_UNSIGNED(FONT_STD_INDEX)},
{STR_FILL_BACKGROUND, ZoneOption::Bool, OPTION_VALUE_BOOL(false)},
{STR_BG_COLOR, ZoneOption::Color,
OPTION_VALUE_UNSIGNED(COLOR_THEME_SECONDARY3 >> 16)},
{STR_BG_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX)},
{STR_USE_THEME_COLOR, ZoneOption::Bool, OPTION_VALUE_BOOL(true)},
{nullptr, ZoneOption::Bool}};
+16 -19
View File
@@ -43,7 +43,7 @@ class ChannelValue : public Window
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICKABLE);
etx_obj_add_style(lvobj, styles->border_thin, LV_PART_MAIN);
etx_obj_add_style(lvobj, styles->border_color_black, LV_PART_MAIN);
etx_obj_add_style(lvobj, styles->border_color[COLOR_BLACK_INDEX], LV_PART_MAIN);
padAll(PAD_ZERO);
@@ -51,28 +51,30 @@ class ChannelValue : public Window
lv_style_set_width(&style, lv_pct(100));
lv_style_set_height(&style, lv_pct(100));
lv_color_t color;
color.full = txtColor >> 16u;
lv_style_set_text_color(&style, color);
color.full = barColor >> 16u;
lv_style_set_bg_color(&style, color);
// lv_color_t color;
// color.full = txtColor >> 16u;
// lv_style_set_text_color(&style, color);
// color.full = barColor >> 16u;
// lv_style_set_bg_color(&style, color);
bar = lv_obj_create(lvobj);
lv_obj_set_style_bg_opa(bar, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_add_style(bar, &style, LV_PART_MAIN);
lv_obj_clear_flag(bar, LV_OBJ_FLAG_CLICKABLE);
lv_obj_set_size(bar, 0, ROW_HEIGHT - 1);
etx_bg_color_from_flags(bar, barColor);
valueLabel = lv_label_create(lvobj);
etx_font(valueLabel, FONT_XS_INDEX);
etx_obj_add_style(valueLabel, styles->text_align_right, LV_PART_MAIN);
etx_txt_color_from_flags(valueLabel, txtColor);
lv_obj_add_style(valueLabel, &style, LV_PART_MAIN);
lv_label_set_text(valueLabel, "");
chanLabel = lv_label_create(lvobj);
etx_font(chanLabel, FONT_XS_INDEX);
etx_obj_add_style(chanLabel, styles->text_align_left, LV_PART_MAIN);
lv_obj_add_style(chanLabel, &style, LV_PART_MAIN);
etx_txt_color_from_flags(chanLabel, txtColor);
lv_label_set_text(chanLabel, "");
chanHasName = g_model.limitData[channel].name[0] != 0;
setChannel();
@@ -168,9 +170,7 @@ class OutputsWidget : public Widget
void update() override
{
// get background color from options[2]
lv_color_t color;
color.full = persistentData->options[2].value.unsignedValue;
lv_style_set_bg_color(&style, color);
etx_bg_color_from_flags(lvobj, persistentData->options[2].value.unsignedValue);
// Set background opacity from options[1]
if (persistentData->options[1].value.boolValue)
@@ -179,8 +179,8 @@ class OutputsWidget : public Widget
lv_obj_clear_state(lvobj, ETX_STATE_BG_FILL);
// Colors
txtColor = COLOR2FLAGS(persistentData->options[3].value.unsignedValue);
barColor = COLOR2FLAGS(persistentData->options[4].value.unsignedValue);
txtColor = persistentData->options[3].value.unsignedValue;
barColor = persistentData->options[4].value.unsignedValue;
// Setup channels
firstChan = persistentData->options[0].value.unsignedValue;
@@ -221,12 +221,9 @@ const ZoneOption OutputsWidget::options[] = {
{STR_FIRST_CHANNEL, ZoneOption::Integer, OPTION_VALUE_UNSIGNED(1),
OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(32)},
{STR_FILL_BACKGROUND, ZoneOption::Bool, OPTION_VALUE_BOOL(false)},
{STR_BG_COLOR, ZoneOption::Color,
OPTION_VALUE_UNSIGNED(COLOR_THEME_SECONDARY3 >> 16)},
{STR_TEXT_COLOR, ZoneOption::Color,
OPTION_VALUE_UNSIGNED(COLOR_THEME_PRIMARY1 >> 16)},
{STR_COLOR, ZoneOption::Color,
OPTION_VALUE_UNSIGNED(COLOR_THEME_SECONDARY1 >> 16)},
{STR_BG_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY3_INDEX)},
{STR_TEXT_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_PRIMARY1_INDEX)},
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX)},
{nullptr, ZoneOption::Bool}};
BaseWidgetFactory<OutputsWidget> outputsWidget("Outputs",
+8 -18
View File
@@ -107,17 +107,10 @@ class RadioInfoWidget : public TopBarWidget
void update() override
{
lv_color_t color;
// get colors from options
color.full = persistentData->options[2].value.unsignedValue;
lv_obj_set_style_bg_color(batteryFill, color, LV_PART_MAIN);
color.full = persistentData->options[1].value.unsignedValue;
lv_obj_set_style_bg_color(batteryFill, color, LV_PART_MAIN | LV_STATE_USER_1);
color.full = persistentData->options[0].value.unsignedValue;
lv_obj_set_style_bg_color(batteryFill, color, LV_PART_MAIN | LV_STATE_USER_2);
etx_bg_color_from_flags(batteryFill, persistentData->options[2].value.unsignedValue, LV_PART_MAIN);
etx_bg_color_from_flags(batteryFill, persistentData->options[1].value.unsignedValue, LV_STATE_USER_1);
etx_bg_color_from_flags(batteryFill, persistentData->options[0].value.unsignedValue, LV_STATE_USER_2);
}
void checkEvents() override
@@ -230,9 +223,9 @@ class RadioInfoWidget : public TopBarWidget
};
const ZoneOption RadioInfoWidget::options[] = {
{STR_LOW_BATT_COLOR, ZoneOption::Color, RGB(0xF4, 0x43, 0x36)},
{STR_MID_BATT_COLOR, ZoneOption::Color, RGB(0xFF, 0xC1, 0x07)},
{STR_HIGH_BATT_COLOR, ZoneOption::Color, RGB(0x4C, 0xAF, 0x50)},
{STR_LOW_BATT_COLOR, ZoneOption::Color, RGB2FLAGS(0xF4, 0x43, 0x36)},
{STR_MID_BATT_COLOR, ZoneOption::Color, RGB2FLAGS(0xFF, 0xC1, 0x07)},
{STR_HIGH_BATT_COLOR, ZoneOption::Color, RGB2FLAGS(0x4C, 0xAF, 0x50)},
{nullptr, ZoneOption::Bool}};
BaseWidgetFactory<RadioInfoWidget> RadioInfoWidget("Radio Info", RadioInfoWidget::options,
@@ -252,9 +245,7 @@ class DateTimeWidget : public TopBarWidget
void update() override
{
// get color from options
LcdFlags color =
COLOR2FLAGS(persistentData->options[0].value.unsignedValue);
dateTime->setColor(color);
dateTime->setColor(persistentData->options[0].value.unsignedValue);
}
HeaderDateTime* dateTime = nullptr;
@@ -268,8 +259,7 @@ class DateTimeWidget : public TopBarWidget
};
const ZoneOption DateTimeWidget::options[] = {
{STR_COLOR, ZoneOption::Color,
OPTION_VALUE_UNSIGNED(COLOR_THEME_PRIMARY2 >> 16)},
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX)},
{nullptr, ZoneOption::Bool}};
BaseWidgetFactory<DateTimeWidget> DateTimeWidget("Date Time",
+2 -5
View File
@@ -61,9 +61,7 @@ class TextWidget : public Widget
lv_label_set_text(label, persistentData->options[0].value.stringValue);
// get font color from options[1]
lv_color_t color;
color.full = persistentData->options[1].value.unsignedValue;
lv_style_set_text_color(&style, color);
etx_txt_color_from_flags(label, persistentData->options[1].value.unsignedValue);
// get font size from options[2]
lv_style_set_text_font(
&style, getFont(persistentData->options[2].value.unsignedValue << 8));
@@ -85,8 +83,7 @@ class TextWidget : public Widget
const ZoneOption TextWidget::options[] = {
{STR_TEXT, ZoneOption::String,
OPTION_VALUE_STRING(TEXT_WIDGET_DEFAULT_LABEL)},
{STR_COLOR, ZoneOption::Color,
OPTION_VALUE_UNSIGNED(COLOR_THEME_SECONDARY1 >> 16)},
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_SECONDARY1_INDEX)},
{STR_SIZE, ZoneOption::TextSize, OPTION_VALUE_UNSIGNED(0)},
{STR_SHADOW, ZoneOption::Bool, OPTION_VALUE_BOOL(false)},
{STR_ALIGNMENT, ZoneOption::Align, OPTION_VALUE_UNSIGNED(ALIGN_LEFT)},
+1 -1
View File
@@ -92,7 +92,7 @@ class TimerWidget : public Widget
lv_obj_set_style_arc_width(timerArc, TMR_ARC_W, LV_PART_MAIN);
lv_obj_set_style_arc_opa(timerArc, LV_OPA_COVER, LV_PART_INDICATOR);
lv_obj_set_style_arc_width(timerArc, TMR_ARC_W, LV_PART_INDICATOR);
etx_obj_add_style(timerArc, styles->arc_color, LV_PART_INDICATOR);
etx_obj_add_style(timerArc, styles->arc_color[COLOR_THEME_SECONDARY1_INDEX], LV_PART_INDICATOR);
lv_obj_add_flag(timerArc, LV_OBJ_FLAG_HIDDEN);
update();
+3 -6
View File
@@ -168,10 +168,8 @@ class ValueWidget : public Widget
mixsrc_t field = persistentData->options[0].value.unsignedValue;
// get color from options[1]
lv_color_t color;
color.full = persistentData->options[1].value.unsignedValue;
lv_style_set_text_color(&labelStyle, color);
lv_style_set_text_color(&valueStyle, color);
etx_txt_color_from_flags(label, persistentData->options[1].value.unsignedValue);
etx_txt_color_from_flags(value, persistentData->options[1].value.unsignedValue);
// get label alignment from options[3]
LcdFlags lblAlign = persistentData->options[3].value.unsignedValue;
@@ -260,8 +258,7 @@ class ValueWidget : public Widget
const ZoneOption ValueWidget::options[] = {
{STR_SOURCE, ZoneOption::Source, OPTION_VALUE_UNSIGNED(MIXSRC_FIRST_STICK)},
{STR_COLOR, ZoneOption::Color,
OPTION_VALUE_UNSIGNED(COLOR_THEME_PRIMARY2 >> 16)},
{STR_COLOR, ZoneOption::Color, COLOR2FLAGS(COLOR_THEME_PRIMARY2_INDEX)},
{STR_SHADOW, ZoneOption::Bool, OPTION_VALUE_BOOL(false)},
{STR_ALIGN_LABEL, ZoneOption::Align, OPTION_VALUE_UNSIGNED(ALIGN_LEFT)},
{STR_ALIGN_VALUE, ZoneOption::Align, OPTION_VALUE_UNSIGNED(ALIGN_LEFT)},
+1 -1
View File
@@ -54,7 +54,7 @@ SetupWidgetsPageSlot::SetupWidgetsPageSlot(Window* parent, const rect_t& rect,
});
etx_obj_add_style(lvobj, styles->border, LV_STATE_FOCUSED);
etx_obj_add_style(lvobj, styles->border_color_focus, LV_STATE_FOCUSED);
etx_obj_add_style(lvobj, styles->border_color[COLOR_THEME_FOCUS_INDEX], LV_STATE_FOCUSED);
lv_style_init(&borderStyle);
lv_style_set_line_width(&borderStyle, 2);