feat(color): add additional properties to the Lua LVGL arc object (#6062)
This commit is contained in:
@@ -395,7 +395,7 @@ void etx_bg_color_from_flags(lv_obj_t* obj, LcdFlags colorFlags,
|
|||||||
if (colorFlags & RGB_FLAG) {
|
if (colorFlags & RGB_FLAG) {
|
||||||
etx_remove_bg_color(obj, selector);
|
etx_remove_bg_color(obj, selector);
|
||||||
lv_obj_set_style_bg_color(obj,
|
lv_obj_set_style_bg_color(obj,
|
||||||
makeLvColor(colorToRGB(colorFlags)), selector);
|
makeLvColor(colorFlags), selector);
|
||||||
} else {
|
} else {
|
||||||
lv_obj_remove_local_style_prop(obj, LV_STYLE_BG_COLOR, selector);
|
lv_obj_remove_local_style_prop(obj, LV_STYLE_BG_COLOR, selector);
|
||||||
etx_bg_color(obj, (LcdColorIndex)COLOR_VAL(colorFlags), selector);
|
etx_bg_color(obj, (LcdColorIndex)COLOR_VAL(colorFlags), selector);
|
||||||
@@ -423,7 +423,7 @@ void etx_txt_color_from_flags(lv_obj_t* obj, LcdFlags colorFlags,
|
|||||||
if (colorFlags & RGB_FLAG) {
|
if (colorFlags & RGB_FLAG) {
|
||||||
etx_remove_txt_color(obj, selector);
|
etx_remove_txt_color(obj, selector);
|
||||||
lv_obj_set_style_text_color(obj,
|
lv_obj_set_style_text_color(obj,
|
||||||
makeLvColor(colorToRGB(colorFlags)), selector);
|
makeLvColor(colorFlags), selector);
|
||||||
} else {
|
} else {
|
||||||
lv_obj_remove_local_style_prop(obj, LV_STYLE_TEXT_COLOR, selector);
|
lv_obj_remove_local_style_prop(obj, LV_STYLE_TEXT_COLOR, selector);
|
||||||
etx_txt_color(obj, (LcdColorIndex)COLOR_VAL(colorFlags), selector);
|
etx_txt_color(obj, (LcdColorIndex)COLOR_VAL(colorFlags), selector);
|
||||||
@@ -460,6 +460,19 @@ void etx_arc_color(lv_obj_t* obj, LcdColorIndex colorIdx,
|
|||||||
etx_obj_add_style(obj, styles->arc_color[colorIdx], selector);
|
etx_obj_add_style(obj, styles->arc_color[colorIdx], selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void etx_arc_color_from_flags(lv_obj_t* obj, LcdFlags colorFlags,
|
||||||
|
lv_style_selector_t selector)
|
||||||
|
{
|
||||||
|
if (colorFlags & RGB_FLAG) {
|
||||||
|
etx_remove_arc_color(obj, selector);
|
||||||
|
lv_obj_set_style_arc_color(obj,
|
||||||
|
makeLvColor(colorFlags), selector);
|
||||||
|
} else {
|
||||||
|
lv_obj_remove_local_style_prop(obj, LV_STYLE_ARC_COLOR, selector);
|
||||||
|
etx_arc_color(obj, (LcdColorIndex)COLOR_VAL(colorFlags), selector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void etx_remove_line_color(lv_obj_t* obj, lv_style_selector_t selector)
|
void etx_remove_line_color(lv_obj_t* obj, lv_style_selector_t selector)
|
||||||
{
|
{
|
||||||
// Remove styles
|
// Remove styles
|
||||||
@@ -475,6 +488,19 @@ void etx_line_color(lv_obj_t* obj, LcdColorIndex colorIdx,
|
|||||||
etx_obj_add_style(obj, styles->line_color[colorIdx], selector);
|
etx_obj_add_style(obj, styles->line_color[colorIdx], selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void etx_line_color_from_flags(lv_obj_t* obj, LcdFlags colorFlags,
|
||||||
|
lv_style_selector_t selector)
|
||||||
|
{
|
||||||
|
if (colorFlags & RGB_FLAG) {
|
||||||
|
etx_remove_line_color(obj, selector);
|
||||||
|
lv_obj_set_style_line_color(obj,
|
||||||
|
makeLvColor(colorFlags), selector);
|
||||||
|
} else {
|
||||||
|
lv_obj_remove_local_style_prop(obj, LV_STYLE_LINE_COLOR, selector);
|
||||||
|
etx_line_color(obj, (LcdColorIndex)COLOR_VAL(colorFlags), selector);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void etx_remove_img_color(lv_obj_t* obj, lv_style_selector_t selector)
|
void etx_remove_img_color(lv_obj_t* obj, lv_style_selector_t selector)
|
||||||
{
|
{
|
||||||
// Remove styles
|
// Remove styles
|
||||||
|
|||||||
@@ -186,10 +186,14 @@ void etx_border_color(lv_obj_t* obj, LcdColorIndex colorIdx,
|
|||||||
void etx_remove_arc_color(lv_obj_t* obj, 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,
|
void etx_arc_color(lv_obj_t* obj, LcdColorIndex colorIdx,
|
||||||
lv_style_selector_t selector = LV_PART_MAIN);
|
lv_style_selector_t selector = LV_PART_MAIN);
|
||||||
|
void etx_arc_color_from_flags(lv_obj_t* obj, LcdFlags colorFlags,
|
||||||
|
lv_style_selector_t selector = LV_PART_MAIN);
|
||||||
|
|
||||||
void etx_remove_line_color(lv_obj_t* obj, lv_style_selector_t selector = LV_PART_MAIN);
|
void etx_remove_line_color(lv_obj_t* obj, lv_style_selector_t selector = LV_PART_MAIN);
|
||||||
void etx_line_color(lv_obj_t* obj, LcdColorIndex colorIdx,
|
void etx_line_color(lv_obj_t* obj, LcdColorIndex colorIdx,
|
||||||
lv_style_selector_t selector = LV_PART_MAIN);
|
lv_style_selector_t selector = LV_PART_MAIN);
|
||||||
|
void etx_line_color_from_flags(lv_obj_t* obj, LcdFlags colorFlags,
|
||||||
|
lv_style_selector_t selector = LV_PART_MAIN);
|
||||||
|
|
||||||
void etx_remove_img_color(lv_obj_t* obj, lv_style_selector_t selector = LV_PART_MAIN);
|
void etx_remove_img_color(lv_obj_t* obj, lv_style_selector_t selector = LV_PART_MAIN);
|
||||||
void etx_img_color(lv_obj_t* obj, LcdColorIndex colorIdx,
|
void etx_img_color(lv_obj_t* obj, LcdColorIndex colorIdx,
|
||||||
|
|||||||
@@ -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_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_opa(timerArc, LV_OPA_COVER, LV_PART_INDICATOR);
|
||||||
lv_obj_set_style_arc_width(timerArc, TMR_ARC_W, LV_PART_INDICATOR);
|
lv_obj_set_style_arc_width(timerArc, TMR_ARC_W, LV_PART_INDICATOR);
|
||||||
etx_obj_add_style(timerArc, styles->arc_color[COLOR_THEME_SECONDARY1_INDEX], LV_PART_INDICATOR);
|
etx_arc_color(timerArc, COLOR_THEME_SECONDARY1_INDEX, LV_PART_INDICATOR);
|
||||||
lv_obj_add_flag(timerArc, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_add_flag(timerArc, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|||||||
@@ -43,6 +43,37 @@ void LvglParamFuncOrValue::parse(lua_State *L, ParamType typ)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LvglParamFuncOrValue::changedColor(LcdFlags newFlags)
|
||||||
|
{
|
||||||
|
flags = newFlags;
|
||||||
|
if (flags != currVal) {
|
||||||
|
currVal = flags;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LvglParamFuncOrValue::changedText(const char* s)
|
||||||
|
{
|
||||||
|
txt = s;
|
||||||
|
uint32_t h = hash(txt, strlen(txt));
|
||||||
|
if (h != currVal) {
|
||||||
|
currVal = h;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LvglParamFuncOrValue::changedValue(uint32_t v)
|
||||||
|
{
|
||||||
|
value = v;
|
||||||
|
if (v != currVal) {
|
||||||
|
currVal = v;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int pcallcont (lua_State *L, int status, lua_KContext extra) {
|
static int pcallcont (lua_State *L, int status, lua_KContext extra) {
|
||||||
@@ -424,18 +455,6 @@ void LvglWidgetObjectBase::update(lua_State *L)
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LvglWidgetObjectBase::colorChanged(LcdFlags newColor)
|
|
||||||
{
|
|
||||||
color.flags = newColor;
|
|
||||||
LcdFlags c = color.flags;
|
|
||||||
if (!(c & RGB_FLAG))
|
|
||||||
c = COLOR(COLOR_VAL(c)) | RGB_FLAG; // Convert index to RGB
|
|
||||||
if (currentColor != c) {
|
|
||||||
currentColor = c;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void LvglSimpleWidgetObject::setPos(coord_t x, coord_t y)
|
void LvglSimpleWidgetObject::setPos(coord_t x, coord_t y)
|
||||||
@@ -506,25 +525,15 @@ void LvglWidgetLabel::clearRefs(lua_State *L)
|
|||||||
|
|
||||||
void LvglWidgetLabel::setText(const char *s)
|
void LvglWidgetLabel::setText(const char *s)
|
||||||
{
|
{
|
||||||
uint32_t h = hash(s, strlen(s));
|
if (lvobj && txt.changedText(s)) {
|
||||||
if (h != textHash) {
|
lv_label_set_text(lvobj, txt.txt);
|
||||||
txt.txt = s;
|
|
||||||
textHash = h;
|
|
||||||
if (lvobj) lv_label_set_text(lvobj, s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LvglWidgetLabel::setColor(LcdFlags newColor)
|
void LvglWidgetLabel::setColor(LcdFlags newColor)
|
||||||
{
|
{
|
||||||
if (lvobj && colorChanged(newColor)) {
|
if (lvobj && color.changedColor(newColor))
|
||||||
if (color.flags & RGB_FLAG) {
|
etx_txt_color_from_flags(lvobj, color.flags);
|
||||||
etx_remove_txt_color(lvobj);
|
|
||||||
lv_obj_set_style_text_color(lvobj, makeLvColor(color.flags), LV_PART_MAIN);
|
|
||||||
} else {
|
|
||||||
lv_obj_remove_local_style_prop(lvobj, LV_STYLE_TEXT_COLOR, LV_PART_MAIN);
|
|
||||||
etx_txt_color(lvobj, (LcdColorIndex)COLOR_VAL(color.flags));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LvglWidgetLabel::setFont(LcdFlags newFont)
|
void LvglWidgetLabel::setFont(LcdFlags newFont)
|
||||||
@@ -581,14 +590,8 @@ void LvglWidgetLineBase::parseParam(lua_State *L, const char *key)
|
|||||||
|
|
||||||
void LvglWidgetLineBase::setColor(LcdFlags newColor)
|
void LvglWidgetLineBase::setColor(LcdFlags newColor)
|
||||||
{
|
{
|
||||||
if (lvobj && colorChanged(newColor)) {
|
if (lvobj && color.changedColor(newColor)) {
|
||||||
if (color.flags & RGB_FLAG) {
|
etx_line_color_from_flags(lvobj, color.flags);
|
||||||
etx_remove_line_color(lvobj);
|
|
||||||
lv_obj_set_style_line_color(lvobj, makeLvColor(color.flags), LV_PART_MAIN);
|
|
||||||
} else {
|
|
||||||
lv_obj_remove_local_style_prop(lvobj, LV_STYLE_LINE_COLOR, LV_PART_MAIN);
|
|
||||||
etx_line_color(lvobj, (LcdColorIndex)COLOR_VAL(color.flags));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -748,14 +751,8 @@ void LvglWidgetLine::clearRefs(lua_State *L)
|
|||||||
|
|
||||||
void LvglWidgetLine::setColor(LcdFlags newColor)
|
void LvglWidgetLine::setColor(LcdFlags newColor)
|
||||||
{
|
{
|
||||||
if (lvobj && colorChanged(newColor)) {
|
if (lvobj && color.changedColor(newColor)) {
|
||||||
if (color.flags & RGB_FLAG) {
|
etx_line_color_from_flags(lvobj, color.flags);
|
||||||
etx_remove_line_color(lvobj);
|
|
||||||
lv_obj_set_style_line_color(lvobj, makeLvColor(color.flags), LV_PART_MAIN);
|
|
||||||
} else {
|
|
||||||
lv_obj_remove_local_style_prop(lvobj, LV_STYLE_LINE_COLOR, LV_PART_MAIN);
|
|
||||||
etx_line_color(lvobj, (LcdColorIndex)COLOR_VAL(color.flags));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -814,7 +811,7 @@ void LvglWidgetLine::refresh()
|
|||||||
lv_obj_del(lvobj);
|
lv_obj_del(lvobj);
|
||||||
lvobj = nullptr;
|
lvobj = nullptr;
|
||||||
}
|
}
|
||||||
currentColor = -1;
|
color.currVal = -1;
|
||||||
build(nullptr);
|
build(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -890,7 +887,7 @@ void LvglWidgetTriangle::clearRefs(lua_State *L)
|
|||||||
|
|
||||||
void LvglWidgetTriangle::setColor(LcdFlags newColor)
|
void LvglWidgetTriangle::setColor(LcdFlags newColor)
|
||||||
{
|
{
|
||||||
if (lvobj && colorChanged(newColor)) {
|
if (lvobj && color.changedColor(newColor)) {
|
||||||
if (color.flags & RGB_FLAG) {
|
if (color.flags & RGB_FLAG) {
|
||||||
etx_remove_img_color(lvobj);
|
etx_remove_img_color(lvobj);
|
||||||
lv_obj_set_style_img_recolor(lvobj, makeLvColor(color.flags), LV_PART_MAIN);
|
lv_obj_set_style_img_recolor(lvobj, makeLvColor(color.flags), LV_PART_MAIN);
|
||||||
@@ -1102,7 +1099,7 @@ void LvglWidgetTriangle::refresh()
|
|||||||
lv_obj_del(lvobj);
|
lv_obj_del(lvobj);
|
||||||
lvobj = nullptr;
|
lvobj = nullptr;
|
||||||
}
|
}
|
||||||
currentColor = -1;
|
color.forceUpdate();
|
||||||
build(nullptr);
|
build(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1214,7 +1211,7 @@ void LvglWidgetBorderedObject::parseParam(lua_State *L, const char *key)
|
|||||||
|
|
||||||
void LvglWidgetBorderedObject::setColor(LcdFlags newColor)
|
void LvglWidgetBorderedObject::setColor(LcdFlags newColor)
|
||||||
{
|
{
|
||||||
if (colorChanged(newColor)) {
|
if (color.changedColor(newColor)) {
|
||||||
if (filled) {
|
if (filled) {
|
||||||
etx_bg_color_from_flags(window->getLvObj(), color.flags);
|
etx_bg_color_from_flags(window->getLvObj(), color.flags);
|
||||||
} else {
|
} else {
|
||||||
@@ -1333,10 +1330,20 @@ void LvglWidgetCircle::build(lua_State *L)
|
|||||||
|
|
||||||
void LvglWidgetArc::parseParam(lua_State *L, const char *key)
|
void LvglWidgetArc::parseParam(lua_State *L, const char *key)
|
||||||
{
|
{
|
||||||
if (!strcmp(key, "startAngle")) {
|
if (!strcmp(key, "rounded")) {
|
||||||
|
rounded = lua_toboolean(L, -1);
|
||||||
|
} else if (!strcmp(key, "startAngle")) {
|
||||||
startAngle.parse(L);
|
startAngle.parse(L);
|
||||||
} else if (!strcmp(key, "endAngle")) {
|
} else if (!strcmp(key, "endAngle")) {
|
||||||
endAngle.parse(L);
|
endAngle.parse(L);
|
||||||
|
} else if (!strcmp(key, "bgColor")) {
|
||||||
|
bgColor.parse(L);
|
||||||
|
} else if (!strcmp(key, "bgOpacity")) {
|
||||||
|
bgOpacity.parse(L);
|
||||||
|
} else if (!strcmp(key, "bgStartAngle")) {
|
||||||
|
bgStartAngle.parse(L);
|
||||||
|
} else if (!strcmp(key, "bgEndAngle")) {
|
||||||
|
bgEndAngle.parse(L);
|
||||||
} else {
|
} else {
|
||||||
LvglWidgetRoundObject::parseParam(L, key);
|
LvglWidgetRoundObject::parseParam(L, key);
|
||||||
}
|
}
|
||||||
@@ -1344,31 +1351,58 @@ void LvglWidgetArc::parseParam(lua_State *L, const char *key)
|
|||||||
|
|
||||||
void LvglWidgetArc::setColor(LcdFlags newColor)
|
void LvglWidgetArc::setColor(LcdFlags newColor)
|
||||||
{
|
{
|
||||||
if (colorChanged(newColor)) {
|
if (color.changedColor(newColor)) {
|
||||||
if (color.flags & RGB_FLAG) {
|
etx_arc_color_from_flags(window->getLvObj(), color.flags, LV_PART_INDICATOR);
|
||||||
etx_remove_arc_color(window->getLvObj());
|
}
|
||||||
lv_obj_set_style_arc_color(window->getLvObj(), makeLvColor(color.flags), LV_PART_INDICATOR);
|
}
|
||||||
} else {
|
|
||||||
lv_obj_remove_local_style_prop(window->getLvObj(), LV_STYLE_ARC_COLOR, LV_PART_MAIN);
|
void LvglWidgetArc::setBgColor(LcdFlags newColor)
|
||||||
etx_arc_color(window->getLvObj(), (LcdColorIndex)COLOR_VAL(color.flags), LV_PART_INDICATOR);
|
{
|
||||||
}
|
if (bgColor.changedColor(newColor)) {
|
||||||
|
etx_arc_color_from_flags(window->getLvObj(), bgColor.flags, LV_PART_MAIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LvglWidgetArc::setOpacity(uint8_t newOpa)
|
void LvglWidgetArc::setOpacity(uint8_t newOpa)
|
||||||
{
|
{
|
||||||
opacity.value = newOpa;
|
if (opacity.changedValue(newOpa)) {
|
||||||
lv_obj_set_style_arc_opa(window->getLvObj(), opacity.value, LV_PART_INDICATOR);
|
lv_obj_set_style_arc_opa(window->getLvObj(), opacity.value, LV_PART_INDICATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LvglWidgetArc::setBgOpacity(uint8_t newOpa)
|
||||||
|
{
|
||||||
|
if (bgOpacity.changedValue(newOpa)) {
|
||||||
|
lv_obj_set_style_arc_opa(window->getLvObj(), bgOpacity.value, LV_PART_MAIN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LvglWidgetArc::setStartAngle(coord_t angle)
|
void LvglWidgetArc::setStartAngle(coord_t angle)
|
||||||
{
|
{
|
||||||
lv_arc_set_start_angle(window->getLvObj(), angle);
|
if (startAngle.changedValue(angle)) {
|
||||||
|
lv_arc_set_start_angle(window->getLvObj(), startAngle.coord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LvglWidgetArc::setBgStartAngle(coord_t angle)
|
||||||
|
{
|
||||||
|
if (bgStartAngle.changedValue(angle)) {
|
||||||
|
lv_arc_set_bg_start_angle(window->getLvObj(), bgStartAngle.coord);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LvglWidgetArc::setEndAngle(coord_t angle)
|
void LvglWidgetArc::setEndAngle(coord_t angle)
|
||||||
{
|
{
|
||||||
lv_arc_set_end_angle(window->getLvObj(), angle);
|
if (endAngle.changedValue(angle)) {
|
||||||
|
lv_arc_set_end_angle(window->getLvObj(), endAngle.coord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LvglWidgetArc::setBgEndAngle(coord_t angle)
|
||||||
|
{
|
||||||
|
if (bgEndAngle.changedValue(angle)) {
|
||||||
|
lv_arc_set_bg_end_angle(window->getLvObj(), bgEndAngle.coord);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LvglWidgetArc::callRefs(lua_State *L)
|
bool LvglWidgetArc::callRefs(lua_State *L)
|
||||||
@@ -1379,6 +1413,12 @@ bool LvglWidgetArc::callRefs(lua_State *L)
|
|||||||
if (!pcallUpdate1Int(L, endAngle.function,
|
if (!pcallUpdate1Int(L, endAngle.function,
|
||||||
[=](int val) { setEndAngle(val); }))
|
[=](int val) { setEndAngle(val); }))
|
||||||
return false;
|
return false;
|
||||||
|
if (!pcallUpdate1Int(L, bgStartAngle.function,
|
||||||
|
[=](int val) { setBgStartAngle(val); }))
|
||||||
|
return false;
|
||||||
|
if (!pcallUpdate1Int(L, bgEndAngle.function,
|
||||||
|
[=](int val) { setBgEndAngle(val); }))
|
||||||
|
return false;
|
||||||
return LvglWidgetRoundObject::callRefs(L);
|
return LvglWidgetRoundObject::callRefs(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1386,6 +1426,10 @@ void LvglWidgetArc::clearRefs(lua_State *L)
|
|||||||
{
|
{
|
||||||
clearRef(L, startAngle.function);
|
clearRef(L, startAngle.function);
|
||||||
clearRef(L, endAngle.function);
|
clearRef(L, endAngle.function);
|
||||||
|
clearRef(L, bgColor.function);
|
||||||
|
clearRef(L, bgOpacity.function);
|
||||||
|
clearRef(L, bgStartAngle.function);
|
||||||
|
clearRef(L, bgEndAngle.function);
|
||||||
LvglWidgetRoundObject::clearRefs(L);
|
LvglWidgetRoundObject::clearRefs(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1399,16 +1443,20 @@ void LvglWidgetArc::build(lua_State *L)
|
|||||||
new Window(lvglManager->getCurrentParent(), {x, y, w, h}, lv_arc_create);
|
new Window(lvglManager->getCurrentParent(), {x, y, w, h}, lv_arc_create);
|
||||||
lv_obj_add_flag(window->getLvObj(), LV_OBJ_FLAG_EVENT_BUBBLE);
|
lv_obj_add_flag(window->getLvObj(), LV_OBJ_FLAG_EVENT_BUBBLE);
|
||||||
lv_obj_clear_flag(window->getLvObj(), LV_OBJ_FLAG_CLICKABLE);
|
lv_obj_clear_flag(window->getLvObj(), LV_OBJ_FLAG_CLICKABLE);
|
||||||
setColor(color.flags);
|
|
||||||
lv_arc_set_bg_angles(window->getLvObj(), 0, 360);
|
|
||||||
lv_arc_set_range(window->getLvObj(), 0, 360);
|
lv_arc_set_range(window->getLvObj(), 0, 360);
|
||||||
lv_arc_set_angles(window->getLvObj(), 0, 360);
|
lv_obj_remove_style(window->getLvObj(), NULL, LV_PART_KNOB);
|
||||||
|
lv_obj_set_style_arc_width(window->getLvObj(), thickness, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_arc_rounded(window->getLvObj(), rounded, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_arc_width(window->getLvObj(), thickness, LV_PART_INDICATOR);
|
||||||
|
lv_obj_set_style_arc_rounded(window->getLvObj(), rounded, LV_PART_INDICATOR);
|
||||||
|
setBgStartAngle(bgStartAngle.coord);
|
||||||
|
setBgEndAngle(bgEndAngle.coord);
|
||||||
setStartAngle(startAngle.coord);
|
setStartAngle(startAngle.coord);
|
||||||
setEndAngle(endAngle.coord);
|
setEndAngle(endAngle.coord);
|
||||||
lv_obj_remove_style(window->getLvObj(), NULL, LV_PART_KNOB);
|
setColor(color.flags);
|
||||||
lv_obj_set_style_arc_opa(window->getLvObj(), LV_OPA_TRANSP, LV_PART_MAIN);
|
setBgColor(bgColor.flags);
|
||||||
lv_obj_set_style_arc_width(window->getLvObj(), thickness, LV_PART_INDICATOR);
|
|
||||||
setOpacity(opacity.value);
|
setOpacity(opacity.value);
|
||||||
|
setBgOpacity(bgOpacity.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -1453,13 +1501,13 @@ void LvglWidgetQRCode::build(lua_State *L)
|
|||||||
void LvglWidgetTextButtonBase::parseParam(lua_State *L, const char *key)
|
void LvglWidgetTextButtonBase::parseParam(lua_State *L, const char *key)
|
||||||
{
|
{
|
||||||
if (!strcmp(key, "text")) {
|
if (!strcmp(key, "text")) {
|
||||||
txt = luaL_checkstring(L, -1);
|
txt.parse(L, LvglParamFuncOrValue::PTXT);
|
||||||
} else if (!strcmp(key, "font")) {
|
} else if (!strcmp(key, "font")) {
|
||||||
font = luaL_checkunsigned(L, -1);
|
font = luaL_checkunsigned(L, -1);
|
||||||
} else if (!strcmp(key, "cornerRadius")) {
|
} else if (!strcmp(key, "cornerRadius")) {
|
||||||
rounded = luaL_checkunsigned(L, -1);
|
rounded = luaL_checkunsigned(L, -1);
|
||||||
} else if (!strcmp(key, "textColor")) {
|
} else if (!strcmp(key, "textColor")) {
|
||||||
textColor = luaL_checkunsigned(L, -1);
|
textColor.parse(L);
|
||||||
} else if (!strcmp(key, "press")) {
|
} else if (!strcmp(key, "press")) {
|
||||||
pressFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
pressFunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
} else {
|
} else {
|
||||||
@@ -1467,18 +1515,35 @@ void LvglWidgetTextButtonBase::parseParam(lua_State *L, const char *key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LvglWidgetTextButtonBase::callRefs(lua_State *L)
|
||||||
|
{
|
||||||
|
int t = lua_gettop(L);
|
||||||
|
if (txt.function != LUA_REFNIL) {
|
||||||
|
if (pcallFunc(L, txt.function, 1)) {
|
||||||
|
const char *s = luaL_checkstring(L, -1);
|
||||||
|
setText(s);
|
||||||
|
lua_settop(L, t);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!pcallUpdate1Int(L, textColor.function,
|
||||||
|
[=](int color) { setTextColor(color); }))
|
||||||
|
return false;
|
||||||
|
return LvglWidgetObject::callRefs(L);
|
||||||
|
}
|
||||||
|
|
||||||
void LvglWidgetTextButtonBase::clearRefs(lua_State *L)
|
void LvglWidgetTextButtonBase::clearRefs(lua_State *L)
|
||||||
{
|
{
|
||||||
|
clearRef(L, txt.function);
|
||||||
|
clearRef(L, textColor.function);
|
||||||
clearRef(L, pressFunction);
|
clearRef(L, pressFunction);
|
||||||
LvglWidgetObject::clearRefs(L);
|
LvglWidgetObject::clearRefs(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LvglWidgetTextButtonBase::setText(const char *s)
|
void LvglWidgetTextButtonBase::setText(const char *s)
|
||||||
{
|
{
|
||||||
uint32_t h = hash(s, strlen(s));
|
if (txt.changedText(s)) {
|
||||||
if (h != textHash) {
|
|
||||||
txt = s;
|
|
||||||
textHash = h;
|
|
||||||
((TextButton *)window)->setText(s);
|
((TextButton *)window)->setText(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1492,14 +1557,15 @@ void LvglWidgetTextButtonBase::setSize(coord_t w, coord_t h)
|
|||||||
|
|
||||||
void LvglWidgetTextButtonBase::setColor(LcdFlags newColor)
|
void LvglWidgetTextButtonBase::setColor(LcdFlags newColor)
|
||||||
{
|
{
|
||||||
color.flags = newColor;
|
if (color.changedColor(newColor)) {
|
||||||
if (color.flags != currentColor) {
|
|
||||||
currentColor = color.flags;
|
|
||||||
etx_bg_color_from_flags(window->getLvObj(), color.flags);
|
etx_bg_color_from_flags(window->getLvObj(), color.flags);
|
||||||
}
|
}
|
||||||
if (textColor != currentTextColor) {
|
}
|
||||||
currentTextColor = textColor;
|
|
||||||
etx_txt_color_from_flags(window->getLvObj(), textColor);
|
void LvglWidgetTextButtonBase::setTextColor(LcdFlags newColor)
|
||||||
|
{
|
||||||
|
if (textColor.changedColor(newColor)) {
|
||||||
|
etx_txt_color_from_flags(window->getLvObj(), textColor.flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1549,7 +1615,7 @@ void LvglWidgetTextButton::build(lua_State *L)
|
|||||||
{
|
{
|
||||||
if (h == LV_SIZE_CONTENT) h = 0;
|
if (h == LV_SIZE_CONTENT) h = 0;
|
||||||
auto btn =
|
auto btn =
|
||||||
new TextButton(lvglManager->getCurrentParent(), {x, y, w, h}, txt, [=]() {
|
new TextButton(lvglManager->getCurrentParent(), {x, y, w, h}, txt.txt, [=]() {
|
||||||
return pcallGetOptIntVal(L, pressFunction, 0);
|
return pcallGetOptIntVal(L, pressFunction, 0);
|
||||||
});
|
});
|
||||||
if (longPressFunction != LUA_REFNIL) {
|
if (longPressFunction != LUA_REFNIL) {
|
||||||
@@ -1561,6 +1627,7 @@ void LvglWidgetTextButton::build(lua_State *L)
|
|||||||
setFont(font);
|
setFont(font);
|
||||||
setChecked(checked);
|
setChecked(checked);
|
||||||
setColor(color.flags);
|
setColor(color.flags);
|
||||||
|
setTextColor(textColor.flags);
|
||||||
setRounded();
|
setRounded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1593,7 +1660,7 @@ void LvglWidgetMomentaryButton::build(lua_State *L)
|
|||||||
{
|
{
|
||||||
if (h == LV_SIZE_CONTENT) h = 0;
|
if (h == LV_SIZE_CONTENT) h = 0;
|
||||||
window =
|
window =
|
||||||
new MomentaryButton(lvglManager->getCurrentParent(), {x, y, w, h}, txt,
|
new MomentaryButton(lvglManager->getCurrentParent(), {x, y, w, h}, txt.txt,
|
||||||
[=]() {
|
[=]() {
|
||||||
pcallSimpleFunc(L, pressFunction);
|
pcallSimpleFunc(L, pressFunction);
|
||||||
},
|
},
|
||||||
@@ -1602,6 +1669,7 @@ void LvglWidgetMomentaryButton::build(lua_State *L)
|
|||||||
});
|
});
|
||||||
setFont(font);
|
setFont(font);
|
||||||
setColor(color.flags);
|
setColor(color.flags);
|
||||||
|
setTextColor(textColor.flags);
|
||||||
setRounded();
|
setRounded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1756,9 +1824,7 @@ void LvglWidgetSliderBase::parseParam(lua_State *L, const char *key)
|
|||||||
|
|
||||||
void LvglWidgetSliderBase::setColor(LcdFlags newColor)
|
void LvglWidgetSliderBase::setColor(LcdFlags newColor)
|
||||||
{
|
{
|
||||||
color.flags = newColor;
|
if (color.changedColor(newColor)) {
|
||||||
if (color.flags != currentColor) {
|
|
||||||
currentColor = color.flags;
|
|
||||||
((SliderBase*)window)->setColor(color.flags);
|
((SliderBase*)window)->setColor(color.flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,13 @@ struct LvglParamFuncOrValue
|
|||||||
uint32_t value;
|
uint32_t value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint32_t currVal = -1;
|
||||||
|
|
||||||
void parse(lua_State *L, ParamType typ = PVALUE);
|
void parse(lua_State *L, ParamType typ = PVALUE);
|
||||||
|
void forceUpdate() { currVal = -1; }
|
||||||
|
bool changedColor(LcdFlags newFlags);
|
||||||
|
bool changedText(const char* s);
|
||||||
|
bool changedValue(uint32_t v);
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -91,7 +97,6 @@ class LvglWidgetObjectBase
|
|||||||
bool clearRequest = false;
|
bool clearRequest = false;
|
||||||
LuaScriptManager *lvglManager = nullptr;
|
LuaScriptManager *lvglManager = nullptr;
|
||||||
coord_t x = 0, y = 0, w = LV_SIZE_CONTENT, h = LV_SIZE_CONTENT;
|
coord_t x = 0, y = 0, w = LV_SIZE_CONTENT, h = LV_SIZE_CONTENT;
|
||||||
LcdFlags currentColor = -1;
|
|
||||||
int getVisibleFunction = LUA_REFNIL;
|
int getVisibleFunction = LUA_REFNIL;
|
||||||
int getSizeFunction = LUA_REFNIL;
|
int getSizeFunction = LUA_REFNIL;
|
||||||
int getPosFunction = LUA_REFNIL;
|
int getPosFunction = LUA_REFNIL;
|
||||||
@@ -105,8 +110,6 @@ class LvglWidgetObjectBase
|
|||||||
|
|
||||||
void getParams(lua_State *L, int index);
|
void getParams(lua_State *L, int index);
|
||||||
|
|
||||||
bool colorChanged(LcdFlags newColor);
|
|
||||||
|
|
||||||
void clearRef(lua_State *L, int& ref);
|
void clearRef(lua_State *L, int& ref);
|
||||||
|
|
||||||
void pcallSimpleFunc(lua_State *L, int funcRef);
|
void pcallSimpleFunc(lua_State *L, int funcRef);
|
||||||
@@ -156,8 +159,6 @@ class LvglWidgetLabel : public LvglSimpleWidgetObject
|
|||||||
void clearRefs(lua_State *L) override;
|
void clearRefs(lua_State *L) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t textHash = -1;
|
|
||||||
|
|
||||||
LvglParamFuncOrValue font = { .function = LUA_REFNIL, .flags = FONT(STD)};
|
LvglParamFuncOrValue font = { .function = LUA_REFNIL, .flags = FONT(STD)};
|
||||||
LvglParamFuncOrValue align = { .function = LUA_REFNIL, .flags = LEFT};
|
LvglParamFuncOrValue align = { .function = LUA_REFNIL, .flags = LEFT};
|
||||||
LvglParamFuncOrValue txt = { .function = LUA_REFNIL, .txt = ""};
|
LvglParamFuncOrValue txt = { .function = LUA_REFNIL, .txt = ""};
|
||||||
@@ -414,16 +415,25 @@ class LvglWidgetArc : public LvglWidgetRoundObject
|
|||||||
LvglWidgetArc() : LvglWidgetRoundObject() {}
|
LvglWidgetArc() : LvglWidgetRoundObject() {}
|
||||||
|
|
||||||
void setColor(LcdFlags newColor) override;
|
void setColor(LcdFlags newColor) override;
|
||||||
|
void setBgColor(LcdFlags newColor);
|
||||||
void setOpacity(uint8_t newOpa) override;
|
void setOpacity(uint8_t newOpa) override;
|
||||||
|
void setBgOpacity(uint8_t newOpa);
|
||||||
void setStartAngle(coord_t angle);
|
void setStartAngle(coord_t angle);
|
||||||
void setEndAngle(coord_t angle);
|
void setEndAngle(coord_t angle);
|
||||||
|
void setBgStartAngle(coord_t angle);
|
||||||
|
void setBgEndAngle(coord_t angle);
|
||||||
|
|
||||||
bool callRefs(lua_State *L) override;
|
bool callRefs(lua_State *L) override;
|
||||||
void clearRefs(lua_State *L) override;
|
void clearRefs(lua_State *L) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool rounded = false;
|
||||||
LvglParamFuncOrValue startAngle = { .function = LUA_REFNIL, .coord = 0};
|
LvglParamFuncOrValue startAngle = { .function = LUA_REFNIL, .coord = 0};
|
||||||
LvglParamFuncOrValue endAngle = { .function = LUA_REFNIL, .coord = 0};
|
LvglParamFuncOrValue endAngle = { .function = LUA_REFNIL, .coord = 360};
|
||||||
|
LvglParamFuncOrValue bgColor = { .function = LUA_REFNIL, .flags = (LcdFlags)-1};
|
||||||
|
LvglParamFuncOrValue bgOpacity = { .function = LUA_REFNIL, .value = LV_OPA_TRANSP};
|
||||||
|
LvglParamFuncOrValue bgStartAngle = { .function = LUA_REFNIL, .coord = 0};
|
||||||
|
LvglParamFuncOrValue bgEndAngle = { .function = LUA_REFNIL, .coord = 360};
|
||||||
|
|
||||||
void build(lua_State *L) override;
|
void build(lua_State *L) override;
|
||||||
void parseParam(lua_State *L, const char *key) override;
|
void parseParam(lua_State *L, const char *key) override;
|
||||||
@@ -431,6 +441,10 @@ class LvglWidgetArc : public LvglWidgetRoundObject
|
|||||||
{
|
{
|
||||||
setStartAngle(startAngle.coord);
|
setStartAngle(startAngle.coord);
|
||||||
setEndAngle(endAngle.coord);
|
setEndAngle(endAngle.coord);
|
||||||
|
setBgStartAngle(bgStartAngle.coord);
|
||||||
|
setBgEndAngle(bgEndAngle.coord);
|
||||||
|
setBgColor(bgColor.flags);
|
||||||
|
setBgOpacity(bgOpacity.value);
|
||||||
LvglWidgetRoundObject::refresh();
|
LvglWidgetRoundObject::refresh();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -478,21 +492,25 @@ class LvglWidgetTextButtonBase : public LvglWidgetObject
|
|||||||
void setText(const char *s);
|
void setText(const char *s);
|
||||||
void setSize(coord_t w, coord_t h) override;
|
void setSize(coord_t w, coord_t h) override;
|
||||||
void setColor(LcdFlags newColor) override;
|
void setColor(LcdFlags newColor) override;
|
||||||
|
void setTextColor(LcdFlags newColor);
|
||||||
void setRounded();
|
void setRounded();
|
||||||
|
|
||||||
|
bool callRefs(lua_State *L) override;
|
||||||
void clearRefs(lua_State *L) override;
|
void clearRefs(lua_State *L) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t textHash = -1;
|
LvglParamFuncOrValue txt = { .function = LUA_REFNIL, .txt = ""};
|
||||||
|
|
||||||
const char *txt = "";
|
|
||||||
LcdFlags font = FONT(STD);
|
LcdFlags font = FONT(STD);
|
||||||
coord_t rounded = -1;
|
coord_t rounded = -1;
|
||||||
LcdFlags textColor = -1;
|
LvglParamFuncOrValue textColor = { .function = LUA_REFNIL, .flags = (LcdFlags)-1};
|
||||||
LcdFlags currentTextColor = -1;
|
|
||||||
int pressFunction = LUA_REFNIL;
|
int pressFunction = LUA_REFNIL;
|
||||||
|
|
||||||
void parseParam(lua_State *L, const char *key) override;
|
void parseParam(lua_State *L, const char *key) override;
|
||||||
|
void refresh() override
|
||||||
|
{
|
||||||
|
setTextColor(textColor.flags);
|
||||||
|
LvglWidgetObject::refresh();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user