fix(color): issues with color picker dialog (#5204)
This commit is contained in:
@@ -28,22 +28,25 @@ static const char* const HSVChars[MAX_BARS] = {"H", "S", "V"};
|
|||||||
|
|
||||||
typedef std::function<uint32_t(int pos)> getRGBFromPos;
|
typedef std::function<uint32_t(int pos)> getRGBFromPos;
|
||||||
|
|
||||||
class ColorBar : public Window
|
class ColorBar : public FormField
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ColorBar(Window* parent, const rect_t& r, uint32_t value = 0,
|
ColorBar(Window* parent, const rect_t& r, uint32_t value = 0,
|
||||||
uint32_t maxValue = 0, bool invert = false) :
|
uint32_t maxValue = 0, bool invert = false) :
|
||||||
Window(parent, r)
|
FormField(parent, r)
|
||||||
{
|
{
|
||||||
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_ENCODER_ACCEL);
|
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_ENCODER_ACCEL);
|
||||||
|
|
||||||
lv_group_add_obj((lv_group_t*)lv_group_get_default(), lvobj);
|
lv_group_add_obj((lv_group_t*)lv_group_get_default(), lvobj);
|
||||||
|
|
||||||
lv_obj_add_event_cb(lvobj, ColorBar::pressing, LV_EVENT_PRESSING, nullptr);
|
lv_obj_add_event_cb(lvobj, ColorBar::pressing, LV_EVENT_PRESSING, nullptr);
|
||||||
lv_obj_add_event_cb(lvobj, ColorBar::on_key, LV_EVENT_KEY, nullptr);
|
lv_obj_add_event_cb(lvobj, ColorBar::on_key, LV_EVENT_KEY, nullptr);
|
||||||
lv_obj_add_event_cb(lvobj, ColorBar::draw_end, LV_EVENT_DRAW_PART_END,
|
lv_obj_add_event_cb(lvobj, ColorBar::draw_end, LV_EVENT_DRAW_PART_END,
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
etx_std_style(lvobj, LV_PART_MAIN, PAD_ZERO);
|
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->outline_color_edit, LV_PART_MAIN | LV_STATE_EDITED);
|
||||||
}
|
}
|
||||||
|
|
||||||
int valueToScreen(int val)
|
int valueToScreen(int val)
|
||||||
@@ -211,59 +214,7 @@ class ColorType
|
|||||||
class BarColorType : public ColorType
|
class BarColorType : public ColorType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BarColorType(Window* parent);
|
BarColorType(Window* parent)
|
||||||
~BarColorType() override;
|
|
||||||
|
|
||||||
void setText() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
ColorBar* bars[MAX_BARS];
|
|
||||||
lv_obj_t* barLabels[MAX_BARS];
|
|
||||||
lv_obj_t* barValLabels[MAX_BARS];
|
|
||||||
|
|
||||||
virtual const char* const* getLabelChars() { return nullptr; };
|
|
||||||
|
|
||||||
lv_obj_t* create_bar_label(lv_obj_t* parent, lv_coord_t x, lv_coord_t y);
|
|
||||||
lv_obj_t* create_bar_value_label(lv_obj_t* parent, lv_coord_t x,
|
|
||||||
lv_coord_t y);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Color editor for HSV color input
|
|
||||||
class HSVColorType : public BarColorType
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
HSVColorType(Window* parent, uint32_t color);
|
|
||||||
uint32_t getRGB() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const char* const* getLabelChars() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Color editor for RGB color input
|
|
||||||
class RGBColorType : public BarColorType
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RGBColorType(Window* parent, uint32_t color);
|
|
||||||
uint32_t getRGB() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const char* const* getLabelChars() override;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Color editor that shows the system theme colors as buttons
|
|
||||||
class ThemeColorType : public ColorType
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ThemeColorType(Window* parent, uint32_t color);
|
|
||||||
uint32_t getRGB() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
uint32_t m_color;
|
|
||||||
void makeButton(Window* parent, uint16_t color);
|
|
||||||
void makeButtonsRow(Window* parent, uint16_t c1, uint16_t c2, uint16_t c3);
|
|
||||||
};
|
|
||||||
|
|
||||||
BarColorType::BarColorType(Window* parent)
|
|
||||||
{
|
{
|
||||||
auto spacePerBar = (parent->width() / MAX_BARS);
|
auto spacePerBar = (parent->width() / MAX_BARS);
|
||||||
|
|
||||||
@@ -289,33 +240,14 @@ BarColorType::BarColorType(Window* parent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BarColorType::~BarColorType()
|
~BarColorType() override
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_BARS; i++) {
|
for (int i = 0; i < MAX_BARS; i++) {
|
||||||
bars[i]->deleteLater();
|
bars[i]->deleteLater();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
lv_obj_t* BarColorType::create_bar_label(lv_obj_t* parent, lv_coord_t x,
|
void setText() override
|
||||||
lv_coord_t y)
|
|
||||||
{
|
|
||||||
lv_obj_t* obj = lv_label_create(parent);
|
|
||||||
lv_obj_set_pos(obj, x, y);
|
|
||||||
etx_txt_color(obj, COLOR_THEME_PRIMARY1_INDEX);
|
|
||||||
etx_font(obj, FONT_XXS_INDEX);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_obj_t* BarColorType::create_bar_value_label(lv_obj_t* parent, lv_coord_t x,
|
|
||||||
lv_coord_t y)
|
|
||||||
{
|
|
||||||
lv_obj_t* obj = lv_label_create(parent);
|
|
||||||
lv_obj_set_pos(obj, x, y);
|
|
||||||
etx_txt_color(obj, COLOR_THEME_PRIMARY1_INDEX);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BarColorType::setText()
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_BARS; i++) {
|
for (int i = 0; i < MAX_BARS; i++) {
|
||||||
auto bar = bars[i];
|
auto bar = bars[i];
|
||||||
@@ -325,8 +257,37 @@ void BarColorType::setText()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HSVColorType::HSVColorType(Window* parent, uint32_t color) :
|
protected:
|
||||||
BarColorType(parent)
|
ColorBar* bars[MAX_BARS];
|
||||||
|
lv_obj_t* barLabels[MAX_BARS];
|
||||||
|
lv_obj_t* barValLabels[MAX_BARS];
|
||||||
|
|
||||||
|
virtual const char* const* getLabelChars() { return nullptr; };
|
||||||
|
|
||||||
|
lv_obj_t* create_bar_label(lv_obj_t* parent, lv_coord_t x, lv_coord_t y)
|
||||||
|
{
|
||||||
|
lv_obj_t* obj = lv_label_create(parent);
|
||||||
|
lv_obj_set_pos(obj, x, y);
|
||||||
|
etx_txt_color(obj, COLOR_THEME_PRIMARY1_INDEX);
|
||||||
|
etx_font(obj, FONT_XXS_INDEX);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_t* create_bar_value_label(lv_obj_t* parent, lv_coord_t x,
|
||||||
|
lv_coord_t y)
|
||||||
|
{
|
||||||
|
lv_obj_t* obj = lv_label_create(parent);
|
||||||
|
lv_obj_set_pos(obj, x, y);
|
||||||
|
etx_txt_color(obj, COLOR_THEME_PRIMARY1_INDEX);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Color editor for HSV color input
|
||||||
|
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 r = GET_RED(color), g = GET_GREEN(color), b = GET_BLUE(color);
|
||||||
float values[MAX_BARS];
|
float values[MAX_BARS];
|
||||||
@@ -359,15 +320,20 @@ HSVColorType::HSVColorType(Window* parent, uint32_t color) :
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t HSVColorType::getRGB()
|
uint32_t getRGB() override
|
||||||
{
|
{
|
||||||
return HSVtoRGB(bars[0]->value, bars[1]->value, bars[2]->value);
|
return HSVtoRGB(bars[0]->value, bars[1]->value, bars[2]->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* const* HSVColorType::getLabelChars() { return HSVChars; }
|
protected:
|
||||||
|
const char* const* getLabelChars() override { return HSVChars; }
|
||||||
|
};
|
||||||
|
|
||||||
RGBColorType::RGBColorType(Window* parent, uint32_t color) :
|
// Color editor for RGB color input
|
||||||
BarColorType(parent)
|
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 r = GET_RED(color), g = GET_GREEN(color), b = GET_BLUE(color);
|
||||||
float values[MAX_BARS];
|
float values[MAX_BARS];
|
||||||
@@ -386,40 +352,20 @@ RGBColorType::RGBColorType(Window* parent, uint32_t color) :
|
|||||||
bars[2]->getRGB = [=](int pos) { return RGB(0, 0, pos); };
|
bars[2]->getRGB = [=](int pos) { return RGB(0, 0, pos); };
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t RGBColorType::getRGB()
|
uint32_t getRGB() override
|
||||||
{
|
{
|
||||||
return RGB(bars[0]->value, bars[1]->value, bars[2]->value);
|
return RGB(bars[0]->value, bars[1]->value, bars[2]->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* const* RGBColorType::getLabelChars() { return RGBChars; }
|
protected:
|
||||||
|
const char* const* getLabelChars() override { return RGBChars; }
|
||||||
|
};
|
||||||
|
|
||||||
void ThemeColorType::makeButton(Window* parent, uint16_t color)
|
// Color editor that shows the system theme colors as buttons
|
||||||
|
class ThemeColorType : public ColorType
|
||||||
{
|
{
|
||||||
auto btn = new TextButton(parent, rect_t{}, " ");
|
public:
|
||||||
etx_bg_color(btn->getLvObj(), (LcdColorIndex)color);
|
ThemeColorType(Window* parent, uint32_t color)
|
||||||
btn->setPressHandler([=]() {
|
|
||||||
auto cv = lcdColorTable[color];
|
|
||||||
m_color = RGB(GET_RED(cv), GET_GREEN(cv), GET_BLUE(cv));
|
|
||||||
lv_event_send(parent->getParent()->getParent()->getLvObj(),
|
|
||||||
LV_EVENT_VALUE_CHANGED, nullptr);
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThemeColorType::makeButtonsRow(Window* parent, uint16_t c1, uint16_t c2,
|
|
||||||
uint16_t c3)
|
|
||||||
{
|
|
||||||
auto hbox = new Window(parent, rect_t{});
|
|
||||||
hbox->setFlexLayout(LV_FLEX_FLOW_ROW, PAD_MEDIUM);
|
|
||||||
lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_CENTER,
|
|
||||||
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND);
|
|
||||||
|
|
||||||
makeButton(hbox, c1);
|
|
||||||
makeButton(hbox, c2);
|
|
||||||
if (c3 != c2) makeButton(hbox, c3);
|
|
||||||
}
|
|
||||||
|
|
||||||
ThemeColorType::ThemeColorType(Window* parent, uint32_t color) : ColorType()
|
|
||||||
{
|
{
|
||||||
m_color = color;
|
m_color = color;
|
||||||
|
|
||||||
@@ -436,7 +382,37 @@ ThemeColorType::ThemeColorType(Window* parent, uint32_t color) : ColorType()
|
|||||||
COLOR_THEME_DISABLED_INDEX);
|
COLOR_THEME_DISABLED_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ThemeColorType::getRGB() { return m_color; }
|
uint32_t getRGB() { return m_color; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
uint32_t m_color;
|
||||||
|
|
||||||
|
void makeButton(Window* parent, uint16_t color)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
lv_event_send(parent->getParent()->getParent()->getLvObj(),
|
||||||
|
LV_EVENT_VALUE_CHANGED, nullptr);
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void makeButtonsRow(Window* parent, uint16_t c1, uint16_t c2, uint16_t c3)
|
||||||
|
{
|
||||||
|
auto hbox = new Window(parent, rect_t{});
|
||||||
|
hbox->padAll(PAD_TINY);
|
||||||
|
hbox->setFlexLayout(LV_FLEX_FLOW_ROW, PAD_MEDIUM);
|
||||||
|
lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_CENTER,
|
||||||
|
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND);
|
||||||
|
|
||||||
|
makeButton(hbox, c1);
|
||||||
|
makeButton(hbox, c2);
|
||||||
|
if (c3 != c2) makeButton(hbox, c3);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
////// ColorEditor Base class
|
////// ColorEditor Base class
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ class ColorEditorPopup : public BaseDialog
|
|||||||
updateColor(color);
|
updateColor(color);
|
||||||
|
|
||||||
hbox = new Window(vbox, rect_t{});
|
hbox = new Window(vbox, rect_t{});
|
||||||
|
hbox->padAll(PAD_TINY);
|
||||||
hbox->setFlexLayout(LV_FLEX_FLOW_ROW, PAD_MEDIUM);
|
hbox->setFlexLayout(LV_FLEX_FLOW_ROW, PAD_MEDIUM);
|
||||||
lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_CENTER,
|
lv_obj_set_flex_align(hbox->getLvObj(), LV_FLEX_ALIGN_CENTER,
|
||||||
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND);
|
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_SPACE_AROUND);
|
||||||
|
|||||||
@@ -239,9 +239,11 @@ EdgeTxStyles::EdgeTxStyles()
|
|||||||
lv_style_init(&border_color_normal);
|
lv_style_init(&border_color_normal);
|
||||||
lv_style_init(&border_color_focus);
|
lv_style_init(&border_color_focus);
|
||||||
lv_style_init(&border_color_active);
|
lv_style_init(&border_color_active);
|
||||||
|
lv_style_init(&border_color_edit);
|
||||||
lv_style_init(&outline_color_light);
|
lv_style_init(&outline_color_light);
|
||||||
lv_style_init(&outline_color_normal);
|
lv_style_init(&outline_color_normal);
|
||||||
lv_style_init(&outline_color_focus);
|
lv_style_init(&outline_color_focus);
|
||||||
|
lv_style_init(&outline_color_edit);
|
||||||
lv_style_init(&arc_color);
|
lv_style_init(&arc_color);
|
||||||
lv_style_init(&graph_border);
|
lv_style_init(&graph_border);
|
||||||
lv_style_init(&graph_dashed);
|
lv_style_init(&graph_dashed);
|
||||||
@@ -336,6 +338,8 @@ void EdgeTxStyles::applyColors()
|
|||||||
makeLvColor(COLOR_THEME_FOCUS));
|
makeLvColor(COLOR_THEME_FOCUS));
|
||||||
lv_style_set_border_color(&border_color_active,
|
lv_style_set_border_color(&border_color_active,
|
||||||
makeLvColor(COLOR_THEME_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,
|
lv_style_set_outline_color(&outline_color_light,
|
||||||
makeLvColor(COLOR_THEME_SECONDARY3));
|
makeLvColor(COLOR_THEME_SECONDARY3));
|
||||||
@@ -343,6 +347,8 @@ void EdgeTxStyles::applyColors()
|
|||||||
makeLvColor(COLOR_THEME_SECONDARY2));
|
makeLvColor(COLOR_THEME_SECONDARY2));
|
||||||
lv_style_set_outline_color(&outline_color_focus,
|
lv_style_set_outline_color(&outline_color_focus,
|
||||||
makeLvColor(COLOR_THEME_FOCUS));
|
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));
|
lv_style_set_arc_color(&arc_color, makeLvColor(COLOR_THEME_SECONDARY1));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,9 +128,11 @@ class EdgeTxStyles
|
|||||||
lv_style_t border_color_white;
|
lv_style_t border_color_white;
|
||||||
lv_style_t border_color_focus;
|
lv_style_t border_color_focus;
|
||||||
lv_style_t border_color_active;
|
lv_style_t border_color_active;
|
||||||
|
lv_style_t border_color_edit;
|
||||||
lv_style_t outline_color_light;
|
lv_style_t outline_color_light;
|
||||||
lv_style_t outline_color_normal;
|
lv_style_t outline_color_normal;
|
||||||
lv_style_t outline_color_focus;
|
lv_style_t outline_color_focus;
|
||||||
|
lv_style_t outline_color_edit;
|
||||||
lv_style_t bg_color_grey;
|
lv_style_t bg_color_grey;
|
||||||
lv_style_t arc_color;
|
lv_style_t arc_color;
|
||||||
lv_style_t graph_border;
|
lv_style_t graph_border;
|
||||||
|
|||||||
Reference in New Issue
Block a user