mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 23:08: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:
@@ -68,10 +68,7 @@ public:
|
||||
for (int i = 0; i < ITEM_COUNT; i++) {
|
||||
int y = start_y + i * item_h;
|
||||
bool sel = (i == _sel);
|
||||
if (sel) {
|
||||
display.fillRect(0, y - 1, display.width(), item_h);
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
}
|
||||
display.drawSelectionRow(0, y - 1, display.width(), item_h, sel);
|
||||
display.setCursor(2, y);
|
||||
display.print(labels[i]);
|
||||
display.setCursor(val_x, y);
|
||||
|
||||
@@ -52,13 +52,7 @@ public:
|
||||
for (int i = 0; i < FIELD_SLOTS; i++) {
|
||||
int y = start_y + i * item_h;
|
||||
bool sel = (i == _sel);
|
||||
if (sel) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.fillRect(0, y - 1, display.width(), item_h);
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
display.drawSelectionRow(0, y - 1, display.width(), item_h, sel);
|
||||
display.setCursor(2, y);
|
||||
display.print(labels[i]);
|
||||
display.setCursor(val_x, y);
|
||||
|
||||
@@ -109,13 +109,7 @@ struct KeyboardWidget {
|
||||
if (caps && ch >= 'a' && ch <= 'z') ch = ch - 'a' + 'A';
|
||||
char ch_buf[2] = { ch == ' ' ? '_' : ch, '\0' };
|
||||
int cx = c * cell_w;
|
||||
if (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.drawSelectionRow(cx, y - 1, cell_w - 1, cell_h, sel);
|
||||
display.setCursor(cx + (cell_w - cw) / 2, y);
|
||||
display.print(ch_buf);
|
||||
}
|
||||
@@ -127,13 +121,7 @@ struct KeyboardWidget {
|
||||
bool sel = (row == KB_ROWS_CHAR && col == i);
|
||||
bool active = (i == 0 && caps);
|
||||
int sx = i * spec_w;
|
||||
if (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);
|
||||
}
|
||||
display.drawSelectionRow(sx, spec_y - 1, spec_w - 1, cell_h, sel || active);
|
||||
int tw = display.getTextWidth(spec[i]);
|
||||
display.setCursor(sx + (spec_w - tw) / 2, spec_y);
|
||||
display.print(spec[i]);
|
||||
|
||||
@@ -473,13 +473,7 @@ public:
|
||||
int y = start_y + i * item_h;
|
||||
const Entry& e = _entries[idx];
|
||||
|
||||
if (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.drawSelectionRow(0, y - 1, display.width(), item_h - 1, sel);
|
||||
|
||||
char filt[32];
|
||||
display.translateUTF8ToBlocks(filt, e.name, sizeof(filt));
|
||||
|
||||
@@ -491,13 +491,7 @@ public:
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int y = start_y + i * item_h;
|
||||
bool sel = (i == _mode_sel);
|
||||
if (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.drawSelectionRow(0, y - 1, display.width(), item_h - 1, sel);
|
||||
display.setCursor(0, y);
|
||||
display.print(sel ? ">" : " ");
|
||||
display.setCursor(cw + 2, y);
|
||||
@@ -527,13 +521,7 @@ public:
|
||||
bool sel = (list_idx == _contact_sel);
|
||||
int y = start_y + i * item_h;
|
||||
|
||||
if (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.drawSelectionRow(0, y - 1, display.width(), item_h - 1, sel);
|
||||
|
||||
ContactInfo c;
|
||||
if (the_mesh.getContactByIdx(mesh_idx, c)) {
|
||||
@@ -576,13 +564,7 @@ public:
|
||||
bool sel = (list_idx == _channel_sel);
|
||||
int y = start_y + i * item_h;
|
||||
|
||||
if (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.drawSelectionRow(0, y - 1, display.width(), item_h - 1, sel);
|
||||
display.setCursor(0, y);
|
||||
display.print(sel ? ">" : " ");
|
||||
ChannelDetails ch;
|
||||
@@ -855,13 +837,7 @@ public:
|
||||
bool sel = (idx == _msg_sel);
|
||||
int y = start_y + i * item_h;
|
||||
|
||||
if (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.drawSelectionRow(0, y - 1, display.width(), item_h - 1, sel);
|
||||
display.setCursor(0, y);
|
||||
display.print(sel ? ">" : " ");
|
||||
|
||||
|
||||
@@ -119,13 +119,7 @@ public:
|
||||
display.print(label);
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
} else if (ni == _len && _len < MAX_NOTES) {
|
||||
if (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.drawSelectionRow(cx, notes_y, cell_w - 1, cell_h, sel);
|
||||
display.setCursor(cx + (cell_w - cw) / 2, notes_y + 3);
|
||||
display.print("+");
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
@@ -164,10 +158,7 @@ public:
|
||||
if (item >= M_COUNT) break;
|
||||
int iy = my + 2 + i * menu_ih;
|
||||
bool sel = (item == _menu_sel);
|
||||
if (sel) {
|
||||
display.fillRect(mx + 1, iy - 1, mw - 2, menu_ih);
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
}
|
||||
display.drawSelectionRow(mx + 1, iy - 1, mw - 2, menu_ih, sel);
|
||||
display.setCursor(mx + 4, iy);
|
||||
if (item == M_PLAY_STOP)
|
||||
display.print(_task->isMelodyPlaying() ? "Stop" : "Play");
|
||||
|
||||
@@ -316,14 +316,7 @@ class SettingsScreen : public UIScreen {
|
||||
}
|
||||
|
||||
bool sel = (item == _selected);
|
||||
|
||||
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.drawSelectionRow(0, y - 1, display.width(), display.lineStep(), sel);
|
||||
|
||||
display.setCursor(0, y);
|
||||
display.print(sel ? ">" : " ");
|
||||
|
||||
@@ -25,13 +25,7 @@ public:
|
||||
for (int i = 0; i < ITEM_COUNT; i++) {
|
||||
int y = start_y + i * item_h;
|
||||
bool sel = (i == _sel);
|
||||
if (sel) {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
display.fillRect(0, y - 1, display.width(), item_h);
|
||||
display.setColor(DisplayDriver::DARK);
|
||||
} else {
|
||||
display.setColor(DisplayDriver::LIGHT);
|
||||
}
|
||||
display.drawSelectionRow(0, y - 1, display.width(), item_h, sel);
|
||||
display.setCursor(0, y);
|
||||
display.print(sel ? ">" : " ");
|
||||
display.setCursor(cw + 2, y);
|
||||
|
||||
Reference in New Issue
Block a user