Skip to content

Commit 8b21616

Browse files
philmozpfeerick
authored andcommitted
fix(color): HSV & RGB color edit bars do not scale correctly to 800x480 LCD size (#7695)
(cherry picked from commit faa6095) (cherry picked from commit 4ef75e2d1adbe41eb78b3f237ffc7ba1d785bc6d)
1 parent 0c70b8b commit 8b21616

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

radio/src/gui/colorlcd/controls/color_editor.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ class ColorBar : public FormField
5252

5353
int valueToScreen(int val)
5454
{
55-
auto h = height() - 4; // exclude border
55+
auto maxY = height() - PAD_BORDER * 2 - 1; // exclude border
5656

57-
int scaledValue = (val * h + maxValue / 2) / maxValue;
57+
int scaledValue = (val * maxY + maxValue / 2) / maxValue;
5858
return scaledValue;
5959
}
6060

6161
uint32_t screenToValue(int pos)
6262
{
63-
auto h = height() - 4; // exclude border
63+
auto maxY = height() - PAD_BORDER * 2 - 1; // exclude border
6464

6565
// range check
66-
pos = min<int>(pos, h);
66+
pos = min<int>(pos, maxY);
6767
pos = max<int>(pos, 0);
6868

69-
uint32_t scaledValue = ((pos * maxValue + h / 2) / h);
69+
uint32_t scaledValue = ((pos * maxValue + maxY / 2) / maxY);
7070
return scaledValue;
7171
}
7272

@@ -147,17 +147,23 @@ class ColorBar : public FormField
147147

148148
auto area = dsc->draw_area;
149149
lv_point_t p1, p2;
150-
int h = area->y2 - area->y1 - 4;
150+
int h = area->y2 - area->y1 - PAD_BORDER * 2;
151+
lv_coord_t x1 = area->x1 + PAD_BORDER;
152+
lv_coord_t x2 = area->x2 + 1 - PAD_BORDER;
153+
lv_coord_t y = area->y1 + PAD_BORDER;
151154

152155
// draw background gradient
153156
for (int i = 0; i <= h; i += 1) {
154-
p1.y = p2.y = i + area->y1 + 2;
155-
if (i == 0 || i == h) {
156-
p1.x = area->x1 + 3;
157-
p2.x = area->x2 - 2;
157+
p1.y = p2.y = i + y;
158+
if (i < PAD_BORDER) {
159+
p1.x = x1 + PAD_BORDER - i;
160+
p2.x = x2 - PAD_BORDER + i;
161+
} else if (i > h - PAD_BORDER) {
162+
p1.x = x1 + PAD_BORDER - (h - i);
163+
p2.x = x2 - PAD_BORDER + (h - i);
158164
} else {
159-
p1.x = area->x1 + 2;
160-
p2.x = area->x2 - 1;
165+
p1.x = x1;
166+
p2.x = x2;
161167
}
162168
auto c = bar->getRGB(bar->screenToValue(i));
163169
line_dsc.color = lv_color_make(GET_RED32(c), GET_GREEN32(c), GET_BLUE32(c));
@@ -170,7 +176,7 @@ class ColorBar : public FormField
170176
cursor_area.x2 = cursor_area.x1 + ColorEditor::CRSR_SZ - 1;
171177

172178
auto pos = bar->valueToScreen(bar->value);
173-
cursor_area.y1 = area->y1 + pos - PAD_THREE;
179+
cursor_area.y1 = area->y1 + PAD_BORDER + pos - (ColorEditor::CRSR_SZ / 2);
174180
cursor_area.y2 = cursor_area.y1 + ColorEditor::CRSR_SZ - 1;
175181

176182
lv_draw_rect_dsc_t cursor_dsc;

radio/src/gui/colorlcd/controls/color_editor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ColorEditor : public Window
5252
static LAYOUT_VAL_SCALED(BAR_HEIGHT_OFFSET, 25)
5353
static LAYOUT_VAL_SCALED(LBL_YO, 9)
5454
static LAYOUT_VAL_SCALED(VAL_XO, 10)
55-
static LAYOUT_VAL_SCALED_EVEN(CRSR_SZ, 10)
55+
static LAYOUT_VAL_SCALED_ODD(CRSR_SZ, 11)
5656

5757
protected:
5858
ColorType* _colorType = nullptr;

0 commit comments

Comments
 (0)