// widgetListBox.c — ListBox widget #include "widgetInternal.h" // ============================================================ // wgtListBox // ============================================================ WidgetT *wgtListBox(WidgetT *parent) { WidgetT *w = widgetAlloc(parent, WidgetListBoxE); if (w) { w->as.listBox.selectedIdx = -1; } return w; } // ============================================================ // wgtListBoxGetSelected // ============================================================ int32_t wgtListBoxGetSelected(const WidgetT *w) { if (!w || w->type != WidgetListBoxE) { return -1; } return w->as.listBox.selectedIdx; } // ============================================================ // wgtListBoxSetItems // ============================================================ void wgtListBoxSetItems(WidgetT *w, const char **items, int32_t count) { if (!w || w->type != WidgetListBoxE) { return; } w->as.listBox.items = items; w->as.listBox.itemCount = count; if (w->as.listBox.selectedIdx >= count) { w->as.listBox.selectedIdx = -1; } } // ============================================================ // wgtListBoxSetSelected // ============================================================ void wgtListBoxSetSelected(WidgetT *w, int32_t idx) { if (!w || w->type != WidgetListBoxE) { return; } w->as.listBox.selectedIdx = idx; }