mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-31 17:26:12 +00:00
feat: dynamic font-adaptive layout and Lemon font icon support for SH1106
- Add getCharWidth()/getLineHeight() virtual methods to DisplayDriver so all layout math adapts to whatever font is active - Fix Lemon font baseline offset from +8 to +6 (cap height, not FONT_ASCENT) - Add LemonIcons.h with Private Use Area glyph table; U+E03B mute icon rendered via drawLemonChar icon lookup - FullscreenMsgView: compute wrap width and visible lines dynamically from display font metrics instead of hardcoded constants - SettingsScreen and MessagesScreen: replace hardcoded ITEM_H/VISIBLE with members computed at render() time from getLineHeight() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b8ac4245cf
commit
24c8dcad72
@@ -3,10 +3,8 @@
|
|||||||
#include <helpers/ui/DisplayDriver.h>
|
#include <helpers/ui/DisplayDriver.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
static const int FS_CHARS = 21;
|
static const int FS_CHARS_MAX = 32; // max buffer per line (larger than any font needs)
|
||||||
static const int FS_LINE_H = 9;
|
static const int FS_START_Y = 12; // header height (fixed, not font-dependent)
|
||||||
static const int FS_START_Y = 12;
|
|
||||||
static const int FS_VISIBLE = (64 - FS_START_Y) / FS_LINE_H;
|
|
||||||
|
|
||||||
struct FullscreenMsgView {
|
struct FullscreenMsgView {
|
||||||
int scroll;
|
int scroll;
|
||||||
@@ -18,22 +16,23 @@ struct FullscreenMsgView {
|
|||||||
|
|
||||||
void begin() { scroll = 0; active = true; }
|
void begin() { scroll = 0; active = true; }
|
||||||
|
|
||||||
static int wrapLines(const char* text, char out[][FS_CHARS + 1], int max_lines) {
|
static int wrapLines(const char* text, int chars, char out[][FS_CHARS_MAX], int max_lines) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
const char* p = text;
|
const char* p = text;
|
||||||
while (*p && count < max_lines) {
|
while (*p && count < max_lines) {
|
||||||
int len = strlen(p);
|
int len = strlen(p);
|
||||||
if (len <= FS_CHARS) {
|
if (len <= chars) {
|
||||||
strncpy(out[count++], p, FS_CHARS);
|
strncpy(out[count++], p, FS_CHARS_MAX - 1);
|
||||||
out[count - 1][len] = '\0';
|
out[count - 1][len < FS_CHARS_MAX ? len : FS_CHARS_MAX - 1] = '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int brk = FS_CHARS;
|
int brk = chars;
|
||||||
for (int i = FS_CHARS - 1; i > 0; i--) {
|
for (int i = chars - 1; i > 0; i--) {
|
||||||
if (p[i] == ' ') { brk = i; break; }
|
if (p[i] == ' ') { brk = i; break; }
|
||||||
}
|
}
|
||||||
strncpy(out[count], p, brk);
|
int copy = brk < FS_CHARS_MAX - 1 ? brk : FS_CHARS_MAX - 1;
|
||||||
out[count++][brk] = '\0';
|
strncpy(out[count], p, copy);
|
||||||
|
out[count++][copy] = '\0';
|
||||||
p += brk + (p[brk] == ' ' ? 1 : 0);
|
p += brk + (p[brk] == ' ' ? 1 : 0);
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
@@ -42,19 +41,23 @@ struct FullscreenMsgView {
|
|||||||
int render(DisplayDriver& display, const char* sender, const char* text,
|
int render(DisplayDriver& display, const char* sender, const char* text,
|
||||||
bool has_prev, bool has_next) {
|
bool has_prev, bool has_next) {
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
|
const int lineH = display.getLineHeight();
|
||||||
|
const int chars = (display.width() - 6) / display.getCharWidth();
|
||||||
|
const int visible = (display.height() - FS_START_Y - lineH) / lineH;
|
||||||
|
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.fillRect(0, 0, display.width(), 10);
|
display.fillRect(0, 0, display.width(), 10);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
display.drawTextEllipsized(2, 1, display.width() - 4, sender);
|
display.drawTextEllipsized(2, 1, display.width() - 4, sender);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
|
||||||
char lines[12][FS_CHARS + 1];
|
char lines[12][FS_CHARS_MAX];
|
||||||
int lcount = wrapLines(text, lines, 12);
|
int lcount = wrapLines(text, chars, lines, 12);
|
||||||
int max_scroll = lcount > FS_VISIBLE ? lcount - FS_VISIBLE : 0;
|
int max_scroll = lcount > visible ? lcount - visible : 0;
|
||||||
if (scroll > max_scroll) scroll = max_scroll;
|
if (scroll > max_scroll) scroll = max_scroll;
|
||||||
|
|
||||||
for (int i = 0; i < FS_VISIBLE && (scroll + i) < lcount; i++) {
|
for (int i = 0; i < visible && (scroll + i) < lcount; i++) {
|
||||||
display.setCursor(0, FS_START_Y + i * FS_LINE_H);
|
display.setCursor(0, FS_START_Y + i * lineH);
|
||||||
display.print(lines[scroll + i]);
|
display.print(lines[scroll + i]);
|
||||||
}
|
}
|
||||||
if (scroll > 0) {
|
if (scroll > 0) {
|
||||||
@@ -62,15 +65,16 @@ struct FullscreenMsgView {
|
|||||||
display.print("^");
|
display.print("^");
|
||||||
}
|
}
|
||||||
if (scroll < max_scroll) {
|
if (scroll < max_scroll) {
|
||||||
display.setCursor(display.width() - 6, FS_START_Y + (FS_VISIBLE - 1) * FS_LINE_H);
|
display.setCursor(display.width() - 6, FS_START_Y + (visible - 1) * lineH);
|
||||||
display.print("v");
|
display.print("v");
|
||||||
}
|
}
|
||||||
|
const int nav_y = display.height() - lineH;
|
||||||
if (has_next) {
|
if (has_next) {
|
||||||
display.setCursor(0, 56);
|
display.setCursor(0, nav_y);
|
||||||
display.print("<");
|
display.print("<");
|
||||||
}
|
}
|
||||||
if (has_prev) {
|
if (has_prev) {
|
||||||
display.setCursor(display.width() - 6, 56);
|
display.setCursor(display.width() - 6, nav_y);
|
||||||
display.print(">");
|
display.print(">");
|
||||||
}
|
}
|
||||||
return 300;
|
return 300;
|
||||||
|
|||||||
@@ -165,11 +165,10 @@ class SettingsScreen : public UIScreen {
|
|||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int VISIBLE_ITEMS = 4;
|
|
||||||
static const int ITEM_H = 11;
|
|
||||||
static const int START_Y = 12;
|
static const int START_Y = 12;
|
||||||
static const int VAL_X = 80;
|
static const int VAL_X = 80;
|
||||||
|
|
||||||
|
int _visible_items, _item_h;
|
||||||
int _selected;
|
int _selected;
|
||||||
int _scroll;
|
int _scroll;
|
||||||
bool _dirty;
|
bool _dirty;
|
||||||
@@ -338,7 +337,7 @@ class SettingsScreen : public UIScreen {
|
|||||||
|
|
||||||
if (sel) {
|
if (sel) {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.fillRect(0, y - 1, display.width(), ITEM_H);
|
display.fillRect(0, y - 1, display.width(), _item_h);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
} else {
|
} else {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
@@ -446,13 +445,15 @@ class SettingsScreen : public UIScreen {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
SettingsScreen(UITask* task)
|
SettingsScreen(UITask* task)
|
||||||
: _task(task), _selected(BRIGHTNESS), _scroll(0), _dirty(false), _edit_slot(-1) {}
|
: _task(task), _visible_items(4), _item_h(11), _selected(BRIGHTNESS), _scroll(0), _dirty(false), _edit_slot(-1) {}
|
||||||
|
|
||||||
|
|
||||||
void markClean() { _dirty = false; }
|
void markClean() { _dirty = false; }
|
||||||
|
|
||||||
int render(DisplayDriver& display) override {
|
int render(DisplayDriver& display) override {
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
|
_item_h = display.getLineHeight() + 3;
|
||||||
|
_visible_items = (display.height() - START_Y) / _item_h;
|
||||||
|
|
||||||
if (_edit_slot >= 0) {
|
if (_edit_slot >= 0) {
|
||||||
return _kb.render(display);
|
return _kb.render(display);
|
||||||
@@ -462,8 +463,8 @@ public:
|
|||||||
display.drawTextCentered(display.width() / 2, 0, "SETTINGS");
|
display.drawTextCentered(display.width() / 2, 0, "SETTINGS");
|
||||||
display.fillRect(0, 10, display.width(), 1);
|
display.fillRect(0, 10, display.width(), 1);
|
||||||
|
|
||||||
for (int i = 0; i < VISIBLE_ITEMS && (_scroll + i) < SettingItem::Count; i++) {
|
for (int i = 0; i < _visible_items && (_scroll + i) < SettingItem::Count; i++) {
|
||||||
renderItem(display, _scroll + i, START_Y + i * ITEM_H);
|
renderItem(display, _scroll + i, START_Y + i * _item_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
// scroll indicators
|
// scroll indicators
|
||||||
@@ -472,9 +473,9 @@ public:
|
|||||||
display.setCursor(display.width() - 6, START_Y);
|
display.setCursor(display.width() - 6, START_Y);
|
||||||
display.print("^");
|
display.print("^");
|
||||||
}
|
}
|
||||||
if (_scroll + VISIBLE_ITEMS < SettingItem::Count) {
|
if (_scroll + _visible_items < SettingItem::Count) {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.setCursor(display.width() - 6, START_Y + (VISIBLE_ITEMS - 1) * ITEM_H);
|
display.setCursor(display.width() - 6, START_Y + (_visible_items - 1) * _item_h);
|
||||||
display.print("v");
|
display.print("v");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,7 +513,7 @@ public:
|
|||||||
int next = nextSelectable(_selected);
|
int next = nextSelectable(_selected);
|
||||||
if (next != _selected) {
|
if (next != _selected) {
|
||||||
_selected = next;
|
_selected = next;
|
||||||
if (_selected >= _scroll + VISIBLE_ITEMS) _scroll = _selected - VISIBLE_ITEMS + 1;
|
if (_selected >= _scroll + _visible_items) _scroll = _selected - _visible_items + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -690,14 +691,11 @@ class QuickMsgScreen : public UIScreen {
|
|||||||
int _dm_hist_sel, _dm_hist_scroll;
|
int _dm_hist_sel, _dm_hist_scroll;
|
||||||
FullscreenMsgView _dm_fs;
|
FullscreenMsgView _dm_fs;
|
||||||
|
|
||||||
static const int VISIBLE = 4;
|
|
||||||
static const int ITEM_H = 12;
|
|
||||||
static const int START_Y = 12;
|
static const int START_Y = 12;
|
||||||
static const int HIST_VISIBLE = 2; // 2-line boxed history entries
|
|
||||||
static const int HIST_ITEM_H = 21; // box(19) + gap(2)
|
|
||||||
static const int HIST_BOX_H = 19;
|
|
||||||
static const int HIST_START_Y = 11;
|
static const int HIST_START_Y = 11;
|
||||||
|
|
||||||
|
int _line_h, _item_h, _visible, _hist_visible, _hist_item_h, _hist_box_h;
|
||||||
|
|
||||||
void expandMsg(const char* tmpl, char* out, int out_len) const {
|
void expandMsg(const char* tmpl, char* out, int out_len) const {
|
||||||
double lat = 0, lon = 0;
|
double lat = 0, lon = 0;
|
||||||
bool gps_valid = false;
|
bool gps_valid = false;
|
||||||
@@ -735,8 +733,8 @@ class QuickMsgScreen : public UIScreen {
|
|||||||
display.setCursor(display.width() - 6, START_Y);
|
display.setCursor(display.width() - 6, START_Y);
|
||||||
display.print("^");
|
display.print("^");
|
||||||
}
|
}
|
||||||
if (scroll + VISIBLE < count) {
|
if (scroll + _visible < count) {
|
||||||
display.setCursor(display.width() - 6, START_Y + (VISIBLE-1)*ITEM_H);
|
display.setCursor(display.width() - 6, START_Y + (_visible-1)*_item_h);
|
||||||
display.print("v");
|
display.print("v");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -992,6 +990,7 @@ public:
|
|||||||
_hist_head(0), _hist_count(0),
|
_hist_head(0), _hist_count(0),
|
||||||
_dm_hist_head(0), _dm_hist_count(0),
|
_dm_hist_head(0), _dm_hist_count(0),
|
||||||
_dm_hist_sel(-1), _dm_hist_scroll(0),
|
_dm_hist_sel(-1), _dm_hist_scroll(0),
|
||||||
|
_line_h(8), _item_h(11), _visible(4), _hist_visible(2), _hist_item_h(21), _hist_box_h(19),
|
||||||
_ctx_dirty(false) {
|
_ctx_dirty(false) {
|
||||||
memset(_ch_unread, 0, sizeof(_ch_unread));
|
memset(_ch_unread, 0, sizeof(_ch_unread));
|
||||||
}
|
}
|
||||||
@@ -1062,6 +1061,12 @@ public:
|
|||||||
|
|
||||||
int render(DisplayDriver& display) override {
|
int render(DisplayDriver& display) override {
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
|
_line_h = display.getLineHeight();
|
||||||
|
_item_h = _line_h + 3;
|
||||||
|
_visible = (display.height() - START_Y) / _item_h;
|
||||||
|
_hist_box_h = 2 * _line_h + 3;
|
||||||
|
_hist_item_h = _hist_box_h + 2;
|
||||||
|
_hist_visible = (display.height() - HIST_START_Y) / _hist_item_h;
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
|
|
||||||
if (_phase == MODE_SELECT) {
|
if (_phase == MODE_SELECT) {
|
||||||
@@ -1074,11 +1079,11 @@ public:
|
|||||||
_task->getRoomUnreadCount()
|
_task->getRoomUnreadCount()
|
||||||
};
|
};
|
||||||
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) {
|
if (sel) {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.fillRect(0, y - 1, display.width(), ITEM_H - 1);
|
display.fillRect(0, y - 1, display.width(), _item_h - 1);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
} else {
|
} else {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
@@ -1106,15 +1111,15 @@ public:
|
|||||||
return 5000;
|
return 5000;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < VISIBLE && (_contact_scroll+i) < _num_contacts; i++) {
|
for (int i = 0; i < _visible && (_contact_scroll+i) < _num_contacts; i++) {
|
||||||
int list_idx = _contact_scroll + i;
|
int list_idx = _contact_scroll + i;
|
||||||
int mesh_idx = _sorted[list_idx];
|
int mesh_idx = _sorted[list_idx];
|
||||||
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) {
|
if (sel) {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.fillRect(0, y - 1, display.width(), ITEM_H - 1);
|
display.fillRect(0, y - 1, display.width(), _item_h - 1);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
} else {
|
} else {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
@@ -1155,14 +1160,14 @@ public:
|
|||||||
return 5000;
|
return 5000;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < VISIBLE && (_channel_scroll+i) < _num_channels; i++) {
|
for (int i = 0; i < _visible && (_channel_scroll+i) < _num_channels; i++) {
|
||||||
int list_idx = _channel_scroll + i;
|
int list_idx = _channel_scroll + i;
|
||||||
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) {
|
if (sel) {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.fillRect(0, y - 1, display.width(), ITEM_H - 1);
|
display.fillRect(0, y - 1, display.width(), _item_h - 1);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
} else {
|
} else {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
@@ -1217,10 +1222,10 @@ public:
|
|||||||
|
|
||||||
int dm_count = dmHistCountForContact(_sel_contact.id.pub_key);
|
int dm_count = dmHistCountForContact(_sel_contact.id.pub_key);
|
||||||
|
|
||||||
for (int i = 0; i < HIST_VISIBLE && (_dm_hist_scroll + i) < dm_count; i++) {
|
for (int i = 0; i < _hist_visible && (_dm_hist_scroll + i) < dm_count; i++) {
|
||||||
int item = _dm_hist_scroll + i;
|
int item = _dm_hist_scroll + i;
|
||||||
bool sel = (item == _dm_hist_sel);
|
bool sel = (item == _dm_hist_sel);
|
||||||
int y = HIST_START_Y + i * HIST_ITEM_H;
|
int y = HIST_START_Y + i * _hist_item_h;
|
||||||
|
|
||||||
int ring_pos = dmHistEntryForContact(_sel_contact.id.pub_key, item);
|
int ring_pos = dmHistEntryForContact(_sel_contact.id.pub_key, item);
|
||||||
if (ring_pos < 0) continue;
|
if (ring_pos < 0) continue;
|
||||||
@@ -1230,18 +1235,18 @@ public:
|
|||||||
|
|
||||||
if (sel) {
|
if (sel) {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.fillRect(0, y, display.width(), HIST_BOX_H);
|
display.fillRect(0, y, display.width(), _hist_box_h);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
display.drawTextEllipsized(3, y + 1, display.width() - 6, sender);
|
display.drawTextEllipsized(3, y + 1, display.width() - 6, sender);
|
||||||
display.drawTextEllipsized(3, y + 10, display.width() - 6, e.text);
|
display.drawTextEllipsized(3, y + _line_h + 2, display.width() - 6, e.text);
|
||||||
} else {
|
} else {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.drawRect(0, y, display.width(), HIST_BOX_H);
|
display.drawRect(0, y, display.width(), _hist_box_h);
|
||||||
display.fillRect(1, y + 1, display.width() - 2, 8);
|
display.fillRect(1, y + 1, display.width() - 2, _line_h);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
display.drawTextEllipsized(3, y + 1, display.width() - 6, sender);
|
display.drawTextEllipsized(3, y + 1, display.width() - 6, sender);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.drawTextEllipsized(3, y + 10, display.width() - 6, e.text);
|
display.drawTextEllipsized(3, y + _line_h + 2, display.width() - 6, e.text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1255,17 +1260,17 @@ public:
|
|||||||
display.setCursor(display.width() - 6, HIST_START_Y + 1);
|
display.setCursor(display.width() - 6, HIST_START_Y + 1);
|
||||||
display.print("^");
|
display.print("^");
|
||||||
}
|
}
|
||||||
if (_dm_hist_scroll + HIST_VISIBLE < dm_count) {
|
if (_dm_hist_scroll + _hist_visible < dm_count) {
|
||||||
display.setCursor(display.width() - 6, HIST_START_Y + HIST_VISIBLE * HIST_ITEM_H - 10);
|
display.setCursor(display.width() - 6, HIST_START_Y + _hist_visible * _hist_item_h - (_line_h + 2));
|
||||||
display.print("v");
|
display.print("v");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compose_sel = (_dm_hist_sel == -1);
|
bool compose_sel = (_dm_hist_sel == -1);
|
||||||
const char* ctxt = "[+ send]";
|
const char* ctxt = "[+ send]";
|
||||||
int ctw = display.getTextWidth(ctxt);
|
int ctw = display.getTextWidth(ctxt);
|
||||||
int cbx = 1, cby = 55;
|
int cbx = 1, cby = display.height() - _line_h - 1;
|
||||||
if (compose_sel) {
|
if (compose_sel) {
|
||||||
display.fillRect(cbx, cby - 1, ctw + 4, 9);
|
display.fillRect(cbx, cby - 1, ctw + 4, _line_h + 1);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
}
|
}
|
||||||
display.setCursor(cbx + 2, cby);
|
display.setCursor(cbx + 2, cby);
|
||||||
@@ -1305,10 +1310,10 @@ public:
|
|||||||
|
|
||||||
int ch_hist_count = histCountForChannel(_sel_channel_idx);
|
int ch_hist_count = histCountForChannel(_sel_channel_idx);
|
||||||
|
|
||||||
for (int i = 0; i < HIST_VISIBLE && (_hist_scroll + i) < ch_hist_count; i++) {
|
for (int i = 0; i < _hist_visible && (_hist_scroll + i) < ch_hist_count; i++) {
|
||||||
int item = _hist_scroll + i;
|
int item = _hist_scroll + i;
|
||||||
bool sel = (item == _hist_sel);
|
bool sel = (item == _hist_sel);
|
||||||
int y = HIST_START_Y + i * HIST_ITEM_H;
|
int y = HIST_START_Y + i * _hist_item_h;
|
||||||
|
|
||||||
int ring_pos = histEntryForChannel(_sel_channel_idx, item);
|
int ring_pos = histEntryForChannel(_sel_channel_idx, item);
|
||||||
if (ring_pos < 0) continue;
|
if (ring_pos < 0) continue;
|
||||||
@@ -1329,18 +1334,18 @@ public:
|
|||||||
|
|
||||||
if (sel) {
|
if (sel) {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.fillRect(0, y, display.width(), HIST_BOX_H);
|
display.fillRect(0, y, display.width(), _hist_box_h);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
display.drawTextEllipsized(3, y + 1, display.width() - 6, sender);
|
display.drawTextEllipsized(3, y + 1, display.width() - 6, sender);
|
||||||
display.drawTextEllipsized(3, y + 10, display.width() - 6, msg_part);
|
display.drawTextEllipsized(3, y + _line_h + 2, display.width() - 6, msg_part);
|
||||||
} else {
|
} else {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.drawRect(0, y, display.width(), HIST_BOX_H);
|
display.drawRect(0, y, display.width(), _hist_box_h);
|
||||||
display.fillRect(1, y + 1, display.width() - 2, 8);
|
display.fillRect(1, y + 1, display.width() - 2, _line_h);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
display.drawTextEllipsized(3, y + 1, display.width() - 6, sender);
|
display.drawTextEllipsized(3, y + 1, display.width() - 6, sender);
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.drawTextEllipsized(3, y + 10, display.width() - 6, msg_part);
|
display.drawTextEllipsized(3, y + _line_h + 2, display.width() - 6, msg_part);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1355,8 +1360,8 @@ public:
|
|||||||
display.setCursor(display.width() - 6, HIST_START_Y + 1);
|
display.setCursor(display.width() - 6, HIST_START_Y + 1);
|
||||||
display.print("^");
|
display.print("^");
|
||||||
}
|
}
|
||||||
if (_hist_scroll + HIST_VISIBLE < ch_hist_count) {
|
if (_hist_scroll + _hist_visible < ch_hist_count) {
|
||||||
display.setCursor(display.width() - 6, HIST_START_Y + HIST_VISIBLE * HIST_ITEM_H - 10);
|
display.setCursor(display.width() - 6, HIST_START_Y + _hist_visible * _hist_item_h - (_line_h + 2));
|
||||||
display.print("v");
|
display.print("v");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1364,14 +1369,14 @@ public:
|
|||||||
bool compose_sel = (_hist_sel == -1);
|
bool compose_sel = (_hist_sel == -1);
|
||||||
const char* ctxt = "[+ send]";
|
const char* ctxt = "[+ send]";
|
||||||
int ctw = display.getTextWidth(ctxt);
|
int ctw = display.getTextWidth(ctxt);
|
||||||
int cbx = 1, cby = 55;
|
int cbx = 1, cby = display.height() - _line_h - 1;
|
||||||
if (compose_sel) {
|
if (compose_sel) {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.fillRect(cbx - 1, cby - 1, ctw + 4, 10);
|
display.fillRect(cbx - 1, cby - 1, ctw + 4, _line_h + 2);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
} else {
|
} else {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.drawRect(cbx - 1, cby - 1, ctw + 4, 10);
|
display.drawRect(cbx - 1, cby - 1, ctw + 4, _line_h + 2);
|
||||||
}
|
}
|
||||||
display.setCursor(cbx + 1, cby);
|
display.setCursor(cbx + 1, cby);
|
||||||
display.print(ctxt);
|
display.print(ctxt);
|
||||||
@@ -1393,14 +1398,14 @@ public:
|
|||||||
display.fillRect(0, 10, display.width(), 1);
|
display.fillRect(0, 10, display.width(), 1);
|
||||||
|
|
||||||
int total_msg_items = 1 + _active_msg_count;
|
int total_msg_items = 1 + _active_msg_count;
|
||||||
for (int i = 0; i < VISIBLE && (_msg_scroll+i) < total_msg_items; i++) {
|
for (int i = 0; i < _visible && (_msg_scroll+i) < total_msg_items; i++) {
|
||||||
int idx = _msg_scroll + i;
|
int idx = _msg_scroll + i;
|
||||||
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) {
|
if (sel) {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.fillRect(0, y - 1, display.width(), ITEM_H - 1);
|
display.fillRect(0, y - 1, display.width(), _item_h - 1);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
} else {
|
} else {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
@@ -1475,7 +1480,7 @@ public:
|
|||||||
}
|
}
|
||||||
if (c == KEY_DOWN && _contact_sel < _num_contacts - 1) {
|
if (c == KEY_DOWN && _contact_sel < _num_contacts - 1) {
|
||||||
_contact_sel++;
|
_contact_sel++;
|
||||||
if (_contact_sel >= _contact_scroll + VISIBLE) _contact_scroll = _contact_sel - VISIBLE + 1;
|
if (_contact_sel >= _contact_scroll + _visible) _contact_scroll = _contact_sel - _visible + 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (c == KEY_ENTER && _num_contacts > 0) {
|
if (c == KEY_ENTER && _num_contacts > 0) {
|
||||||
@@ -1536,7 +1541,7 @@ public:
|
|||||||
}
|
}
|
||||||
if (c == KEY_DOWN && _channel_sel < _num_channels - 1) {
|
if (c == KEY_DOWN && _channel_sel < _num_channels - 1) {
|
||||||
_channel_sel++;
|
_channel_sel++;
|
||||||
if (_channel_sel >= _channel_scroll + VISIBLE) _channel_scroll = _channel_sel - VISIBLE + 1;
|
if (_channel_sel >= _channel_scroll + _visible) _channel_scroll = _channel_sel - _visible + 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (c == KEY_ENTER && _num_channels > 0) {
|
if (c == KEY_ENTER && _num_channels > 0) {
|
||||||
@@ -1593,8 +1598,8 @@ public:
|
|||||||
if (_dm_hist_sel == -1 && dm_count > 0) { _dm_hist_sel = 0; _dm_hist_scroll = 0; }
|
if (_dm_hist_sel == -1 && dm_count > 0) { _dm_hist_sel = 0; _dm_hist_scroll = 0; }
|
||||||
else if (_dm_hist_sel >= 0 && _dm_hist_sel < dm_count - 1) {
|
else if (_dm_hist_sel >= 0 && _dm_hist_sel < dm_count - 1) {
|
||||||
_dm_hist_sel++;
|
_dm_hist_sel++;
|
||||||
if (_dm_hist_sel >= _dm_hist_scroll + HIST_VISIBLE)
|
if (_dm_hist_sel >= _dm_hist_scroll + _hist_visible)
|
||||||
_dm_hist_scroll = _dm_hist_sel - HIST_VISIBLE + 1;
|
_dm_hist_scroll = _dm_hist_sel - _hist_visible + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1633,7 +1638,7 @@ public:
|
|||||||
if (_hist_sel == -1 && ch_hist_count > 0) { _hist_sel = 0; _hist_scroll = 0; }
|
if (_hist_sel == -1 && ch_hist_count > 0) { _hist_sel = 0; _hist_scroll = 0; }
|
||||||
else if (_hist_sel >= 0 && _hist_sel < ch_hist_count - 1) {
|
else if (_hist_sel >= 0 && _hist_sel < ch_hist_count - 1) {
|
||||||
_hist_sel++;
|
_hist_sel++;
|
||||||
if (_hist_sel >= _hist_scroll + HIST_VISIBLE) _hist_scroll = _hist_sel - HIST_VISIBLE + 1;
|
if (_hist_sel >= _hist_scroll + _hist_visible) _hist_scroll = _hist_sel - _hist_visible + 1;
|
||||||
}
|
}
|
||||||
updateChannelUnread();
|
updateChannelUnread();
|
||||||
return true;
|
return true;
|
||||||
@@ -1677,7 +1682,7 @@ public:
|
|||||||
}
|
}
|
||||||
if (c == KEY_DOWN && _msg_sel < total_msg_items - 1) {
|
if (c == KEY_DOWN && _msg_sel < total_msg_items - 1) {
|
||||||
_msg_sel++;
|
_msg_sel++;
|
||||||
if (_msg_sel >= _msg_scroll + VISIBLE) _msg_scroll = _msg_sel - VISIBLE + 1;
|
if (_msg_sel >= _msg_scroll + _visible) _msg_scroll = _msg_sel - _visible + 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (c == KEY_ENTER) {
|
if (c == KEY_ENTER) {
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public:
|
|||||||
virtual void drawRect(int x, int y, int w, int h) = 0;
|
virtual void drawRect(int x, int y, int w, int h) = 0;
|
||||||
virtual void drawXbm(int x, int y, const uint8_t* bits, int w, int h) = 0;
|
virtual void drawXbm(int x, int y, const uint8_t* bits, int w, int h) = 0;
|
||||||
virtual uint16_t getTextWidth(const char* str) = 0;
|
virtual uint16_t getTextWidth(const char* str) = 0;
|
||||||
|
virtual int getCharWidth() const { return 6; } // advance width of a typical character (xAdvance for monospace)
|
||||||
|
virtual int getLineHeight() const { return 8; } // pixel rows per line (cell height, not just glyph height)
|
||||||
virtual void drawTextCentered(int mid_x, int y, const char* str) { // helper method (override to optimise)
|
virtual void drawTextCentered(int mid_x, int y, const char* str) { // helper method (override to optimise)
|
||||||
int w = getTextWidth(str);
|
int w = getTextWidth(str);
|
||||||
setCursor(mid_x - w/2, y);
|
setCursor(mid_x - w/2, y);
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// Lemon font icon glyphs (Private Use Area), converted manually from lemon.bdf
|
||||||
|
// Add new icons by appending to the bitmap array, lemonIconCPs, and lemonIconGlyphs.
|
||||||
|
#pragma once
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
|
||||||
|
static const uint8_t lemonIconBitmaps[] PROGMEM = {
|
||||||
|
0xEE, 0xBA, 0x2B, 0xA3, 0xB0, // U+E03B mute: 6×6, yoff=0
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint32_t lemonIconCPs[] PROGMEM = {
|
||||||
|
0xE03B, // mute
|
||||||
|
};
|
||||||
|
|
||||||
|
static const GFXglyph lemonIconGlyphs[] PROGMEM = {
|
||||||
|
// off w h adv xo yo
|
||||||
|
{ 0, 6, 6, 5, 0, -6 }, // U+E03B mute
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t lemonIconCount = sizeof(lemonIconCPs) / sizeof(lemonIconCPs[0]);
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <Adafruit_GrayOLED.h>
|
#include <Adafruit_GrayOLED.h>
|
||||||
#include "Adafruit_SH110X.h"
|
#include "Adafruit_SH110X.h"
|
||||||
#include "LemonFont.h"
|
#include "LemonFont.h"
|
||||||
|
#include "LemonIcons.h"
|
||||||
|
|
||||||
bool SH1106Display::i2c_probe(TwoWire &wire, uint8_t addr)
|
bool SH1106Display::i2c_probe(TwoWire &wire, uint8_t addr)
|
||||||
{
|
{
|
||||||
@@ -90,6 +91,27 @@ uint32_t SH1106Display::decodeUtf8(const uint8_t*& p) {
|
|||||||
|
|
||||||
// Draw one Lemon glyph at (x, y), return new cursor x.
|
// Draw one Lemon glyph at (x, y), return new cursor x.
|
||||||
int16_t SH1106Display::drawLemonChar(int16_t x, int16_t y, uint32_t cp) {
|
int16_t SH1106Display::drawLemonChar(int16_t x, int16_t y, uint32_t cp) {
|
||||||
|
// Check icon table for Private Use Area codepoints
|
||||||
|
for (uint8_t i = 0; i < lemonIconCount; i++) {
|
||||||
|
if (pgm_read_dword(&lemonIconCPs[i]) == cp) {
|
||||||
|
const GFXglyph* g = &lemonIconGlyphs[i];
|
||||||
|
uint8_t w = pgm_read_byte(&g->width);
|
||||||
|
uint8_t h = pgm_read_byte(&g->height);
|
||||||
|
int8_t xo = (int8_t)pgm_read_byte(&g->xOffset);
|
||||||
|
int8_t yo = (int8_t)pgm_read_byte(&g->yOffset);
|
||||||
|
uint8_t xa = pgm_read_byte(&g->xAdvance);
|
||||||
|
uint16_t bo = pgm_read_word(&g->bitmapOffset);
|
||||||
|
uint8_t bits = 0, bit = 0;
|
||||||
|
for (uint8_t row = 0; row < h; row++)
|
||||||
|
for (uint8_t col = 0; col < w; col++) {
|
||||||
|
if (!bit) { bits = pgm_read_byte(&lemonIconBitmaps[bo++]); bit = 0x80; }
|
||||||
|
if (bits & bit) display.drawPixel(x + xo + col, y + 6 + yo + row, _color);
|
||||||
|
bit >>= 1;
|
||||||
|
}
|
||||||
|
return x + xa;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cp < Lemon.first || cp > Lemon.last) {
|
if (cp < Lemon.first || cp > Lemon.last) {
|
||||||
// outside font range — use default advance
|
// outside font range — use default advance
|
||||||
return x + 6;
|
return x + 6;
|
||||||
@@ -107,7 +129,7 @@ int16_t SH1106Display::drawLemonChar(int16_t x, int16_t y, uint32_t cp) {
|
|||||||
for (uint8_t col = 0; col < w; col++) {
|
for (uint8_t col = 0; col < w; col++) {
|
||||||
if (!bit) { bits = pgm_read_byte(&lemonBitmaps[bo++]); bit = 0x80; }
|
if (!bit) { bits = pgm_read_byte(&lemonBitmaps[bo++]); bit = 0x80; }
|
||||||
if (bits & bit)
|
if (bits & bit)
|
||||||
display.drawPixel(x + xo + col, y + yo + row, _color);
|
display.drawPixel(x + xo + col, y + 6 + yo + row, _color); // +6 = cap height: cursor y aligns with top of uppercase/digit glyphs
|
||||||
bit >>= 1;
|
bit >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ public:
|
|||||||
void drawRect(int x, int y, int w, int h) override;
|
void drawRect(int x, int y, int w, int h) override;
|
||||||
void drawXbm(int x, int y, const uint8_t *bits, int w, int h) override;
|
void drawXbm(int x, int y, const uint8_t *bits, int w, int h) override;
|
||||||
uint16_t getTextWidth(const char *str) override;
|
uint16_t getTextWidth(const char *str) override;
|
||||||
|
int getCharWidth() const override { return 5; } // Lemon font: xAdvance = 5
|
||||||
|
int getLineHeight() const override { return 9; } // Lemon font: visual line spacing (yAdvance=10, used as 9 for tighter fit)
|
||||||
void setBrightness(uint8_t level) override;
|
void setBrightness(uint8_t level) override;
|
||||||
void endFrame() override;
|
void endFrame() override;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user