29#define ALLEGRO_UNSTABLE 1
52 " -V log level: LOG_NULL, LOG_NOTICE, LOG_INFO, LOG_ERR, LOG_DEBUG\n"
62 while ((
getoptret = getopt(argc, argv,
"hvV:")) != EOF) {
65 fprintf(stderr,
"build date: %s %s\n", __DATE__, __TIME__);
68 if (!strcmp(
"LOG_NULL", optarg))
70 else if (!strcmp(
"LOG_NOTICE", optarg))
72 else if (!strcmp(
"LOG_INFO", optarg))
74 else if (!strcmp(
"LOG_ERR", optarg))
76 else if (!strcmp(
"LOG_DEBUG", optarg))
79 fprintf(stderr,
"%s is not a valid log level\n", optarg);
88 if (optopt ==
'V') fprintf(stderr,
"\n Missing log level\n");
96int main(
int argc,
char** argv) {
99 if (!al_init() || !al_init_font_addon()) {
103 ALLEGRO_FONT*
font = al_create_builtin_font();
111 al_destroy_font(
font);
121 float nw = 0.0f, nh = 0.0f;
124 expect_true(
"wide label needs less than it has", nw > 0.0f && nw <= 300.0f);
125 expect_true(
"wide label needs one line", nh > 0.0f && nh <= 20.0f);
131 float nw = 0.0f, nh = 0.0f;
135 expect_true(
"narrow label reports the width it needs", nw > 40.0f);
141 float nw = 0.0f, nh = 0.0f;
143 "A justified label wraps its text to the width it is given, so a "
144 "paragraph in a box one line tall is drawn clipped and grows an "
145 "inner scrollbar instead of reporting anything.";
148 expect_true(
"justified label reports the height it needs", nh > 14.0f);
154 expect_true(
"justified label fits once given the reported height",
161 float wide_h = 0.0f, narrow_h = 0.0f;
163 "Wrapping is a function of the width the label is given, so the "
164 "narrower box needs the taller one of the two.";
169 expect_true(
"narrower wrapping needs more height", narrow_h > wide_h);
182 al_destroy_font(
font);
void process_args(int argc, char **argv)
static void expect_true(const char *label, int cond)
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.
#define N_GUI_ALIGN_LEFT
left aligned text
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.
N_GUI_WIDGET * n_gui_get_widget(N_GUI_CTX *ctx, int widget_id)
Get a widget 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.
int n_gui_label_fits(N_GUI_CTX *ctx, int widget_id, float *needed_w, float *needed_h)
Report whether a label's text is drawn in full inside its own widget box.
#define N_GUI_ALIGN_JUSTIFIED
justified text (spread words to fill width)
#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_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.