#define ALLEGRO_UNSTABLE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int opt;
while ((opt = getopt(argc, argv, "V:")) != -1) {
switch (opt) {
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
return -1;
break;
default:
return -1;
}
}
return 0;
}
static void expect_close(
const char* label,
float got,
float want,
float tol) {
float d = got - want;
if (d < 0) d = -d;
if (d > tol) {
label, got, want, tol);
} else {
}
}
if (!cond) {
} else {
}
}
int main(
int argc,
char** argv) {
fprintf(stderr, "Usage: %s [-V LOG_LEVEL]\n", argv[0]);
return 2;
}
if (!al_init()) {
return 1;
}
if (!al_init_font_addon()) {
return 1;
}
ALLEGRO_FONT* font = al_create_builtin_font();
if (!font) {
return 1;
}
al_destroy_font(font);
return 1;
}
expect_true(
"add button widget exists", add_btn != NULL);
expect_true(
"row 0 key widget exists", row0_key != NULL);
add_btn->
y >= row0_key->
y + row0_key->
h - 0.5f);
expect_true(
"+ still exists after resize", add_btn != NULL);
add_btn->
y >= row0_key->
y + row0_key->
h - 0.5f);
float scaled_row_h = row0_key->
h;
n_log(
LOG_INFO,
"row 0 scaled height after resize: %.3f", scaled_row_h);
for (
int i = kv->
nb_rows - 1; i >= 0; i--) {
}
expect_true(
"+ button below Key header (after clear+add)",
add_btn->
y >= lbl_key->
y + lbl_key->
h - 0.5f);
int last_active = -1;
for (
int i = 0; i < kv->
nb_rows; i++) {
}
expect_true(
"at least one active row exists", last_active >= 0);
if (last_active >= 0) {
new_key->
h, scaled_row_h, 0.5f);
add_btn->
y >= new_key->
y + new_key->
h - 0.5f);
}
add_btn != NULL && add_btn->
y > 0.0f);
int rows_after_first_fill = kv->
nb_rows;
expect_true(
"reload reuses slots (nb_rows does not grow)",
kv->
nb_rows == rows_after_first_fill);
{
int active = -1;
for (
int i = 0; i < kv->
nb_rows; i++) {
active = i;
break;
}
}
expect_true(
"single-column: one active row", active >= 0);
if (active >= 0) {
wk && wwin && wk->
w > wwin->
w * 0.5f);
}
}
{
float y_before = lk_before ? lk_before->
y : 0.0f;
lk_after && lk_after->
y > y_before + 10.0f);
}
{
if (kv2) {
float h_before = r0 ? r0->
h : 0.0f;
expect_true(
"move-policy row has a height", h_before > 0.0f);
expect_close(
"move-policy row keeps its height", r0 ? r0->
h : -1.0f, h_before, 0.5f);
expect_close(
"move-policy new row matches", r1 ? r1->
h : -1.0f, h_before, 0.5f);
float w_before = k_before ? k_before->
w : 0.0f;
k_after && k_after->
w > w_before + 1.0f);
}
}
al_destroy_font(font);
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)
int visible
visibility flag
int nb_rows
total rows (including removed)
int btn_add
button widget ID for "+" add row
int remove_id
button widget ID for the remove action
N_GUI_KV_ROW rows[128]
row storage
int key_id
textarea widget ID for the key
int desc_id
textarea widget ID for the description
int lbl_key
label widget ID for "Key" header
float y
position y relative to parent window
int active
1 if active, 0 if removed
int lbl_value
label widget ID for "Value" header
int enabled_id
checkbox widget ID for the enabled toggle
int value_id
textarea widget ID for the value
void n_gui_set_display_size(N_GUI_CTX *ctx, float w, float h)
Set the display (viewport) size for global scrollbar computation.
void n_gui_kvtable_set_top_offset(N_GUI_KVTABLE *table, float top_offset)
reserve top_offset unscaled pixels above the header row so other widgets (a toolbar,...
void n_gui_kvtable_relayout(N_GUI_KVTABLE *table)
re-apply layout to all KV table widgets (positions, sizes, normalized coords).
int n_gui_kvtable_get_count(const N_GUI_KVTABLE *table)
get the number of active rows
N_GUI_KVTABLE * n_gui_kvtable_create(N_GUI_CTX *ctx, int window_id, float row_height, float padding, void(*on_remove)(int, void *), void *user_data)
create a KV table in an existing window
#define N_GUI_WIN_RESIZE_SCALE
reposition AND resize proportionally, child widgets scale too
void n_gui_kvtable_free(N_GUI_KVTABLE **table)
free a KV table (does not destroy the N_GUI widgets)
void n_gui_window_set_resize_policy(N_GUI_CTX *ctx, int window_id, int policy)
Set per-window resize policy (N_GUI_WIN_RESIZE_NONE / _MOVE / _SCALE).
void n_gui_kvtable_clear(N_GUI_KVTABLE *table)
remove every row at once.
void n_gui_kvtable_set_placeholders(N_GUI_KVTABLE *table, const char *key_hint, const char *value_hint)
set the placeholder/hint text shown in each row's key (and value) textarea while it is empty.
void n_gui_kvtable_remove_row(N_GUI_KVTABLE *table, int row_index)
remove a row by index (hides widgets, marks inactive)
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_set_resize_mode(N_GUI_CTX *ctx, int mode)
Set context-level resize mode: N_GUI_RESIZE_VIRTUAL (default) or N_GUI_RESIZE_ADAPTIVE.
void n_gui_kvtable_set_columns(N_GUI_KVTABLE *table, int show_value, int show_desc, int show_enabled)
choose which optional columns are shown: Value, Description, and the enabled checkbox.
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
int n_gui_kvtable_add_row(N_GUI_KVTABLE *table, const char *key, const char *value, const char *description, int enabled)
add a row to the KV table
#define N_GUI_WIN_RESIZE_MOVE
reposition proportionally, keep pixel size
#define N_GUI_RESIZE_ADAPTIVE
virtual size tracks display; windows adapt per their resize_policy
The top-level GUI context that holds all windows.
key-value table built from textareas, checkboxes, and buttons
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.