Completions offered under a textarea while it is typed in (headless).
The separator set is what makes it usable in a field holding a list: with "," the word being completed is the one the cursor is in, and picking one replaces that word and leaves the rest of the line alone.
#define ALLEGRO_UNSTABLE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if (!cond) {
} else {
}
}
static void expect_text(
const char* label,
const char* got,
const char* want) {
if (!got || strcmp(got, want) != 0) {
n_log(
LOG_ERR,
"%s: FAILED, got \"%s\" wanted \"%s\"", label, got ? got :
"(null)", want);
} else {
}
}
static const char* words[] = {"sunset", "sunsets", "sunrise", "sunflower",
"beach", "berlin", "bergen", NULL};
size_t n = strlen(prefix);
int i = 0;
(void)user_data;
for (i = 0; words[i]; i++) {
}
}
(void)prefix;
(void)sink;
(void)user_data;
}
static ALLEGRO_EVENT
key_event(
int keycode) {
ALLEGRO_EVENT ev;
memset(&ev, 0, sizeof(ev));
ev.type = ALLEGRO_EVENT_KEY_CHAR;
ev.keyboard.keycode = keycode;
return ev;
}
ev.keyboard.unichar = (int)(unsigned char)c;
return ev;
}
while (*s) {
s++;
}
}
int win, field, plain;
if (!al_init() || !al_init_font_addon()) {
return 1;
}
font = al_create_builtin_font();
return 1;
}
return 1;
}
{
expect_true(
"a key that does not change the word does not ask again",
}
"sunsets");
"beach, sunrise");
expect_true(
"the panel followed the cursor back into the first word",
expect_text(
"the first word is completed and the tail is kept",
expect_true(
"a provider that answers nothing shows nothing",
{
}
return 1;
}
return 0;
}
static void expect_true(const char *label, int cond)
static ALLEGRO_EVENT key_event(int keycode, unsigned int modifiers)
Build a key event for keycode with modifiers.
static void nothing(const char *prefix, N_GUI_SUGGEST_SINK *sink, void *user_data)
A provider that answers nothing, whatever it is asked.
static void vocabulary(const char *prefix, N_GUI_SUGGEST_SINK *sink, void *user_data)
A vocabulary to complete against, the way a catalog would answer.
static char last_prefix[64]
The last prefix the provider was given.
static void expect_text(const char *label, const char *got, const char *want)
Assert two strings are equal.
static void type(N_GUI_CTX *gui, const char *s)
Type a whole string into whatever has focus.
static ALLEGRO_EVENT char_event(char c)
Build a key event that types c.
static int asks
How many times the provider was asked.
FONT * font
the default 8x8 font, valid after allegro_init()
void n_gui_set_display_size(N_GUI_CTX *ctx, float w, float h)
set the display (viewport) size so global scrollbars can be computed.
int n_gui_suggest_add(N_GUI_SUGGEST_SINK *sink, const char *text)
add one completion to a suggestion sink
#define N_GUI_ALIGN_LEFT
left aligned text
void n_gui_textarea_set_text(N_GUI_CTX *ctx, int widget_id, const char *text)
set the text content of a textarea widget
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
int n_gui_add_label(N_GUI_CTX *ctx, int window_id, const char *text, float x, float y, float w, float h, int align)
Add a static text label.
void n_gui_set_focus(N_GUI_CTX *ctx, int widget_id)
Set keyboard focus to a specific widget.
#define N_GUI_WIN_FRAMELESS
frameless window: no title bar drawn, drag via window body unless N_GUI_WIN_FIXED_POSITION is also se...
int n_gui_add_window(N_GUI_CTX *ctx, const char *title, float x, float y, float w, float h)
Add a new pseudo-window to the context.
N_GUI_CTX * n_gui_new_ctx(ALLEGRO_FONT *default_font)
Create a new GUI context.
void n_gui_textarea_set_suggest(N_GUI_CTX *ctx, int widget_id, N_GUI_SUGGEST_FN fn, const char *separators, void *user_data)
offer completions in a textarea
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
const char * n_gui_textarea_get_text(N_GUI_CTX *ctx, int widget_id)
get the text content of a textarea widget
size_t n_gui_textarea_get_text_length(N_GUI_CTX *ctx, int widget_id)
return the current text length in bytes
void n_gui_open_window(N_GUI_CTX *ctx, int window_id)
Open (show) a window.
int n_gui_textarea_suggest_is_open(N_GUI_CTX *ctx, int widget_id)
is a textarea's completion panel up
void n_gui_window_set_flags(N_GUI_CTX *ctx, int window_id, int flags)
Set feature flags on a window.
int n_gui_add_textarea(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int multiline, size_t char_limit, void(*on_change)(int, const char *, void *), void *user_data)
Add a text area widget.
The top-level GUI context that holds all windows.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL ).
#define LOG_NOTICE
normal but significant condition
#define LOG_INFO
informational
Common headers and low-level functions & define.
handle textarea key input.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.