Skip to content

Commit

Permalink
Add 'color' setting to slider control.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Jan 30, 2025
1 parent ac810db commit 83bef3b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
10 changes: 9 additions & 1 deletion radio/src/gui/colorlcd/libui/slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ void SliderBase::enable(bool enabled)
}
}

void SliderBase::setColor(LcdFlags color)
{
etx_bg_color_from_flags(slider, color, LV_PART_KNOB);
if (tickPts)
for (int i = 0; i < (vmax - vmin - 1); i += 1)
etx_bg_color_from_flags(tickPts[i], color);
}

//-----------------------------------------------------------------------------

// Slider
Expand All @@ -118,7 +126,7 @@ static void slider_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
etx_bg_color(obj, COLOR_THEME_EDIT_INDEX,
LV_PART_INDICATOR | LV_STATE_FOCUSED | LV_STATE_EDITED);

etx_obj_add_style(obj, styles->bg_opacity_cover, LV_PART_KNOB);
etx_solid_bg(obj, COLOR_THEME_PRIMARY2_INDEX, LV_PART_KNOB);
etx_obj_add_style(obj, slider_knob, LV_PART_KNOB);
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_SECONDARY1_INDEX], LV_PART_MAIN);
etx_obj_add_style(obj, styles->border_color[COLOR_THEME_FOCUS_INDEX],
Expand Down
1 change: 1 addition & 0 deletions radio/src/gui/colorlcd/libui/slider.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SliderBase : public Window
std::function<int()> getValue, std::function<void(int)> setValue);

void setValue(int value);
void setColor(LcdFlags color);

void update();

Expand Down
12 changes: 12 additions & 0 deletions radio/src/lua/lua_lvgl_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,7 @@ void LvglWidgetTextButtonBase::setSize(coord_t w, coord_t h)

void LvglWidgetTextButtonBase::setColor(LcdFlags newColor)
{
color = newColor;
if (color != currentColor) {
currentColor = color;
etx_bg_color_from_flags(window->getLvObj(), color);
Expand Down Expand Up @@ -1648,6 +1649,15 @@ void LvglWidgetSliderBase::parseParam(lua_State *L, const char *key)
}
}

void LvglWidgetSliderBase::setColor(LcdFlags newColor)
{
color = newColor;
if (color != currentColor) {
currentColor = color;
((SliderBase*)window)->setColor(color);
}
}

void LvglWidgetSliderBase::clearRefs(lua_State *L)
{
clearRef(L, getValueFunction);
Expand All @@ -1664,6 +1674,7 @@ void LvglWidgetSlider::build(lua_State *L)
[=]() { return pcallGetIntVal(L, getValueFunction); },
[=](int val) { pcallSetIntVal(L, setValueFunction, val); });
window->setPos(x, y);
setColor(color);
}

//-----------------------------------------------------------------------------
Expand All @@ -1675,6 +1686,7 @@ void LvglWidgetVerticalSlider::build(lua_State *L)
[=]() { return pcallGetIntVal(L, getValueFunction); },
[=](int val) { pcallSetIntVal(L, setValueFunction, val); });
window->setPos(x, y);
setColor(color);
}

//-----------------------------------------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion radio/src/lua/lua_lvgl_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,12 @@ class LvglWidgetNumberEdit : public LvglWidgetObject
class LvglWidgetSliderBase : public LvglWidgetObject
{
public:
LvglWidgetSliderBase() : LvglWidgetObject(LVGL_SIMPLEMETATABLE) {}
LvglWidgetSliderBase() : LvglWidgetObject(LVGL_SIMPLEMETATABLE)
{
color = -1;
}

void setColor(LcdFlags newColor) override;

void clearRefs(lua_State *L) override;

Expand Down

0 comments on commit 83bef3b

Please sign in to comment.