// WidgetUpdater.h - Gestion de la mise à jour des widgets de l'interface
#ifndef WIDGET_UPDATER_H
#define WIDGET_UPDATER_H
#include <TFT_eSPI.h>
class UpdatableWidget {
public:
virtual void draw(TFT_eSPI& tft) = 0;
virtual void update(TFT_eSPI& tft, bool forceRedraw = false) = 0;
virtual bool needsUpdate() = 0;
virtual void setDirty(bool dirty) = 0;
virtual bool isDirty() = 0;
virtual void markDirty() { setDirty(true); }
protected:
int widgetX, widgetY, widgetW, widgetH;
};
class WidgetManager {
private:
static const int MAX_WIDGETS = 30;
UpdatableWidget* widgets[MAX_WIDGETS];
int widgetCount;
unsigned long lastUpdate;
int updateInterval;
public:
WidgetManager() : widgetCount(0), lastUpdate(0), updateInterval(100) {}
void addWidget(UpdatableWidget* widget) {
if (widgetCount < MAX_WIDGETS) {
widgets[widgetCount++] = widget;
}
}
void updateAll(TFT_eSPI& tft, bool forceAll = false) {
unsigned long now = millis();
if (forceAll || (now - lastUpdate) >= updateInterval) {
for (int i = 0; i < widgetCount; i++) {
if (forceAll || widgets[i]->needsUpdate() || widgets[i]->isDirty()) {
widgets[i]->update(tft, true);
widgets[i]->setDirty(false);
}
}
lastUpdate = now;
}
}
void forceRedraw() {
for (int i = 0; i < widgetCount; i++) {
widgets[i]->setDirty(true);
}
}
void clear() {
widgetCount = 0;
}
};
#endif