feat: runtime font switcher — Default vs Lemon in Settings > Display

- Add Lemon font (LemonFont.h, LemonIcons.h) to the standard build
  alongside the Adafruit built-in font; ~101 KB added to flash
- SH1106Display: add _use_lemon flag + setLemonFont(bool) to switch
  at runtime; print() and getTextWidth() use Lemon path when active;
  translateUTF8ToBlocks() passes UTF-8 through unchanged (Lemon supports
  full Unicode U+0020-U+04FF) vs transliterating for the default font
- DisplayDriver: add getCharWidth()/getLineHeight() virtuals (defaults 6/8);
  SH1106Display returns 5/9 for Lemon, 6/8 for default; add setLemonFont()
  no-op virtual; fix orphaned UTF-8 leading byte in drawTextEllipsized
- FullscreenMsgView: replace fixed-char-count word-wrap with pixel-accurate
  wrap using display.getTextWidth(); use getLineHeight() for spacing so
  Lemon (9 px) and default (8 px) both render correctly
- NodePrefs: add use_lemon_font field (0=default, 1=Lemon)
- SettingsScreen: add "Font" item in Display section (Default / Lemon),
  calls UITask::applyFont() on change
- UITask: add applyFont() that calls display->setLemonFont(use_lemon_font);
  called at startup (begin()) and when the setting changes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-05-22 09:33:35 +02:00
co-authored by Claude Sonnet 4.6
parent 72c07df8b3
commit a115916d8f
10 changed files with 1732 additions and 29 deletions
+11 -1
View File
@@ -21,11 +21,17 @@ class SH1106Display : public DisplayDriver
uint8_t _color;
uint8_t _contrast;
uint8_t _precharge;
bool _use_lemon;
bool i2c_probe(TwoWire &wire, uint8_t addr);
static uint32_t decodeUtf8(const uint8_t*& p);
int16_t drawLemonChar(int16_t x, int16_t y, uint32_t cp);
uint8_t lemonXAdvance(uint32_t cp);
public:
SH1106Display() : DisplayDriver(128, 64), display(128, 64, &Wire, PIN_OLED_RESET) { _isOn = false; _contrast = 255; _precharge = 0x1F; }
SH1106Display() : DisplayDriver(128, 64), display(128, 64, &Wire, PIN_OLED_RESET) {
_isOn = false; _contrast = 255; _precharge = 0x1F; _use_lemon = false;
}
bool begin();
bool isOn() override { return _isOn; }
@@ -41,6 +47,10 @@ public:
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;
uint16_t getTextWidth(const char *str) override;
int getCharWidth() const override { return _use_lemon ? 5 : 6; }
int getLineHeight() const override { return _use_lemon ? 9 : 8; }
void setLemonFont(bool enabled) override { _use_lemon = enabled; }
void translateUTF8ToBlocks(char* dest, const char* src, size_t dest_size) override;
void setBrightness(uint8_t level) override;
void endFrame() override;
};