#pragma once
//Widget.h — classe de base pour tous les widgets (colonne gauche et droite)
#include <TFT_eSPI.h>
#include "Theme.h"
// ─── Classe de base Widget ────────────────────────────────────────────────
// Chaque widget connaît sa position et sait se dessiner.
// Pour ajouter un widget : hériter de Widget, implémenter draw().
class Widget {
public:
int x, y, w, h;
Widget(int _x, int _y, int _w, int _h)
: x(_x), y(_y), w(_w), h(_h) {}
virtual void draw(TFT_eSPI& tft) = 0;
// ─── Primitives partagées ────────────────────────────────────────────
void drawBackground(TFT_eSPI& tft) {
tft.fillRoundRect(x, y, w, h, RADIUS, C_PANEL);
tft.drawRoundRect(x, y, w, h, RADIUS, C_BORDER);
}
void drawLabel(TFT_eSPI& tft, int ox, int oy, const char* text) {
tft.setTextSize(1);
tft.setTextColor(C_MUTED, C_PANEL);
tft.setCursor(x + ox, y + oy);
tft.print(text);
}
void drawValue(TFT_eSPI& tft, int ox, int oy, const char* text,
uint16_t color = C_WHITE, uint8_t size = 2) {
tft.setTextSize(size);
tft.setTextColor(color, C_PANEL);
tft.setCursor(x + ox, y + oy);
tft.print(text);
}
void drawValueInt(TFT_eSPI& tft, int ox, int oy, int val,
uint16_t color = C_WHITE, uint8_t size = 2) {
tft.setTextSize(size);
tft.setTextColor(color, C_PANEL);
tft.setCursor(x + ox, y + oy);
tft.print(val);
}
// Barre de progression horizontale
void drawBar(TFT_eSPI& tft, int ox, int oy, int bw, int bh,
float ratio, uint16_t fillColor) {
tft.fillRoundRect(x+ox, y+oy, bw, bh, 2, C_BORDER);
int filled = (int)(bw * constrain(ratio, 0.0f, 1.0f));
if (filled > 0)
tft.fillRoundRect(x+ox, y+oy, filled, bh, 2, fillColor);
}
};