refactor(display): extract tile layout logic to library helper class
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
#include "DisplayDriverTFT.h"
|
||||
#include <KlubhausCore.h>
|
||||
|
||||
extern DisplayManager display;
|
||||
|
||||
void DisplayDriverTFT::begin() {
|
||||
// Backlight
|
||||
@@ -134,25 +137,19 @@ void DisplayDriverTFT::drawDashboard(const ScreenState& st) {
|
||||
_tft.setCursor(DISPLAY_WIDTH - 50, 5);
|
||||
_tft.printf("WiFi:%s", st.wifiSsid.length() > 0 ? "ON" : "OFF");
|
||||
|
||||
// Render tiles via DisplayManager (abstracted to library)
|
||||
// For now, draw directly using our tile implementation
|
||||
constexpr int cols = 2;
|
||||
constexpr int rows = 2;
|
||||
constexpr int tileW = DISPLAY_WIDTH / cols;
|
||||
constexpr int tileH = (DISPLAY_HEIGHT - 30) / rows;
|
||||
constexpr int margin = 8;
|
||||
// Get tile layouts from library helper
|
||||
int tileCount = display.calculateDashboardLayouts(30, 8);
|
||||
const TileLayout* layouts = display.getTileLayouts();
|
||||
|
||||
const char* tileLabels[] = { "Alert", "Silent", "Status", "Reboot" };
|
||||
const uint16_t tileColors[] = { 0x0280, 0x0400, 0x0440, 0x0100 };
|
||||
|
||||
for(int i = 0; i < 4; 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 < 4; i++) {
|
||||
const TileLayout& lay = layouts[i];
|
||||
int x = lay.x;
|
||||
int y = lay.y;
|
||||
int w = lay.w;
|
||||
int h = lay.h;
|
||||
|
||||
// Tile background
|
||||
_tft.fillRoundRect(x, y, w, h, 8, tileColors[i]);
|
||||
@@ -180,7 +177,6 @@ TouchEvent DisplayDriverTFT::readTouch() {
|
||||
evt.pressed = true;
|
||||
evt.x = tx;
|
||||
evt.y = ty;
|
||||
Serial.printf("[TOUCH] x=%d, y=%d\n", tx, ty);
|
||||
}
|
||||
return evt;
|
||||
}
|
||||
@@ -196,22 +192,6 @@ void DisplayDriverTFT::transformTouch(int* x, int* y) {
|
||||
*y = temp;
|
||||
}
|
||||
|
||||
void DisplayDriverTFT::drawTileAt(int x, int y, int w, int h, const char* label, uint16_t bgColor) {
|
||||
// Tile background
|
||||
_tft.fillRoundRect(x, y, w, h, 8, bgColor);
|
||||
|
||||
// Tile border
|
||||
_tft.drawRoundRect(x, y, w, h, 8, TFT_WHITE);
|
||||
|
||||
// Tile label
|
||||
_tft.setTextColor(TFT_WHITE);
|
||||
_tft.setTextSize(2);
|
||||
int textLen = strlen(label);
|
||||
int textW = textLen * 12; // approx width
|
||||
_tft.setCursor(x + w/2 - textW/2, y + h/2 - 10);
|
||||
_tft.print(label);
|
||||
}
|
||||
|
||||
HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
||||
HoldState h;
|
||||
TouchEvent t = readTouch();
|
||||
|
||||
Reference in New Issue
Block a user