refactor(Style): Add font abstraction and CSS-like styling constants
This commit is contained in:
@@ -58,6 +58,16 @@ int DisplayDriverGFX::width() { return _gfx ? _gfx->width() : DISP_W; }
|
||||
|
||||
int DisplayDriverGFX::height() { return _gfx ? _gfx->height() : DISP_H; }
|
||||
|
||||
// ── Fonts ──
|
||||
// LovyanGFX built-in fonts for 800x480 display
|
||||
void DisplayDriverGFX::setTitleFont() { _gfx->setFont(&fonts::FreeSansBold24pt7b); }
|
||||
|
||||
void DisplayDriverGFX::setBodyFont() { _gfx->setFont(&fonts::FreeSans18pt7b); }
|
||||
|
||||
void DisplayDriverGFX::setLabelFont() { _gfx->setFont(&fonts::FreeSans12pt7b); }
|
||||
|
||||
void DisplayDriverGFX::setDefaultFont() { _gfx->setFont(&fonts::Font2); }
|
||||
|
||||
// Transform touch coordinates to match display orientation
|
||||
// GT911 touch panel on this board is rotated 180° relative to display
|
||||
void DisplayDriverGFX::transformTouch(int* x, int* y) {
|
||||
@@ -121,9 +131,12 @@ bool DisplayDriverGFX::parseTestTouch(int* outX, int* outY, bool* outPressed) {
|
||||
|
||||
Serial.printf("[TEST] Injecting touch: (%d,%d) %s\n", x, y, pressed ? "press" : "release");
|
||||
|
||||
if(outX) *outX = x;
|
||||
if(outY) *outY = y;
|
||||
if(outPressed) *outPressed = pressed;
|
||||
if(outX)
|
||||
*outX = x;
|
||||
if(outY)
|
||||
*outY = y;
|
||||
if(outPressed)
|
||||
*outPressed = pressed;
|
||||
|
||||
_testMode = true;
|
||||
return true;
|
||||
@@ -323,18 +336,19 @@ void DisplayDriverGFX::render(const ScreenState& state) {
|
||||
void DisplayDriverGFX::drawBoot(const ScreenState& state) {
|
||||
BootStage stage = state.bootStage;
|
||||
|
||||
_gfx->fillScreen(0x000000);
|
||||
_gfx->setTextColor(0xFFFF);
|
||||
_gfx->setTextSize(2);
|
||||
_gfx->setCursor(10, 10);
|
||||
_gfx->fillScreen(TFT_BLACK);
|
||||
_gfx->setTextColor(STYLE_COLOR_FG);
|
||||
setTitleFont();
|
||||
_gfx->setCursor(STYLE_SPACING_X, STYLE_SPACING_Y);
|
||||
_gfx->print("KLUBHAUS");
|
||||
|
||||
_gfx->setTextSize(1);
|
||||
_gfx->setCursor(10, 50);
|
||||
setBodyFont();
|
||||
_gfx->setCursor(STYLE_SPACING_X, STYLE_SPACING_Y + STYLE_HEADER_HEIGHT);
|
||||
_gfx->print(BOARD_NAME);
|
||||
|
||||
// Show boot stage status
|
||||
_gfx->setCursor(10, 80);
|
||||
setLabelFont();
|
||||
_gfx->setCursor(STYLE_SPACING_X, STYLE_SPACING_Y + STYLE_HEADER_HEIGHT + 30);
|
||||
switch(stage) {
|
||||
case BootStage::SPLASH:
|
||||
_gfx->print("Initializing...");
|
||||
@@ -363,30 +377,29 @@ void DisplayDriverGFX::drawAlert(const ScreenState& state) {
|
||||
uint16_t bg = _gfx->color565(pulse, 0, 0);
|
||||
|
||||
_gfx->fillScreen(bg);
|
||||
_gfx->setTextColor(0xFFFF, bg);
|
||||
_gfx->setTextColor(STYLE_COLOR_FG, bg);
|
||||
|
||||
_gfx->setTextSize(3);
|
||||
_gfx->setCursor(10, 20);
|
||||
setTitleFont();
|
||||
_gfx->setCursor(STYLE_SPACING_X, STYLE_HEADER_HEIGHT);
|
||||
_gfx->print(state.alertTitle.length() > 0 ? state.alertTitle.c_str() : "ALERT");
|
||||
|
||||
_gfx->setTextSize(2);
|
||||
_gfx->setCursor(10, 80);
|
||||
setBodyFont();
|
||||
_gfx->setCursor(STYLE_SPACING_X, STYLE_HEADER_HEIGHT + 50);
|
||||
_gfx->print(state.alertBody);
|
||||
|
||||
_gfx->setTextSize(1);
|
||||
_gfx->setCursor(10, DISP_H - 20);
|
||||
setLabelFont();
|
||||
_gfx->setCursor(STYLE_SPACING_X, DISP_H - STYLE_SPACING_Y);
|
||||
_gfx->print("Hold to silence...");
|
||||
}
|
||||
|
||||
void DisplayDriverGFX::drawDashboard(const ScreenState& state) {
|
||||
_gfx->fillScreen(0x001030); // Dark blue
|
||||
_gfx->fillScreen(STYLE_COLOR_BG);
|
||||
|
||||
// Header
|
||||
_gfx->fillRect(0, 0, DISP_W, 40, 0x1A1A); // Dark gray
|
||||
_gfx->setFont(&fonts::Font2);
|
||||
_gfx->setTextColor(0xFFFF);
|
||||
_gfx->setTextSize(1);
|
||||
_gfx->setCursor(10, 12);
|
||||
_gfx->fillRect(0, 0, DISP_W, STYLE_HEADER_HEIGHT, STYLE_COLOR_HEADER);
|
||||
setBodyFont();
|
||||
_gfx->setTextColor(STYLE_COLOR_FG);
|
||||
_gfx->setCursor(STYLE_SPACING_X, 12);
|
||||
_gfx->printf("KLUBHAUS");
|
||||
|
||||
// WiFi status
|
||||
@@ -407,15 +420,15 @@ void DisplayDriverGFX::drawDashboard(const ScreenState& state) {
|
||||
int h = lay.h;
|
||||
|
||||
// Tile background
|
||||
_gfx->fillRoundRect(x, y, w, h, 8, 0x0220);
|
||||
_gfx->fillRoundRect(x, y, w, h, STYLE_TILE_RADIUS, 0x0220);
|
||||
|
||||
// Tile border
|
||||
_gfx->drawRoundRect(x, y, w, h, 8, 0xFFFF);
|
||||
_gfx->drawRoundRect(x, y, w, h, STYLE_TILE_RADIUS, STYLE_COLOR_FG);
|
||||
|
||||
// Tile label
|
||||
_gfx->setTextColor(0xFFFF);
|
||||
_gfx->setTextSize(2);
|
||||
_gfx->setCursor(x + w / 2 - 10, y + h / 2 - 10);
|
||||
_gfx->setTextColor(STYLE_COLOR_FG);
|
||||
setBodyFont();
|
||||
_gfx->setCursor(x + w / 2 - 30, y + h / 2 - 10);
|
||||
_gfx->print(tileLabels[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user