Label overflow regression test (headless): n_gui_label_fits reports a single-line label whose text is drawn truncated and a justified label whose wrapped text is drawn clipped, and hands back the size that shows all of it.
Label overflow regression test (headless): n_gui_label_fits reports a single-line label whose text is drawn truncated and a justified label whose wrapped text is drawn clipped, and hands back the size that shows all of it.
#define ALLEGRO_UNSTABLE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
if (!cond) {
}
}
static void usage(
void) {
fprintf(stderr,
" -v version\n"
" -V log level: LOG_NULL, LOG_NOTICE, LOG_INFO, LOG_ERR, LOG_DEBUG\n"
" -h help\n");
}
while ((
getoptret = getopt(argc, argv,
"hvV:")) != EOF) {
case 'v':
fprintf(stderr, "build date: %s %s\n", __DATE__, __TIME__);
exit(0);
case 'V':
if (!strcmp("LOG_NULL", optarg))
else if (!strcmp("LOG_NOTICE", optarg))
else if (!strcmp("LOG_INFO", optarg))
else if (!strcmp("LOG_ERR", optarg))
else if (!strcmp("LOG_DEBUG", optarg))
else {
fprintf(stderr, "%s is not a valid log level\n", optarg);
exit(1);
}
break;
case 'h':
exit(0);
default:
case '?':
if (optopt == 'V') fprintf(stderr, "\n Missing log level\n");
exit(1);
}
}
}
int main(
int argc,
char** argv) {
if (!al_init() || !al_init_font_addon()) {
return 1;
}
ALLEGRO_FONT*
font = al_create_builtin_font();
return 1;
}
return 1;
}
{
float nw = 0.0f, nh = 0.0f;
expect_true(
"wide label needs less than it has", nw > 0.0f && nw <= 300.0f);
expect_true(
"wide label needs one line", nh > 0.0f && nh <= 20.0f);
}
{
float nw = 0.0f, nh = 0.0f;
expect_true(
"narrow label reports the width it needs", nw > 40.0f);
}
{
float nw = 0.0f, nh = 0.0f;
const char* para =
"A justified label wraps its text to the width it is given, so a "
"paragraph in a box one line tall is drawn clipped and grows an "
"inner scrollbar instead of reporting anything.";
expect_true(
"justified label reports the height it needs", nh > 14.0f);
if (w) {
expect_true(
"justified label fits once given the reported height",
}
}
{
float wide_h = 0.0f, narrow_h = 0.0f;
const char* para =
"Wrapping is a function of the width the label is given, so the "
"narrower box needs the taller one of the two.";
expect_true(
"narrower wrapping needs more height", narrow_h > wide_h);
}
{
}
return 1;
}
return 0;
}
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.