DVX_GUI/widgets/widgetTextInput.h

42 lines
2 KiB
C

// widgetTextInput.h -- Text input widget API
#ifndef WIDGET_TEXTINPUT_H
#define WIDGET_TEXTINPUT_H
#include "../core/dvxWidget.h"
// Colorize callback: called for each visible line during paint.
// line: pointer into the buffer (NOT null-terminated).
// lineLen: number of characters in this line.
// colors: output array -- fill colors[0..lineLen-1] with color indices:
// 0 = default, 1 = keyword, 2 = string, 3 = comment,
// 4 = number, 5 = operator, 6 = type/builtin, 7 = reserved
// ctx: user context pointer.
typedef void (*TextColorFnT)(const char *line, int32_t lineLen, uint8_t *colors, void *ctx);
typedef struct {
WidgetT *(*create)(WidgetT *parent, int32_t maxLen);
WidgetT *(*password)(WidgetT *parent, int32_t maxLen);
WidgetT *(*masked)(WidgetT *parent, const char *mask);
WidgetT *(*textArea)(WidgetT *parent, int32_t maxLen);
void (*setColorize)(WidgetT *w, TextColorFnT fn, void *ctx);
void (*goToLine)(WidgetT *w, int32_t line);
void (*setAutoIndent)(WidgetT *w, bool enable);
void (*setShowLineNumbers)(WidgetT *w, bool show);
} TextInputApiT;
static inline const TextInputApiT *dvxTextInputApi(void) {
static const TextInputApiT *sApi;
if (!sApi) { sApi = (const TextInputApiT *)wgtGetApi("textinput"); }
return sApi;
}
#define wgtTextInput(parent, maxLen) dvxTextInputApi()->create(parent, maxLen)
#define wgtPasswordInput(parent, maxLen) dvxTextInputApi()->password(parent, maxLen)
#define wgtMaskedInput(parent, mask) dvxTextInputApi()->masked(parent, mask)
#define wgtTextArea(parent, maxLen) dvxTextInputApi()->textArea(parent, maxLen)
#define wgtTextAreaSetColorize(w, fn, ctx) dvxTextInputApi()->setColorize(w, fn, ctx)
#define wgtTextAreaGoToLine(w, line) dvxTextInputApi()->goToLine(w, line)
#define wgtTextAreaSetAutoIndent(w, en) dvxTextInputApi()->setAutoIndent(w, en)
#define wgtTextAreaSetShowLineNumbers(w, show) dvxTextInputApi()->setShowLineNumbers(w, show)
#endif // WIDGET_TEXTINPUT_H