refactor(display): extract tile layout logic to library helper class
This commit is contained in:
@@ -5,9 +5,11 @@
|
||||
#include "board_config.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <KlubhausCore.h>
|
||||
|
||||
// ── Globals ──
|
||||
static LGFX* _gfx = nullptr;
|
||||
extern DisplayManager display;
|
||||
|
||||
// ── Forward declarations ──
|
||||
static void initDisplay();
|
||||
@@ -52,9 +54,9 @@ void DisplayDriverGFX::setBacklight(bool on) {
|
||||
}
|
||||
}
|
||||
|
||||
int DisplayDriverGFX::width() { return DISP_W; }
|
||||
int DisplayDriverGFX::width() { return _gfx ? _gfx->width() : DISP_W; }
|
||||
|
||||
int DisplayDriverGFX::height() { return DISP_H; }
|
||||
int DisplayDriverGFX::height() { return _gfx ? _gfx->height() : DISP_H; }
|
||||
|
||||
// ── Touch handling ──
|
||||
|
||||
@@ -96,22 +98,6 @@ int DisplayDriverGFX::dashboardTouch(int x, int y) {
|
||||
return row * cols + col;
|
||||
}
|
||||
|
||||
void DisplayDriverGFX::drawTileAt(int x, int y, int w, int h, const char* label, uint16_t bgColor) {
|
||||
// Tile background (use fillRect - LovyanGFX may not have fillRoundRect)
|
||||
_gfx->fillRect(x, y, w, h, bgColor);
|
||||
|
||||
// Tile border
|
||||
_gfx->drawRect(x, y, w, h, 0xFFFF);
|
||||
|
||||
// Tile label
|
||||
_gfx->setTextColor(0xFFFF);
|
||||
_gfx->setTextSize(2);
|
||||
int textLen = strlen(label);
|
||||
int textW = textLen * 12;
|
||||
_gfx->setCursor(x + w/2 - textW/2, y + h/2 - 10);
|
||||
_gfx->print(label);
|
||||
}
|
||||
|
||||
HoldState DisplayDriverGFX::updateHold(unsigned long holdMs) {
|
||||
HoldState state;
|
||||
|
||||
@@ -256,24 +242,18 @@ void DisplayDriverGFX::drawDashboard(const ScreenState& state) {
|
||||
_gfx->setCursor(DISP_W - 100, 10);
|
||||
_gfx->printf("WiFi:%s", state.wifiSsid.length() > 0 ? "ON" : "OFF");
|
||||
|
||||
// Tiles: 2 rows × 4 columns
|
||||
constexpr int cols = 4;
|
||||
constexpr int rows = 2;
|
||||
constexpr int tileW = DISP_W / cols;
|
||||
constexpr int tileH = (DISP_H - 30) / rows;
|
||||
constexpr int margin = 8;
|
||||
// Get tile layouts from library helper
|
||||
int tileCount = display.calculateDashboardLayouts(30, 8);
|
||||
const TileLayout* layouts = display.getTileLayouts();
|
||||
|
||||
// Draw placeholder tiles (8 total for 2x4 grid)
|
||||
const char* tileLabels[] = { "1", "2", "3", "4", "5", "6", "7", "8" };
|
||||
|
||||
for(int i = 0; i < 8; i++) {
|
||||
int col = i % cols;
|
||||
int row = i / cols;
|
||||
|
||||
int x = col * tileW + margin;
|
||||
int y = 30 + row * tileH + margin;
|
||||
int w = tileW - 2 * margin;
|
||||
int h = tileH - 2 * margin;
|
||||
for(int i = 0; i < tileCount && i < 8; i++) {
|
||||
const TileLayout& lay = layouts[i];
|
||||
int x = lay.x;
|
||||
int y = lay.y;
|
||||
int w = lay.w;
|
||||
int h = lay.h;
|
||||
|
||||
// Tile background
|
||||
_gfx->fillRoundRect(x, y, w, h, 8, 0x0220);
|
||||
@@ -281,10 +261,10 @@ void DisplayDriverGFX::drawDashboard(const ScreenState& state) {
|
||||
// Tile border
|
||||
_gfx->drawRoundRect(x, y, w, h, 8, 0xFFFF);
|
||||
|
||||
// Tile number
|
||||
// Tile label
|
||||
_gfx->setTextColor(0xFFFF);
|
||||
_gfx->setTextSize(2);
|
||||
_gfx->setCursor(x + w / 2 - 10, y + h / 2 - 10);
|
||||
_gfx->setCursor(x + w/2 - 10, y + h/2 - 10);
|
||||
_gfx->print(tileLabels[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,6 @@ public:
|
||||
int width() override;
|
||||
int height() override;
|
||||
|
||||
// Dashboard tiles - library handles grid math, we just draw
|
||||
void drawTileAt(int x, int y, int w, int h, const char* label, uint16_t bgColor) override;
|
||||
|
||||
// ── Internal ──
|
||||
static DisplayDriverGFX& instance();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user