DVX_GUI/widgets/textInput/textInpt.h

60 lines
3.5 KiB
C

// textInpt.h -- Text input widget API
#ifndef TEXTINPT_H
#define TEXTINPT_H
#include "../../core/dvxWgt.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);
void (*setCaptureTabs)(WidgetT *w, bool capture);
void (*setTabWidth)(WidgetT *w, int32_t width);
void (*setUseTabChar)(WidgetT *w, bool useChar);
bool (*findNext)(WidgetT *w, const char *needle, bool caseSensitive, bool forward);
int32_t (*replaceAll)(WidgetT *w, const char *needle, const char *replacement, bool caseSensitive);
void (*setLineDecorator)(WidgetT *w, uint32_t (*fn)(int32_t, uint32_t *, void *), void *ctx);
int32_t (*getCursorLine)(const WidgetT *w);
void (*setGutterClick)(WidgetT *w, void (*fn)(WidgetT *, int32_t));
int32_t (*getWordAtCursor)(const WidgetT *w, char *buf, int32_t bufSize);
} 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)
#define wgtTextAreaSetCaptureTabs(w, capture) dvxTextInputApi()->setCaptureTabs(w, capture)
#define wgtTextAreaSetTabWidth(w, width) dvxTextInputApi()->setTabWidth(w, width)
#define wgtTextAreaSetUseTabChar(w, useChar) dvxTextInputApi()->setUseTabChar(w, useChar)
#define wgtTextAreaFindNext(w, needle, caseSens, fwd) dvxTextInputApi()->findNext(w, needle, caseSens, fwd)
#define wgtTextAreaReplaceAll(w, needle, repl, caseSens) dvxTextInputApi()->replaceAll(w, needle, repl, caseSens)
#define wgtTextAreaSetLineDecorator(w, fn, ctx) dvxTextInputApi()->setLineDecorator(w, fn, ctx)
#define wgtTextAreaGetCursorLine(w) dvxTextInputApi()->getCursorLine(w)
#define wgtTextAreaSetGutterClick(w, fn) dvxTextInputApi()->setGutterClick(w, fn)
#define wgtTextAreaGetWordAtCursor(w, buf, sz) dvxTextInputApi()->getWordAtCursor(w, buf, sz)
#endif // TEXTINPT_H