mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-02 02:06:11 +00:00
refactor(ui): drawSelectionRow helper for the 5-line invert/restore pattern
Eight screens repeated the same if/else block to invert the row background for selected items. Add DisplayDriver::drawSelectionRow that sets LIGHT, optionally fills the rect, and leaves the colour as DARK when sel (so the caller's text renders inverted). 61 lines removed across SettingsScreen, KeyboardWidget (cells + special row), ToolsScreen, DashboardConfigScreen, BotScreen, RingtoneEditorScreen (note slots + menu), NearbyScreen, QuickMsgScreen (4 list views). Card-style rows (QuickMsg hist, NearbyScreen discover, RingtoneEditor notes display) keep their original drawRect/partial-fill outline for unselected — they don't match the simple-invert pattern. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
52a7081a13
commit
d981f93e6e
@@ -68,10 +68,7 @@ public:
|
|||||||
for (int i = 0; i < ITEM_COUNT; i++) {
|
for (int i = 0; i < ITEM_COUNT; i++) {
|
||||||
int y = start_y + i * item_h;
|
int y = start_y + i * item_h;
|
||||||
bool sel = (i == _sel);
|
bool sel = (i == _sel);
|
||||||
if (sel) {
|
display.drawSelectionRow(0, y - 1, display.width(), item_h, sel);
|
||||||
display.fillRect(0, y - 1, display.width(), item_h);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
}
|
|
||||||
display.setCursor(2, y);
|
display.setCursor(2, y);
|
||||||
display.print(labels[i]);
|
display.print(labels[i]);
|
||||||
display.setCursor(val_x, y);
|
display.setCursor(val_x, y);
|
||||||
|
|||||||
@@ -52,13 +52,7 @@ public:
|
|||||||
for (int i = 0; i < FIELD_SLOTS; i++) {
|
for (int i = 0; i < FIELD_SLOTS; i++) {
|
||||||
int y = start_y + i * item_h;
|
int y = start_y + i * item_h;
|
||||||
bool sel = (i == _sel);
|
bool sel = (i == _sel);
|
||||||
if (sel) {
|
display.drawSelectionRow(0, y - 1, display.width(), item_h, sel);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(0, y - 1, display.width(), item_h);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
display.setCursor(2, y);
|
display.setCursor(2, y);
|
||||||
display.print(labels[i]);
|
display.print(labels[i]);
|
||||||
display.setCursor(val_x, y);
|
display.setCursor(val_x, y);
|
||||||
|
|||||||
@@ -109,13 +109,7 @@ struct KeyboardWidget {
|
|||||||
if (caps && ch >= 'a' && ch <= 'z') ch = ch - 'a' + 'A';
|
if (caps && ch >= 'a' && ch <= 'z') ch = ch - 'a' + 'A';
|
||||||
char ch_buf[2] = { ch == ' ' ? '_' : ch, '\0' };
|
char ch_buf[2] = { ch == ' ' ? '_' : ch, '\0' };
|
||||||
int cx = c * cell_w;
|
int cx = c * cell_w;
|
||||||
if (sel) {
|
display.drawSelectionRow(cx, y - 1, cell_w - 1, cell_h, sel);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(cx, y - 1, cell_w - 1, cell_h);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
display.setCursor(cx + (cell_w - cw) / 2, y);
|
display.setCursor(cx + (cell_w - cw) / 2, y);
|
||||||
display.print(ch_buf);
|
display.print(ch_buf);
|
||||||
}
|
}
|
||||||
@@ -127,13 +121,7 @@ struct KeyboardWidget {
|
|||||||
bool sel = (row == KB_ROWS_CHAR && col == i);
|
bool sel = (row == KB_ROWS_CHAR && col == i);
|
||||||
bool active = (i == 0 && caps);
|
bool active = (i == 0 && caps);
|
||||||
int sx = i * spec_w;
|
int sx = i * spec_w;
|
||||||
if (sel || active) {
|
display.drawSelectionRow(sx, spec_y - 1, spec_w - 1, cell_h, sel || active);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(sx, spec_y - 1, spec_w - 1, cell_h);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
int tw = display.getTextWidth(spec[i]);
|
int tw = display.getTextWidth(spec[i]);
|
||||||
display.setCursor(sx + (spec_w - tw) / 2, spec_y);
|
display.setCursor(sx + (spec_w - tw) / 2, spec_y);
|
||||||
display.print(spec[i]);
|
display.print(spec[i]);
|
||||||
|
|||||||
@@ -473,13 +473,7 @@ public:
|
|||||||
int y = start_y + i * item_h;
|
int y = start_y + i * item_h;
|
||||||
const Entry& e = _entries[idx];
|
const Entry& e = _entries[idx];
|
||||||
|
|
||||||
if (sel) {
|
display.drawSelectionRow(0, y - 1, display.width(), item_h - 1, sel);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(0, y - 1, display.width(), item_h - 1);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
char filt[32];
|
char filt[32];
|
||||||
display.translateUTF8ToBlocks(filt, e.name, sizeof(filt));
|
display.translateUTF8ToBlocks(filt, e.name, sizeof(filt));
|
||||||
|
|||||||
@@ -491,13 +491,7 @@ public:
|
|||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
int y = start_y + i * item_h;
|
int y = start_y + i * item_h;
|
||||||
bool sel = (i == _mode_sel);
|
bool sel = (i == _mode_sel);
|
||||||
if (sel) {
|
display.drawSelectionRow(0, y - 1, display.width(), item_h - 1, sel);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(0, y - 1, display.width(), item_h - 1);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
display.setCursor(0, y);
|
display.setCursor(0, y);
|
||||||
display.print(sel ? ">" : " ");
|
display.print(sel ? ">" : " ");
|
||||||
display.setCursor(cw + 2, y);
|
display.setCursor(cw + 2, y);
|
||||||
@@ -527,13 +521,7 @@ public:
|
|||||||
bool sel = (list_idx == _contact_sel);
|
bool sel = (list_idx == _contact_sel);
|
||||||
int y = start_y + i * item_h;
|
int y = start_y + i * item_h;
|
||||||
|
|
||||||
if (sel) {
|
display.drawSelectionRow(0, y - 1, display.width(), item_h - 1, sel);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(0, y - 1, display.width(), item_h - 1);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
ContactInfo c;
|
ContactInfo c;
|
||||||
if (the_mesh.getContactByIdx(mesh_idx, c)) {
|
if (the_mesh.getContactByIdx(mesh_idx, c)) {
|
||||||
@@ -576,13 +564,7 @@ public:
|
|||||||
bool sel = (list_idx == _channel_sel);
|
bool sel = (list_idx == _channel_sel);
|
||||||
int y = start_y + i * item_h;
|
int y = start_y + i * item_h;
|
||||||
|
|
||||||
if (sel) {
|
display.drawSelectionRow(0, y - 1, display.width(), item_h - 1, sel);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(0, y - 1, display.width(), item_h - 1);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
display.setCursor(0, y);
|
display.setCursor(0, y);
|
||||||
display.print(sel ? ">" : " ");
|
display.print(sel ? ">" : " ");
|
||||||
ChannelDetails ch;
|
ChannelDetails ch;
|
||||||
@@ -855,13 +837,7 @@ public:
|
|||||||
bool sel = (idx == _msg_sel);
|
bool sel = (idx == _msg_sel);
|
||||||
int y = start_y + i * item_h;
|
int y = start_y + i * item_h;
|
||||||
|
|
||||||
if (sel) {
|
display.drawSelectionRow(0, y - 1, display.width(), item_h - 1, sel);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(0, y - 1, display.width(), item_h - 1);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
display.setCursor(0, y);
|
display.setCursor(0, y);
|
||||||
display.print(sel ? ">" : " ");
|
display.print(sel ? ">" : " ");
|
||||||
|
|
||||||
|
|||||||
@@ -119,13 +119,7 @@ public:
|
|||||||
display.print(label);
|
display.print(label);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
} else if (ni == _len && _len < MAX_NOTES) {
|
} else if (ni == _len && _len < MAX_NOTES) {
|
||||||
if (sel) {
|
display.drawSelectionRow(cx, notes_y, cell_w - 1, cell_h, sel);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(cx, notes_y, cell_w - 1, cell_h);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
display.setCursor(cx + (cell_w - cw) / 2, notes_y + 3);
|
display.setCursor(cx + (cell_w - cw) / 2, notes_y + 3);
|
||||||
display.print("+");
|
display.print("+");
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
@@ -164,10 +158,7 @@ public:
|
|||||||
if (item >= M_COUNT) break;
|
if (item >= M_COUNT) break;
|
||||||
int iy = my + 2 + i * menu_ih;
|
int iy = my + 2 + i * menu_ih;
|
||||||
bool sel = (item == _menu_sel);
|
bool sel = (item == _menu_sel);
|
||||||
if (sel) {
|
display.drawSelectionRow(mx + 1, iy - 1, mw - 2, menu_ih, sel);
|
||||||
display.fillRect(mx + 1, iy - 1, mw - 2, menu_ih);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
}
|
|
||||||
display.setCursor(mx + 4, iy);
|
display.setCursor(mx + 4, iy);
|
||||||
if (item == M_PLAY_STOP)
|
if (item == M_PLAY_STOP)
|
||||||
display.print(_task->isMelodyPlaying() ? "Stop" : "Play");
|
display.print(_task->isMelodyPlaying() ? "Stop" : "Play");
|
||||||
|
|||||||
@@ -316,14 +316,7 @@ class SettingsScreen : public UIScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool sel = (item == _selected);
|
bool sel = (item == _selected);
|
||||||
|
display.drawSelectionRow(0, y - 1, display.width(), display.lineStep(), sel);
|
||||||
if (sel) {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(0, y - 1, display.width(), display.lineStep());
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
display.setCursor(0, y);
|
display.setCursor(0, y);
|
||||||
display.print(sel ? ">" : " ");
|
display.print(sel ? ">" : " ");
|
||||||
|
|||||||
@@ -25,13 +25,7 @@ public:
|
|||||||
for (int i = 0; i < ITEM_COUNT; i++) {
|
for (int i = 0; i < ITEM_COUNT; i++) {
|
||||||
int y = start_y + i * item_h;
|
int y = start_y + i * item_h;
|
||||||
bool sel = (i == _sel);
|
bool sel = (i == _sel);
|
||||||
if (sel) {
|
display.drawSelectionRow(0, y - 1, display.width(), item_h, sel);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
display.fillRect(0, y - 1, display.width(), item_h);
|
|
||||||
display.setColor(DisplayDriver::DARK);
|
|
||||||
} else {
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
|
||||||
}
|
|
||||||
display.setCursor(0, y);
|
display.setCursor(0, y);
|
||||||
display.print(sel ? ">" : " ");
|
display.print(sel ? ">" : " ");
|
||||||
display.setCursor(cw + 2, y);
|
display.setCursor(cw + 2, y);
|
||||||
|
|||||||
@@ -150,6 +150,18 @@ public:
|
|||||||
translateUTF8Static(dest, src, dest_size);
|
translateUTF8Static(dest, src, dest_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Common selection-row pattern: when sel, fills (x,y,w,h) with ink and sets
|
||||||
|
// colour to DARK so the next text render appears inverted; when not sel,
|
||||||
|
// just sets ink colour to LIGHT. Replaces the 5-line if/else copy-paste
|
||||||
|
// present in every list-style screen.
|
||||||
|
void drawSelectionRow(int x, int y, int w, int h, bool sel) {
|
||||||
|
setColor(LIGHT);
|
||||||
|
if (sel) {
|
||||||
|
fillRect(x, y, w, h);
|
||||||
|
setColor(DARK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Advance a UTF-8 pointer by one codepoint, returning the decoded value.
|
// Advance a UTF-8 pointer by one codepoint, returning the decoded value.
|
||||||
// Invalid sequences return 0xFFFD and consume trailing continuation bytes.
|
// Invalid sequences return 0xFFFD and consume trailing continuation bytes.
|
||||||
static uint32_t decodeCodepoint(const uint8_t*& p) {
|
static uint32_t decodeCodepoint(const uint8_t*& p) {
|
||||||
|
|||||||
Reference in New Issue
Block a user