30#define ALLEGRO_UNSTABLE 1
44static void expect_close(
const char* label,
float got,
float want) {
45 if (fabsf(got - want) > 0.01f) {
46 n_log(
LOG_ERR,
"%s: got %.3f, expected %.3f", label, got, want);
61 " -V log level: LOG_NULL, LOG_NOTICE, LOG_INFO, LOG_ERR, LOG_DEBUG\n"
71 while ((
getoptret = getopt(argc, argv,
"hvV:")) != EOF) {
74 fprintf(stderr,
"build date: %s %s\n", __DATE__, __TIME__);
77 if (!strcmp(
"LOG_NULL", optarg))
79 else if (!strcmp(
"LOG_NOTICE", optarg))
81 else if (!strcmp(
"LOG_INFO", optarg))
83 else if (!strcmp(
"LOG_ERR", optarg))
85 else if (!strcmp(
"LOG_DEBUG", optarg))
88 fprintf(stderr,
"%s is not a valid log level\n", optarg);
97 if (optopt ==
'V') fprintf(stderr,
"\n Missing log level\n");
105int main(
int argc,
char** argv) {
108 if (!al_init() || !al_init_font_addon()) {
112 ALLEGRO_FONT*
font = al_create_builtin_font();
120 al_destroy_font(
font);
137 expect_true(
"window and widget still resolve", w != NULL && b != NULL);
173 expect_true(
"widget and window resolve", b != NULL && w != NULL);
211 expect_true(
"tab buttons resolve", t0 != NULL && t1 != NULL);
239 expect_true(
"page widgets created", page >= 0 && r0 >= 0 && r1 >= 0);
245 expect_true(
"page rows resolve", a != NULL && c != NULL);
257 if (c)
expect_close(
"kept axis scales from its refreshed norm", c->
y, 120.0f);
270 al_destroy_font(
font);
void process_args(int argc, char **argv)
static void expect_true(const char *label, int cond)
static void expect_close(const char *label, float got, float want, float tol)
FONT * font
the default 8x8 font, valid after allegro_init()
float button_h
height of each tab button
float x
position x on screen
float norm_x
normalized position x (0.0-1.0 fraction of reference display width)
int button_ids[16]
toggle button widget IDs
float x
position x relative to parent window
float norm_h
normalized height (fraction of reference display height, used in SCALE mode)
float button_w
width of each tab button
float norm_w
normalized width (fraction of reference display width, used in SCALE mode)
float y
position y relative to parent window
float norm_w
normalized width (fraction of parent window w)
float x
x origin of first tab button
float y
position y on screen
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.
void n_gui_window_set_rect(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h)
Move and resize a window at runtime, reflowing its widgets.
void n_gui_widget_set_rect(N_GUI_CTX *ctx, int widget_id, float x, float y, float w, float h)
Move and resize a widget after creation.
void n_gui_tab_free(N_GUI_TAB_PANEL **panel)
free a tab panel (does not destroy the N_GUI widgets)
int n_gui_tab_add(N_GUI_TAB_PANEL *panel, const char *label)
add a tab to the panel, returns tab index
N_GUI_WIDGET * n_gui_get_widget(N_GUI_CTX *ctx, int widget_id)
Get a widget pointer by id.
N_GUI_WINDOW * n_gui_get_window(N_GUI_CTX *ctx, int window_id)
Get a window pointer by id.
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_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
N_GUI_TAB_PANEL * n_gui_tab_create(N_GUI_CTX *ctx, int window_id, float x, float y, float button_w, float button_h, void(*on_tab_change)(int, void *), void *user_data)
create a tab panel in an existing window
void n_gui_tab_relayout(N_GUI_TAB_PANEL *panel, float x, float y, float button_w, float button_h)
Move/resize a tab panel's button row after creation.
#define N_GUI_SHAPE_RECT
rectangle shape (default)
void n_gui_window_set_rect_axes(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int scale_x, int scale_y)
n_gui_window_set_rect with per-axis control over the widget reflow.
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.
tab panel built from toggle buttons with content window management
A pseudo window that contains widgets.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#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_NULL
no log output
#define LOG_INFO
informational
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.