fix(color): Refresh color picker labels when chg between HSV and RGB (#2774)
This commit is contained in:
@@ -334,20 +334,21 @@ void ColorEditor::setColorEditorType(COLOR_EDITOR_TYPE colorType)
|
|||||||
if (_colorType != nullptr) {
|
if (_colorType != nullptr) {
|
||||||
delete _colorType;
|
delete _colorType;
|
||||||
}
|
}
|
||||||
if (colorType == RGB_COLOR_EDITOR)
|
if (colorType == RGB_COLOR_EDITOR) {
|
||||||
_colorType = new RGBColorType(this, _color);
|
_colorType = new RGBColorType(this, _color);
|
||||||
else
|
setRGB();
|
||||||
|
} else {
|
||||||
_colorType = new HSVColorType(this, _color);
|
_colorType = new HSVColorType(this, _color);
|
||||||
|
setHSV();
|
||||||
|
}
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorEditor::setRGB()
|
void ColorEditor::setText()
|
||||||
{
|
{
|
||||||
_color = _colorType->getRGB();
|
|
||||||
|
|
||||||
// update bars & labels
|
|
||||||
for (int i = 0; i < MAX_BARS; i++) {
|
for (int i = 0; i < MAX_BARS; i++) {
|
||||||
auto bar = _colorType->bars[i];
|
auto bar = _colorType->bars[i];
|
||||||
|
lv_label_set_text_static(barLabels[i], _colorType->getLabelChars()[i]);
|
||||||
lv_label_set_text_fmt(barValLabels[i], "%" PRIu32, bar->value);
|
lv_label_set_text_fmt(barValLabels[i], "%" PRIu32, bar->value);
|
||||||
bar->invalidate();
|
bar->invalidate();
|
||||||
}
|
}
|
||||||
@@ -355,6 +356,19 @@ void ColorEditor::setRGB()
|
|||||||
if (_setValue != nullptr) _setValue(_color);
|
if (_setValue != nullptr) _setValue(_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ColorEditor::setRGB()
|
||||||
|
{
|
||||||
|
_color = _colorType->getRGB();
|
||||||
|
// update bars & labels
|
||||||
|
setText();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColorEditor::setHSV()
|
||||||
|
{
|
||||||
|
// update bars & labels
|
||||||
|
setText();
|
||||||
|
}
|
||||||
|
|
||||||
void ColorEditor::value_changed(lv_event_t* e)
|
void ColorEditor::value_changed(lv_event_t* e)
|
||||||
{
|
{
|
||||||
lv_obj_t* target = lv_event_get_target(e);
|
lv_obj_t* target = lv_event_get_target(e);
|
||||||
|
|||||||
@@ -97,6 +97,8 @@ class ColorEditor : public FormGroup
|
|||||||
std::function<void(uint32_t)> _setValue;
|
std::function<void(uint32_t)> _setValue;
|
||||||
uint32_t _color;
|
uint32_t _color;
|
||||||
|
|
||||||
|
void setText();
|
||||||
|
void setHSV();
|
||||||
void setRGB();
|
void setRGB();
|
||||||
static void value_changed(lv_event_t* e);
|
static void value_changed(lv_event_t* e);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user