Runtime window relayout regression test (headless): n_gui_window_set_rect moves/resizes a window and rescales its widgets from their normalized coordinates, and the window's norms follow so a later adaptive resize keeps the new proportions.
Runtime window relayout regression test (headless): n_gui_window_set_rect moves/resizes a window and rescales its widgets from their normalized coordinates, and the window's norms follow so a later adaptive resize keeps the new proportions.
#define ALLEGRO_UNSTABLE 1
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static void expect_close(
const char* label,
float got,
float want) {
if (fabsf(got - want) > 0.01f) {
n_log(
LOG_ERR,
"%s: got %.3f, expected %.3f", label, got, want);
}
}
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;
}
expect_true(
"window and widget still resolve", w != NULL && b != NULL);
if (w && b) {
}
if (w && b) {
}
{
expect_true(
"widget and window resolve", b != NULL && w != NULL);
if (b) {
}
if (b) {
}
if (b) {
}
}
{
if (tabs) {
{
expect_true(
"tab buttons resolve", t0 != NULL && t1 != NULL);
if (t0 && t1) {
}
}
}
}
{
expect_true(
"page widgets created", page >= 0 && r0 >= 0 && r1 >= 0);
{
expect_true(
"page rows resolve", a != NULL && c != NULL);
if (a && c) {
}
}
{
if (c)
expect_close(
"kept axis scales from its refreshed norm", c->
y, 120.0f);
}
}
if (w) {
}
return 1;
}
return 0;
}
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.