30#define ALLEGRO_UNSTABLE 1
53 memset(&ev, 0,
sizeof(ev));
54 ev.type = down ? ALLEGRO_EVENT_MOUSE_BUTTON_DOWN : ALLEGRO_EVENT_MOUSE_BUTTON_UP;
61int main(
int argc,
char** argv) {
66 if (!al_init() || !al_init_font_addon()) {
70 ALLEGRO_FONT*
font = al_create_builtin_font();
78 al_destroy_font(
font);
87 expect_true(
"listbox created", win >= 0 && lb >= 0);
94 expect_true(
"short items fit the widget", narrow > 0.0f && narrow < 120.0f);
98 "GET https://api.example.com/v1/some/quite/long/resource/path?with=query");
100 expect_true(
"content width follows the widest item", wide > narrow);
101 expect_true(
"content overflows the widget", wide > 120.0f);
112 float sb =
gui->style.scrollbar_size;
113 float rows_h = 80.0f - sb;
146 al_destroy_font(
font);
static void expect_true(const char *label, int cond)
static void mouse_button(N_GUI_CTX *gui, int down, float x, float y)
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_add_listbox(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int selection_mode, void(*on_select)(int, int, int, void *), void *user_data)
Add a listbox widget.
float n_gui_listbox_get_h_scroll(N_GUI_CTX *ctx, int widget_id)
get a listbox's horizontal scroll offset in pixels (0 = leftmost)
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
#define N_GUI_WIN_FIXED_POSITION
disable window dragging (default:enable)
int n_gui_listbox_add_item(N_GUI_CTX *ctx, int widget_id, const char *text)
add an item to a listbox widget
void n_gui_listbox_set_h_scroll(N_GUI_CTX *ctx, int widget_id, float px)
set a listbox's horizontal scroll offset in pixels
#define N_GUI_SELECT_SINGLE
single item selection
#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_listbox_get_selected(N_GUI_CTX *ctx, int widget_id)
get the index of the first selected item in a listbox
float n_gui_listbox_content_width(N_GUI_CTX *ctx, int widget_id)
width the widest item of a listbox needs to be drawn in full
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_listbox_clear(N_GUI_CTX *ctx, int widget_id)
remove all items from a listbox widget
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
void n_gui_window_set_flags(N_GUI_CTX *ctx, int window_id, int flags)
Set feature flags on a window.
#define N_GUI_SHAPE_RECT
rectangle shape (default)
int n_gui_add_button(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, int shape, void(*on_click)(int, void *), void *user_data)
Add a button widget to a window.
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
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.