Additional larger font for InkHUD UI (#7201)

* Add 12pt fonts

* Add fontMedium
In addition to fontSmall and fontLarge

* Set fonts in nicheGraphics.h

* Change all uses of fontLarge to fontMedium
fontLarge was previously set at 9pt. fontLarge is now 12pt, fontMedium is 9pt. (NB: fonts may be customized per-variant)

* Use fontLarge with "All Messages" and "DMs" applets

* Documentation
This commit is contained in:
todd-herbert
2025-07-03 12:18:34 +12:00
committed by GitHub
parent f99ac2104c
commit 1f85e2a02a
25 changed files with 1679 additions and 58 deletions

View File

@@ -8,8 +8,9 @@
using namespace NicheGraphics;
InkHUD::AppletFont InkHUD::Applet::fontLarge; // General purpose font. Set by setDefaultFonts
InkHUD::AppletFont InkHUD::Applet::fontSmall; // General purpose font. Set by setDefaultFonts
InkHUD::AppletFont InkHUD::Applet::fontLarge; // General purpose fonts. Set in nicheGraphics.h
InkHUD::AppletFont InkHUD::Applet::fontMedium;
InkHUD::AppletFont InkHUD::Applet::fontSmall;
constexpr float InkHUD::Applet::LOGO_ASPECT_RATIO; // Ratio of the Meshtastic logo
InkHUD::Applet::Applet() : GFX(0, 0)

View File

@@ -95,7 +95,7 @@ class Applet : public GFX
static uint16_t getHeaderHeight(); // How tall the "standard" applet header is
static AppletFont fontSmall, fontLarge; // The general purpose fonts, used by all applets
static AppletFont fontSmall, fontMedium, fontLarge; // The general purpose fonts, used by all applets
const char *name = nullptr; // Shown in applet selection menu. Also used as an identifier by InkHUD::getSystemApplet

View File

@@ -61,20 +61,26 @@ class AppletFont
// Line padding has been adjusted manually, to compensate for a few *extra tall* diacritics
// Central European
#include "graphics/niche/Fonts/FreeSans12pt_Win1250.h"
#include "graphics/niche/Fonts/FreeSans6pt_Win1250.h"
#include "graphics/niche/Fonts/FreeSans9pt_Win1250.h"
#define FREESANS_12PT_WIN1250 InkHUD::AppletFont(FreeSans12pt_Win1250, InkHUD::AppletFont::WINDOWS_1250, -3, 1)
#define FREESANS_9PT_WIN1250 InkHUD::AppletFont(FreeSans9pt_Win1250, InkHUD::AppletFont::WINDOWS_1250, -1, -1)
#define FREESANS_6PT_WIN1250 InkHUD::AppletFont(FreeSans6pt_Win1250, InkHUD::AppletFont::WINDOWS_1250, -1, -2)
// Cyrillic
#include "graphics/niche/Fonts/FreeSans12pt_Win1251.h"
#include "graphics/niche/Fonts/FreeSans6pt_Win1251.h"
#include "graphics/niche/Fonts/FreeSans9pt_Win1251.h"
#define FREESANS_12PT_WIN1251 InkHUD::AppletFont(FreeSans12pt_Win1251, InkHUD::AppletFont::WINDOWS_1251, -3, 1)
#define FREESANS_9PT_WIN1251 InkHUD::AppletFont(FreeSans9pt_Win1251, InkHUD::AppletFont::WINDOWS_1251, -2, -1)
#define FREESANS_6PT_WIN1251 InkHUD::AppletFont(FreeSans6pt_Win1251, InkHUD::AppletFont::WINDOWS_1251, -1, -2)
// Western European
#include "graphics/niche/Fonts/FreeSans12pt_Win1252.h"
#include "graphics/niche/Fonts/FreeSans6pt_Win1252.h"
#include "graphics/niche/Fonts/FreeSans9pt_Win1252.h"
#define FREESANS_12PT_WIN1252 InkHUD::AppletFont(FreeSans12pt_Win1252, InkHUD::AppletFont::WINDOWS_1252, -3, 1)
#define FREESANS_9PT_WIN1252 InkHUD::AppletFont(FreeSans9pt_Win1252, InkHUD::AppletFont::WINDOWS_1252, -2, -1)
#define FREESANS_6PT_WIN1252 InkHUD::AppletFont(FreeSans6pt_Win1252, InkHUD::AppletFont::WINDOWS_1252, -1, -2)

View File

@@ -168,11 +168,11 @@ void InkHUD::NodeListApplet::onRender()
// Define two lines of text for the card
// We will center our text on these lines
uint16_t lineAY = cardTopY + (fontLarge.lineHeight() / 2);
uint16_t lineBY = cardTopY + fontLarge.lineHeight() + (fontSmall.lineHeight() / 2);
uint16_t lineAY = cardTopY + (fontMedium.lineHeight() / 2);
uint16_t lineBY = cardTopY + fontMedium.lineHeight() + (fontSmall.lineHeight() / 2);
// Print the short name
setFont(fontLarge);
setFont(fontMedium);
printAt(0, lineAY, shortName, LEFT, MIDDLE);
// Print the distance
@@ -182,8 +182,8 @@ void InkHUD::NodeListApplet::onRender()
// If we have a direct connection to the node, draw the signal indicator
if (hopsAway == 0 && signal != SIGNAL_UNKNOWN) {
uint16_t signalW = getTextWidth("Xkm"); // Indicator should be similar width to distance label
uint16_t signalH = fontLarge.lineHeight() * 0.75;
int16_t signalY = lineAY + (fontLarge.lineHeight() / 2) - (fontLarge.lineHeight() * 0.75);
uint16_t signalH = fontMedium.lineHeight() * 0.75;
int16_t signalY = lineAY + (fontMedium.lineHeight() / 2) - (fontMedium.lineHeight() * 0.75);
int16_t signalX = width() - signalW;
drawSignalIndicator(signalX, signalY, signalW, signalH, signal);
}

View File

@@ -65,8 +65,8 @@ class NodeListApplet : public Applet, public MeshModule
// Card Dimensions
// - for rendering and for maxCards calc
const uint8_t cardMarginH = fontSmall.lineHeight() / 2; // Gap between cards
const uint16_t cardH = fontLarge.lineHeight() + fontSmall.lineHeight() + cardMarginH; // Height of card
uint8_t cardMarginH = fontSmall.lineHeight() / 2; // Gap between cards
uint16_t cardH = fontMedium.lineHeight() + fontSmall.lineHeight() + cardMarginH; // Height of card
};
} // namespace NicheGraphics::InkHUD

View File

@@ -15,7 +15,7 @@ InkHUD::LogoApplet::LogoApplet() : concurrency::OSThread("LogoApplet")
// This behavior assists manufacturers during mass production, and should not be modified without good reason
if (!settings->tips.safeShutdownSeen) {
meshtastic_NodeInfoLite *ourNode = nodeDB->getMeshNode(nodeDB->getNodeNum());
fontTitle = fontLarge;
fontTitle = fontMedium;
textLeft = xstr(APP_VERSION_SHORT);
textRight = parseShortName(ourNode);
textTitle = "Meshtastic";
@@ -116,7 +116,7 @@ void InkHUD::LogoApplet::onShutdown()
textLeft = "";
textRight = "";
textTitle = parseShortName(ourNode);
fontTitle = fontLarge;
fontTitle = fontMedium;
// This is then drawn by InkHUD::Events::onShutdown, with a blocking FULL update, after InkHUD's flash write is complete
}

View File

@@ -667,11 +667,11 @@ void InkHUD::MenuApplet::drawSystemInfoPanel(int16_t left, int16_t top, uint16_t
// ====================
std::string clockString = getTimeString();
if (clockString.length() > 0) {
setFont(fontLarge);
setFont(fontMedium);
printAt(width / 2, top, clockString, CENTER, TOP);
height += fontLarge.lineHeight();
height += fontLarge.lineHeight() * 0.1; // Padding below clock
height += fontMedium.lineHeight();
height += fontMedium.lineHeight() * 0.1; // Padding below clock
}
// Stats

View File

@@ -12,13 +12,13 @@ InkHUD::PairingApplet::PairingApplet()
void InkHUD::PairingApplet::onRender()
{
// Header
setFont(fontLarge);
setFont(fontMedium);
printAt(X(0.5), Y(0.25), "Bluetooth", CENTER, BOTTOM);
setFont(fontSmall);
printAt(X(0.5), Y(0.25), "Enter this code", CENTER, TOP);
// Passkey
setFont(fontLarge);
setFont(fontMedium);
printThick(X(0.5), Y(0.5), passkey.substr(0, 3) + " " + passkey.substr(3), 3, 2);
// Device's bluetooth name, if it will fit

View File

@@ -50,11 +50,11 @@ void InkHUD::TipsApplet::onRender()
break;
case Tip::FINISH_SETUP: {
setFont(fontLarge);
setFont(fontMedium);
printAt(0, 0, "Tip: Finish Setup");
setFont(fontSmall);
int16_t cursorY = fontLarge.lineHeight() * 1.5;
int16_t cursorY = fontMedium.lineHeight() * 1.5;
printAt(0, cursorY, "- connect antenna");
cursorY += fontSmall.lineHeight() * 1.2;
@@ -80,7 +80,7 @@ void InkHUD::TipsApplet::onRender()
} break;
case Tip::SAFE_SHUTDOWN: {
setFont(fontLarge);
setFont(fontMedium);
printAt(0, 0, "Tip: Shutdown");
setFont(fontSmall);
@@ -88,29 +88,29 @@ void InkHUD::TipsApplet::onRender()
shutdown += "Before removing power, please shut down from InkHUD menu, or a client app. \n";
shutdown += "\n";
shutdown += "This ensures data is saved.";
printWrapped(0, fontLarge.lineHeight() * 1.5, width(), shutdown);
printWrapped(0, fontMedium.lineHeight() * 1.5, width(), shutdown);
printAt(0, Y(1.0), "Press button to continue", LEFT, BOTTOM);
} break;
case Tip::CUSTOMIZATION: {
setFont(fontLarge);
setFont(fontMedium);
printAt(0, 0, "Tip: Customization");
setFont(fontSmall);
printWrapped(0, fontLarge.lineHeight() * 1.5, width(),
printWrapped(0, fontMedium.lineHeight() * 1.5, width(),
"Configure & control display with the InkHUD menu. Optional features, layout, rotation, and more.");
printAt(0, Y(1.0), "Press button to continue", LEFT, BOTTOM);
} break;
case Tip::BUTTONS: {
setFont(fontLarge);
setFont(fontMedium);
printAt(0, 0, "Tip: Buttons");
setFont(fontSmall);
int16_t cursorY = fontLarge.lineHeight() * 1.5;
int16_t cursorY = fontMedium.lineHeight() * 1.5;
printAt(0, cursorY, "User Button");
cursorY += fontSmall.lineHeight() * 1.2;
@@ -123,11 +123,11 @@ void InkHUD::TipsApplet::onRender()
} break;
case Tip::ROTATION: {
setFont(fontLarge);
setFont(fontMedium);
printAt(0, 0, "Tip: Rotation");
setFont(fontSmall);
printWrapped(0, fontLarge.lineHeight() * 1.5, width(),
printWrapped(0, fontMedium.lineHeight() * 1.5, width(),
"To rotate the display, use the InkHUD menu. Long-press the user button > Options > Rotate.");
printAt(0, Y(1.0), "Press button to continue", LEFT, BOTTOM);
@@ -155,7 +155,7 @@ void InkHUD::TipsApplet::renderWelcome()
uint16_t logoH = getLogoHeight(logoWLimit, logoHLimit);
// Title size
setFont(fontLarge);
setFont(fontMedium);
std::string title;
if (width() >= 200) // Future proofing: hide if *tiny* display
title = "meshtastic.org";

View File

@@ -101,15 +101,25 @@ void InkHUD::AllMessageApplet::onRender()
// Extra gap below the header
int16_t textTop = headerDivY + padDivH;
// Determine size if printed large
// Attempt to print with fontLarge
uint32_t textHeight;
setFont(fontLarge);
uint32_t textHeight = getWrappedTextHeight(0, width(), text);
textHeight = getWrappedTextHeight(0, width(), text);
if (textHeight <= (uint32_t)height()) {
printWrapped(0, textTop, width(), text);
return;
}
// If too large, swap to small font
if (textHeight + textTop > (uint32_t)height()) // (compare signed and unsigned)
setFont(fontSmall);
// Fallback (too large): attempt to print with fontMedium
setFont(fontMedium);
textHeight = getWrappedTextHeight(0, width(), text);
if (textHeight <= (uint32_t)height()) {
printWrapped(0, textTop, width(), text);
return;
}
// Print text
// Fallback (too large): print with fontSmall
setFont(fontSmall);
printWrapped(0, textTop, width(), text);
}

View File

@@ -97,15 +97,25 @@ void InkHUD::DMApplet::onRender()
// Extra gap below the header
int16_t textTop = headerDivY + padDivH;
// Determine size if printed large
// Attempt to print with fontLarge
uint32_t textHeight;
setFont(fontLarge);
uint32_t textHeight = getWrappedTextHeight(0, width(), text);
textHeight = getWrappedTextHeight(0, width(), text);
if (textHeight <= (uint32_t)height()) {
printWrapped(0, textTop, width(), text);
return;
}
// If too large, swap to small font
if (textHeight + textTop > (uint32_t)height()) // (compare signed and unsigned)
setFont(fontSmall);
// Fallback (too large): attempt to print with fontMedium
setFont(fontMedium);
textHeight = getWrappedTextHeight(0, width(), text);
if (textHeight <= (uint32_t)height()) {
printWrapped(0, textTop, width(), text);
return;
}
// Print text
// Fallback (too large): print with fontSmall
setFont(fontSmall);
printWrapped(0, textTop, width(), text);
}

View File

@@ -312,18 +312,19 @@ As a general overview:
## Fonts
InkHUD uses AdafruitGFX fonts. The large and small font which are shared by all applets are set in nicheGraphics.h.
InkHUD uses AdafruitGFX fonts. Three shared fonts (small, medium, large) are available for use by all applets. These are set per-variant in nicheGraphics.h.
```cpp
// Prepare fonts
InkHUD::Applet::fontLarge = FREESANS_9PT_WIN1252;
InkHUD::Applet::fontLarge = FREESANS_12PT_WIN1252;
InkHUD::Applet::fontMedium = FREESANS_9PT_WIN1252;
InkHUD::Applet::fontSmall = FREESANS_6PT_WIN1252;
// Using a generic AdafruitGFX font instead:
// InkHUD::Applet::fontLarge = FreeSerif9pt7b;
// InkHUD::Applet::fontLarge = FreeSerif18pt7b;
```
Any generic AdafruitGFX font may be used, but the fonts which are bundled with InkHUD have been customized with extended-ASCII character sets.
Any generic AdafruitGFX font may be used, but the fonts which are bundled with InkHUD have been customized with extended-ASCII character sets and emoji.
### Parsing Unicode Text
@@ -351,10 +352,12 @@ InkHUD is bundled with extended-ASCII fonts for:
The default builds use Windows-1252 encoding. This can be changed in nicheGraphics.h.
```cpp
InkHUD::Applet::fontLarge = FREESANS_9PT_WIN1250;
InkHUD::Applet::fontLarge = FREESANS_12PT_WIN1250;
InkHUD::Applet::fontMedium = FREESANS_9PT_WIN1250;
InkHUD::Applet::fontSmall = FREESANS_6PT_WIN1250;
InkHUD::Applet::fontLarge = FREESANS_9PT_WIN1251;
InkHUD::Applet::fontLarge = FREESANS_12PT_WIN1251;
InkHUD::Applet::fontMedium = FREESANS_9PT_WIN1251;
InkHUD::Applet::fontSmall = FREESANS_6PT_WIN1251;
```