// dropdown.h  -- Dropdown widget API
#ifndef DROPDOWN_H
#define DROPDOWN_H

#include "../../../libs/kpunch/libdvx/dvxWgt.h"

typedef struct {
    WidgetT *(*create)(WidgetT *parent);
    void     (*setItems)(WidgetT *w, const char **items, int32_t count);
    int32_t  (*getSelected)(const WidgetT *w);
    void     (*setSelected)(WidgetT *w, int32_t idx);
    void     (*addItem)(WidgetT *w, const char *text);
    void     (*removeItem)(WidgetT *w, int32_t idx);
    void     (*clear)(WidgetT *w);
    const char *(*getItem)(const WidgetT *w, int32_t idx);
    int32_t  (*getItemCount)(const WidgetT *w);
} DropdownApiT;

static inline const DropdownApiT *dvxDropdownApi(void) {
    static const DropdownApiT *sApi;
    if (!sApi) { sApi = (const DropdownApiT *)wgtGetApi("dropdown"); }
    return sApi;
}

#define wgtDropdown(parent)                  dvxDropdownApi()->create(parent)
#define wgtDropdownSetItems(w, items, count)  dvxDropdownApi()->setItems(w, items, count)
#define wgtDropdownGetSelected(w)            dvxDropdownApi()->getSelected(w)
#define wgtDropdownSetSelected(w, idx)       dvxDropdownApi()->setSelected(w, idx)
#define wgtDropdownAddItem(w, text)          dvxDropdownApi()->addItem(w, text)
#define wgtDropdownRemoveItem(w, idx)        dvxDropdownApi()->removeItem(w, idx)
#define wgtDropdownClear(w)                  dvxDropdownApi()->clear(w)
#define wgtDropdownGetItem(w, idx)           dvxDropdownApi()->getItem(w, idx)
#define wgtDropdownGetItemCount(w)           dvxDropdownApi()->getItemCount(w)

#endif // DROPDOWN_H
