// widgetTimer.h  -- Timer widget API
#ifndef WIDGET_TIMER_H
#define WIDGET_TIMER_H

#include "../core/dvxWidget.h"

typedef struct {
    WidgetT *(*create)(WidgetT *parent, int32_t intervalMs, bool repeat);
    void     (*start)(WidgetT *w);
    void     (*stop)(WidgetT *w);
    void     (*setInterval)(WidgetT *w, int32_t intervalMs);
    bool     (*isRunning)(const WidgetT *w);
    void     (*updateTimers)(void);
} TimerApiT;

static inline const TimerApiT *dvxTimerApi(void) {
    static const TimerApiT *sApi;
    if (!sApi) { sApi = (const TimerApiT *)wgtGetApi("timer"); }
    return sApi;
}

#define wgtTimer(parent, intervalMs, repeat) dvxTimerApi()->create(parent, intervalMs, repeat)
#define wgtTimerStart(w)                     dvxTimerApi()->start(w)
#define wgtTimerStop(w)                      dvxTimerApi()->stop(w)
#define wgtTimerSetInterval(w, intervalMs)   dvxTimerApi()->setInterval(w, intervalMs)
#define wgtTimerIsRunning(w)                 dvxTimerApi()->isRunning(w)
#define wgtUpdateTimers() do { const TimerApiT *_ta = dvxTimerApi(); if (_ta) { _ta->updateTimers(); } } while(0)

#endif // WIDGET_TIMER_H
