60 char* a = al_malloc(strlen(s) + 1);
74#define N_GUI_KEY_PRESS_FLASH_SEC 0.12
81#define N_GUI_ANIM_TAIL_SEC 0.05
86static double _clamp(
double v,
double lo,
double hi) {
87 if (v < lo)
return lo;
88 if (v > hi)
return hi;
96 if (step <= 0.0) step = 1.0;
97 double steps = round((val - min_val) / step);
98 double snapped = min_val + steps * step;
99 if (snapped < min_val) snapped = min_val;
100 if (snapped > max_val) snapped = max_val;
140 case ALLEGRO_KEY_ENTER:
141 case ALLEGRO_KEY_PAD_ENTER:
142 case ALLEGRO_KEY_SPACE:
143 case ALLEGRO_KEY_LEFT:
144 case ALLEGRO_KEY_RIGHT:
146 case ALLEGRO_KEY_DOWN:
172 for (
char* src = s; *src; src++) {
173 if (*src !=
'\r') *dst++ = *src;
198#define N_GUI_MEAS_CACHE_SIZE 1024u
199#define N_GUI_MEAS_KEY_MAX 32
219 unsigned int h = 2166136261u;
220 for (
size_t i = 0; i < len; i++) {
221 h ^= (
unsigned char)
text[i];
224 int line_h = al_get_font_line_height(
font);
225 h ^= (
unsigned int)line_h * 2654435761u;
228 e->
len == (
unsigned short)len && memcmp(e->
key,
text, len) == 0) {
235 e->
len = (
unsigned short)len;
248 size_t len = strlen(
text);
262 int bx = 0, by = 0, bw = 0, bh = 0;
264 size_t len = strlen(
text);
266 al_get_text_dimensions(
font,
text, &bx, &by, &bw, &bh);
328 if (!al_get_mouse_cursor_position(&cx, &cy))
return;
330 al_get_window_position(win->
native, &wx, &wy);
352 int want_w = (int)(win->
w + 0.5f);
353 int want_h = minimised ? (int)(
_win_tbh(win) + 0.5f) : (int)(win->
h + 0.5f);
354 int resizable = (al_get_display_flags(win->
native) & ALLEGRO_RESIZABLE) ? 1 : 0;
355 if (want_w < 1) want_w = 1;
356 if (want_h < 1) want_h = 1;
364 if (resizable && minimised) {
365 int cmin_w = (int)(win->
min_w + 0.5f);
366 if (cmin_w < 1) cmin_w = 1;
367 if (al_set_window_constraints(win->
native, cmin_w, want_h, 0, 0))
368 al_apply_window_constraints(win->
native,
true);
371 if (want_w != al_get_display_width(win->
native) || want_h != al_get_display_height(win->
native)) {
372 al_resize_display(win->
native, want_w, want_h);
375 if (resizable && !minimised) {
376 int cmin_w = (int)(win->
min_w + 0.5f);
377 int cmin_h = (int)(win->
min_h + 0.5f);
378 if (cmin_w < 1) cmin_w = 1;
379 if (cmin_h < 1) cmin_h = 1;
380 if (al_set_window_constraints(win->
native, cmin_w, cmin_h, 0, 0))
381 al_apply_window_constraints(win->
native,
true);
394 if (!
display || !info)
return 0;
396 al_get_window_position(
display, &wx, &wy);
397 int nb_adapters = al_get_num_video_adapters();
398 for (
int adapter = 0; adapter < nb_adapters; adapter++) {
399 ALLEGRO_MONITOR_INFO mi;
400 if (!al_get_monitor_info(adapter, &mi))
continue;
401 if (wx >= mi.x1 && wx < mi.x2 && wy >= mi.y1 && wy < mi.y2) {
406 return al_get_monitor_info(0, info) ? 1 : 0;
413 switch (event->type) {
414 case ALLEGRO_EVENT_MOUSE_AXES:
415 case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
416 case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
417 case ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY:
418 case ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY:
419 case ALLEGRO_EVENT_MOUSE_WARPED:
420 return event->mouse.display;
421 case ALLEGRO_EVENT_KEY_DOWN:
422 case ALLEGRO_EVENT_KEY_UP:
423 case ALLEGRO_EVENT_KEY_CHAR:
424 return event->keyboard.display;
425 case ALLEGRO_EVENT_TOUCH_BEGIN:
426 case ALLEGRO_EVENT_TOUCH_END:
427 case ALLEGRO_EVENT_TOUCH_MOVE:
428 case ALLEGRO_EVENT_TOUCH_CANCEL:
429 return event->touch.display;
430 case ALLEGRO_EVENT_DISPLAY_EXPOSE:
431 case ALLEGRO_EVENT_DISPLAY_RESIZE:
432 case ALLEGRO_EVENT_DISPLAY_CLOSE:
433 case ALLEGRO_EVENT_DISPLAY_LOST:
434 case ALLEGRO_EVENT_DISPLAY_FOUND:
435 case ALLEGRO_EVENT_DISPLAY_SWITCH_IN:
436 case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT:
437 case ALLEGRO_EVENT_DISPLAY_ORIENTATION:
438 case ALLEGRO_EVENT_DISPLAY_HALT_DRAWING:
439 case ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING:
440 return event->display.source;
474 if (
display) al_set_system_mouse_cursor(
display, (ALLEGRO_SYSTEM_MOUSE_CURSOR)shape);
493 return ctx ? ctx->
cursor_shape : ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT;
497static int _point_in_rect(
float px,
float py,
float rx,
float ry,
float rw,
float rh) {
498 return (px >= rx && px <= rx + rw && py >= ry && py <= ry + rh);
565 float ratio = viewport / content;
566 if (ratio > 1.0f) ratio = 1.0f;
567 float thumb = ratio * track_length;
568 if (thumb < thumb_min) thumb = thumb_min;
569 float max_scroll = content - viewport;
570 float track_range = track_length - thumb;
571 if (track_range <= 0 || max_scroll <= 0)
return 0;
572 float pos_ratio = (
mouse - track_start - thumb / 2.0f) / track_range;
573 if (pos_ratio < 0) pos_ratio = 0;
574 if (pos_ratio > 1) pos_ratio = 1;
575 return pos_ratio * max_scroll;
588 int max_off = total_items - visible_items;
589 if (max_off <= 0)
return 0;
591 (
float)visible_items, (
float)total_items, thumb_min);
592 int offset = (int)(scroll + 0.5f);
593 if (offset < 0) offset = 0;
594 if (offset > max_off) offset = max_off;
730 if (win && win->
id == window_id)
return node;
740 snprintf(
key,
sizeof(
key),
"%d", w->
id);
748 size_t new_cap = (*cap == 0) ? 8 : (*cap) * 2;
749 if (new_cap < *cap)
return 0;
753 if (*items && *nb > 0) {
793 t.
bg_normal = al_map_rgba(50, 50, 60, 230);
794 t.
bg_hover = al_map_rgba(70, 70, 85, 240);
795 t.
bg_active = al_map_rgba(90, 90, 110, 250);
800 t.
text_hover = al_map_rgba(255, 255, 255, 255);
827 ALLEGRO_COLOR bg_hover,
828 ALLEGRO_COLOR bg_active,
829 ALLEGRO_COLOR border,
830 ALLEGRO_COLOR border_hover,
831 ALLEGRO_COLOR border_active,
833 ALLEGRO_COLOR text_hover,
834 ALLEGRO_COLOR text_active,
835 float border_thickness,
873static ALLEGRO_COLOR
_color_mix(ALLEGRO_COLOR a, ALLEGRO_COLOR b,
float t) {
875 if (t <= 0.0f)
return a;
876 if (t >= 1.0f)
return b;
877 c.r = a.r + (b.r - a.r) * t;
878 c.g = a.g + (b.g - a.g) * t;
879 c.b = a.b + (b.b - a.b) * t;
880 c.a = a.a + (b.a - a.a) * t;
892 t.
bg_hover = al_map_rgba(255, 255, 255, 40);
893 t.
bg_active = al_map_rgba(255, 255, 255, 80);
898 t.
text_hover = al_map_rgba(255, 255, 255, 255);
914 t.
bg_hover = al_map_rgba(232, 17, 35, 220);
915 t.
bg_active = al_map_rgba(200, 10, 25, 255);
993 s.
grip_color = al_map_rgba(160, 160, 180, 200);
1110 n_log(
LOG_ERR,
"n_gui_new_ctx: failed to allocate window list");
1116 n_log(
LOG_ERR,
"n_gui_new_ctx: failed to allocate widget hash table");
1128 ctx->
cursor_shape = ALLEGRO_SYSTEM_MOUSE_CURSOR_DEFAULT;
1189 if (ctx) ctx->
dirty = 1;
1194 if (ctx->
dirty)
return 1;
1212 if ((*ctx)->windows) {
1218 if (dwin && dwin->
native) {
1224 if ((*ctx)->widgets_by_id) {
1240 if (dw <= 0 || dh <= 0)
return;
1261 if (win->
w > 0 && win->
h > 0) {
1287 win->
title[0] =
'\0';
1298 n_log(
LOG_ERR,
"n_gui_add_window: failed to allocate widget list");
1521 if (!al_set_display_flag(win->
native, ALLEGRO_MAXIMIZED, now_max ?
false :
true)) {
1522 n_log(
LOG_DEBUG,
"n_gui_maximize_window: window manager refused ALLEGRO_MAXIMIZED for window %d", window_id);
1526 ALLEGRO_MONITOR_INFO mi;
1528 al_set_window_position(win->
native, mi.x1, mi.y1);
1529 al_resize_display(win->
native, mi.x2 - mi.x1, mi.y2 - mi.y1);
1605 if (!win || !win->
native)
return;
1606 ALLEGRO_DISPLAY* d = win->
native;
1611 al_get_window_position(d, &wx, &wy);
1614 win->
native_w = (float)al_get_display_width(d);
1615 win->
native_h = (float)al_get_display_height(d);
1625 al_unregister_event_source(ctx->
event_queue, al_get_display_event_source(d));
1627 al_destroy_display(d);
1632 al_set_target_backbuffer(ctx->
display);
1643 n_log(
LOG_ERR,
"n_gui_window_detach: no window with id %d", window_id);
1651 n_log(
LOG_ERR,
"n_gui_window_detach: no event queue set, call n_gui_set_event_queue first");
1663 float shown_h = own_chrome ? win->
h : (win->
h -
_win_tbh(win));
1664 if (shown_h < 1.0f) shown_h = win->
h;
1665 int dw = (int)(win->
w + 0.5f);
1666 int dh = (int)(shown_h + 0.5f);
1676 ALLEGRO_BITMAP* prev_target = al_get_target_bitmap();
1677 int prev_new_flags = al_get_new_display_flags();
1678 int new_flags = ALLEGRO_WINDOWED;
1684 new_flags |= ALLEGRO_FRAMELESS | ALLEGRO_RESIZABLE;
1686 al_set_new_display_flags(new_flags);
1691 if (win->
title[0]) al_set_new_window_title(win->
title);
1692 int prev_pos_x = 0, prev_pos_y = 0;
1693 al_get_new_window_position(&prev_pos_x, &prev_pos_y);
1697 ALLEGRO_DISPLAY* d = al_create_display(dw, dh);
1698 al_set_new_display_flags(prev_new_flags);
1699 al_set_new_window_position(prev_pos_x, prev_pos_y);
1700 al_set_new_window_title(
"");
1701 if (prev_target) al_set_target_bitmap(prev_target);
1703 n_log(
LOG_ERR,
"n_gui_window_detach: al_create_display(%d, %d) failed for window %d", dw, dh, window_id);
1707 al_set_window_title(d, win->
caption);
1708 else if (win->
title[0])
1709 al_set_window_title(d, win->
title);
1717 if (new_flags & ALLEGRO_RESIZABLE) {
1718 int cmin_w = (int)(win->
min_w + 0.5f);
1720 if (cmin_w < 1) cmin_w = 1;
1721 if (cmin_h < 1) cmin_h = 1;
1722 if (al_set_window_constraints(d, cmin_w, cmin_h, 0, 0)) {
1723 al_apply_window_constraints(d,
true);
1726 al_register_event_source(ctx->
event_queue, al_get_display_event_source(d));
1763 if (win->
w > 0.0f && win->
h > 0.0f) {
1769 n_log(
LOG_DEBUG,
"n_gui_window_detach: window %d ('%s') detached into a %dx%d native window", window_id, win->
title, dw, dh);
1780 n_log(
LOG_ERR,
"n_gui_window_attach: no window with id %d", window_id);
1796 if (win->
w > 0.0f && win->
h > 0.0f) {
1802 n_log(
LOG_DEBUG,
"n_gui_window_attach: window %d ('%s') is a pop-up again", window_id, win->
title);
1812 return (win && win->
native) ? 1 : 0;
1822 return win ? win->
native : NULL;
1848 if (win && win->
native) n++;
1859 if (num_icons < 1) {
1860 n_log(
LOG_ERR,
"n_gui_window_set_native_icons: num_icons must be >= 1");
1864 if (!win || !win->
native) {
1865 n_log(
LOG_ERR,
"n_gui_window_set_native_icons: window %d is not detached", window_id);
1869 al_set_display_icon(win->
native, icons[0]);
1871 al_set_display_icons(win->
native, num_icons, icons);
1881 if (!win || !win->
native)
return 0;
1883 return (al_get_display_flags(win->
native) & ALLEGRO_MINIMIZED) ? 1 : 0;
2021 for (
int i = 1; i < n; i++) {
2028 if (gj > gi || (gj == gi && gi == 1 && arr[j]->z_value > tmp->
z_value)) {
2029 arr[j + 1] = arr[j];
2045 for (
int i = 0; i < n; i++) {
2093 float ox = 0.0f, oy = 0.0f;
2097 if (x) *x = ox + wgt->
x;
2098 if (y) *y = oy + wgt->
y;
2110 float bx = 0.0f, by = 0.0f, bw = 0.0f, bh = 0.0f;
2139 if (!win || !label)
return -1;
2151 if (!ctx || !ctx->
windows)
return NULL;
2155 if (!win || !win->
widgets)
continue;
2159 if (wgt && wgt->
id == widget_id)
return wgt;
2177 case ALLEGRO_KEY_LEFT:
2178 case ALLEGRO_KEY_RIGHT:
2179 case ALLEGRO_KEY_UP:
2180 case ALLEGRO_KEY_DOWN:
2181 case ALLEGRO_KEY_HOME:
2182 case ALLEGRO_KEY_END:
2183 case ALLEGRO_KEY_PGUP:
2184 case ALLEGRO_KEY_PGDN:
2185 case ALLEGRO_KEY_ENTER:
2186 case ALLEGRO_KEY_PAD_ENTER:
2226 float band = ((a->
h < b->
h) ? a->
h : b->
h) * 0.5f;
2228 if (fabsf(a->
y - b->
y) >= band)
return (a->
y < b->
y) ? -1 : 1;
2229 if (a->
x != b->
x)
return (a->
x < b->
x) ? -1 : 1;
2230 return a->
id - b->
id;
2253 if (!w || !w->
widgets)
continue;
2255 if (gn->ptr == from) {
2262 if (!win)
return -1;
2269 if (forward ? order > 0 : order < 0) {
2277 if (best)
return best->
id;
2278 return wrap ? wrap->
id : -1;
2291 switch (wgt->
type) {
2320 return (wgt && wgt->
visible) ? 1 : 0;
2410 n_log(
LOG_ERR,
"n_gui_window_set_zorder: unknown z_mode %d for window %d (expected N_GUI_ZORDER_NORMAL, N_GUI_ZORDER_ALWAYS_ON_TOP, N_GUI_ZORDER_ALWAYS_BEHIND, N_GUI_ZORDER_FIXED, or N_GUI_ZORDER_POPUP), falling back to N_GUI_ZORDER_NORMAL", z_mode, window_id);
2425 if (max_scroll <= 0)
return 0;
2427 if (step <= 0) step = 1.0;
2517 if (win) win->
flags = flags;
2526 if (win)
return win->
flags;
2536 if (!win || !win->
widgets)
return;
2538 float max_right = 0.0f;
2539 float max_bottom = 0.0f;
2545 float r = wgt->
x + wgt->
w;
2546 float b = wgt->
y + wgt->
h;
2547 if (r > max_right) max_right = r;
2548 if (b > max_bottom) max_bottom = b;
2551 float new_w = max_right + pad;
2552 float new_h = max_bottom + pad +
_win_tbh(win);
2553 if (new_w < win->min_w) new_w = win->
min_w;
2554 if (new_h < win->min_h) new_h = win->
min_h;
2567 n_log(
LOG_ERR,
"n_gui_window_set_autofit: window %d not found", window_id);
2590 float max_right = 0.0f;
2591 float max_bottom = 0.0f;
2594 if (!wgt || !wgt->
visible)
continue;
2595 float r = wgt->
x + wgt->
w;
2596 float b = wgt->
y + wgt->
h;
2597 if (r > max_right) max_right = r;
2598 if (b > max_bottom) max_bottom = b;
2608 float needed_w = max_right + border * 2.0f;
2609 if (needed_w < win->min_w) needed_w = win->
min_w;
2613 win->
x -= (needed_w - win->
w);
2620 float needed_h = max_bottom + border * 2.0f + tbh;
2621 if (needed_h < win->min_h) needed_h = win->
min_h;
2625 win->
y -= (needed_h - win->
h);
2637 if (!win || !win->
widgets)
return;
2638 float max_right = 0.0f;
2639 float max_bottom = 0.0f;
2642 if (!wgt || !wgt->
visible)
continue;
2643 float r = wgt->
x + wgt->
w;
2644 float b = wgt->
y + wgt->
h;
2650 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
2653 float text_r = wgt->
x + tw + 8.0f;
2654 if (text_r > r) r = text_r;
2658 if (r > max_right) max_right = r;
2659 if (b > max_bottom) max_bottom = b;
2680 v[0] = v[1] = v[2] = v[3] = 0.0f;
2681 h[0] =
h[1] =
h[2] =
h[3] = 0.0f;
2686 int need_v = 0, need_h = 0;
2688 if (win->
content_h > body_h) need_v = 1;
2690 if (need_v && win->
content_w > (win->
w - size)) need_h = 1;
2691 if (need_h && win->
content_h > (body_h - size)) need_v = 1;
2693 float area_w = win->
w - (need_v ? size : 0);
2694 float area_h = body_h - (need_h ? size : 0);
2697 v[0] = win->
x + win->
w - size;
2706 h[1] = win->
y + win->
h - size;
2720int 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) {
2762int n_gui_add_button_bitmap(
N_GUI_CTX* ctx,
int window_id,
const char* label,
float x,
float y,
float w,
float h, ALLEGRO_BITMAP* normal, ALLEGRO_BITMAP* hover, ALLEGRO_BITMAP* active,
void (*
on_click)(
int,
void*),
void* user_data) {
2764 if (
id < 0)
return -1;
2766 if (wgt && wgt->
data) {
2790int n_gui_add_toggle_button(
N_GUI_CTX* ctx,
int window_id,
const char* label,
float x,
float y,
float w,
float h,
int shape,
int initial_state,
void (*
on_click)(
int,
void*),
void* user_data) {
2792 if (
id < 0)
return -1;
2794 if (wgt && wgt->
data) {
2797 bd->
toggled = initial_state ? 1 : 0;
2823 snprintf(bd->
label,
sizeof(bd->
label),
"%s", label);
2848 if (ctx) ctx->
dirty = 1;
2893 for (dp = 0; dp < ncols; dp++) {
2895 if (width[dp] > 0.0f)
2898 for (dp = 0; dp < ncols; dp++) {
2900 for (cur = dp; cur < ncols; cur++)
2903 if (cur < ncols && cur != dp)
2920 if (p->
kind != wgt->
type)
continue;
2935 float ox = 0.0f, oy = 0.0f;
2973 float ox = 0.0f, oy = 0.0f;
3093 for (
int i = 0; i < count; i++) {
3106int n_gui_add_slider(
N_GUI_CTX* ctx,
int window_id,
float x,
float y,
float w,
float h,
double min_val,
double max_val,
double initial,
int mode,
void (*
on_change)(
int,
double,
void*),
void* user_data) {
3148int n_gui_add_vslider(
N_GUI_CTX* ctx,
int window_id,
float x,
float y,
float w,
float h,
double min_val,
double max_val,
double initial,
int mode,
void (*
on_change)(
int,
double,
void*),
void* user_data) {
3149 int id =
n_gui_add_slider(ctx, window_id, x, y, w,
h, min_val, max_val, initial,
mode,
on_change, user_data);
3150 if (
id < 0)
return -1;
3152 if (wgt && wgt->
data) {
3162int n_gui_add_textarea(
N_GUI_CTX* ctx,
int window_id,
float x,
float y,
float w,
float h,
int multiline,
size_t char_limit,
void (*
on_change)(
int,
const char*,
void*),
void* user_data) {
3173 memset(td, 0,
sizeof(*td));
3207int n_gui_add_checkbox(
N_GUI_CTX* ctx,
int window_id,
const char* label,
float x,
float y,
float w,
float h,
int initial_checked,
void (*
on_toggle)(
int,
int,
void*),
void* user_data) {
3222 cd->
checked = initial_checked ? 1 : 0;
3241int n_gui_add_scrollbar(
N_GUI_CTX* ctx,
int window_id,
float x,
float y,
float w,
float h,
int orientation,
int shape,
double content_size,
double viewport_size,
void (*
on_scroll)(
int,
double,
void*),
void* user_data) {
3253 sb->
content_size = content_size > 0 ? content_size : 1;
3285int n_gui_add_listbox(
N_GUI_CTX* ctx,
int window_id,
float x,
float y,
float w,
float h,
int selection_mode,
void (*
on_select)(
int,
int,
int,
void*),
void* user_data) {
3331int n_gui_add_splitpane(
N_GUI_CTX* ctx,
int window_id,
float x,
float y,
float w,
float h,
int orientation,
float ratio,
void (*
on_change)(
int,
float,
void*),
void* user_data) {
3621 id->bitmap = bitmap;
3622 id->scale_mode = scale_mode;
3680int n_gui_add_label_link(
N_GUI_CTX* ctx,
int window_id,
const char*
text,
const char* link,
float x,
float y,
float w,
float h,
int align,
void (*
on_link_click)(
int,
const char*,
void*),
void* user_data) {
3682 if (wid < 0)
return -1;
3684 if (wgt && wgt->
data) {
3704 snprintf(
key,
sizeof(
key),
"%d", widget_id);
3767 if (widget_id < 0)
return 0;
3797 if (w) w->
theme = theme;
3810 if (!ctx || !ctx->
windows)
return;
3858 if (w < 0.0f) w = 0.0f;
3859 if (
h < 0.0f)
h = 0.0f;
3870 if (it && it->
id == widget_id) {
3917 if (widget_id < 0) {
3924 n_log(
LOG_ERR,
"n_gui_set_focus: widget %d not found", widget_id);
3941 if (!win || !win->
widgets)
continue;
3944 if (w && w->
id == widget_id) {
4065 sd->
key_step = step > 0.0 ? step : 0.0;
4111 float start = 0.0f, length = 0.0f;
4112 double range = 0.0, ratio = 0.0;
4117 ratio = (range > 0) ? (sd->
value - sd->
min_val) / range : 0.0;
4120 float along =
start + (float)(ratio * (
double)length);
4148 if (!fmt || !fmt[0]) {
4165 ALLEGRO_FONT*
font = NULL;
4167 char low[32], high[32];
4175 if (!
font)
return 0.0f;
4184 widest = (a.
w > b.
w) ? a.
w : b.
w;
4269 snprintf(cd->
label,
sizeof(cd->
label),
"%s", label);
4312 if (max_scroll < 0) max_scroll = 0;
4342 sb->
content_size = content_size > 0 ? content_size : 1;
4345 if (max_scroll < 0) max_scroll = 0;
4365 item->
text[0] =
'\0';
4386 if (index < 0 || (
size_t)index >= ld->
nb_items)
return -1;
4387 if ((
size_t)index < ld->nb_items - 1) {
4388 memmove(&ld->
items[index], &ld->
items[index + 1],
4442 if (index >= 0 && (
size_t)index < ld->nb_items) {
4459 for (
size_t i = 0; i < ld->
nb_items; i++) {
4477 if (index >= 0 && (
size_t)index < ld->nb_items) {
4495 if (index < 0 || (
size_t)index >= ld->
nb_items)
return;
4514 if (max_offset < 0) max_offset = 0;
4515 if (offset < 0) offset = 0;
4516 if (offset > max_offset) offset = max_offset;
4540 if (!
font)
return 0.0f;
4541 for (i = 0; i < ld->
nb_items; i++) {
4543 if (tw > cw) cw = tw;
4575 if (px < 0.0f) px = 0.0f;
4577 if (ctx) ctx->
dirty = 1;
4604 if (ratio < sd->min_ratio) ratio = sd->
min_ratio;
4620 if (min_ratio < 0.0f) min_ratio = 0.0f;
4621 if (max_ratio > 1.0f) max_ratio = 1.0f;
4622 if (min_ratio > max_ratio) min_ratio = max_ratio;
4625 if (sd->
ratio < min_ratio) sd->
ratio = min_ratio;
4626 if (sd->
ratio > max_ratio) sd->
ratio = max_ratio;
4636 if (need <= hd->cap)
return 1;
4637 ncap = hd->
cap ? hd->
cap : 64;
4638 while (ncap < need) ncap *= 2;
4639 nd = (
unsigned char*)realloc(hd->
data, ncap);
4661 if (at >= hd->
len)
return 0;
4662 memmove(hd->
data + at, hd->
data + at + 1, hd->
len - at - 1);
4672 if (unichar >=
'0' && unichar <=
'9')
return unichar -
'0';
4673 if (unichar >=
'a' && unichar <=
'f')
return unichar -
'a' + 10;
4674 if (unichar >=
'A' && unichar <=
'F')
return unichar -
'A' + 10;
4675 if (keycode >= ALLEGRO_KEY_PAD_0 && keycode <= ALLEGRO_KEY_PAD_9)
return keycode - ALLEGRO_KEY_PAD_0;
4682 int row = (int)(hd->
cursor / (
size_t)bpr);
4683 if (visible_rows < 1) visible_rows = 1;
4694 int kc = ev->keyboard.keycode;
4695 int changed = 0, consumed = 1;
4699 if (visible_rows < 1) visible_rows = 1;
4702 case ALLEGRO_KEY_LEFT:
4705 else if (hd->
cursor > 0) {
4710 case ALLEGRO_KEY_RIGHT:
4718 case ALLEGRO_KEY_UP:
4719 if (hd->
cursor >= (
size_t)bpr) hd->
cursor -= (size_t)bpr;
4722 case ALLEGRO_KEY_DOWN:
4723 if (hd->
cursor + (
size_t)bpr <= hd->len) hd->
cursor += (size_t)bpr;
4726 case ALLEGRO_KEY_PGUP: {
4727 size_t step = (size_t)bpr * (
size_t)visible_rows;
4731 case ALLEGRO_KEY_PGDN: {
4732 size_t step = (size_t)bpr * (
size_t)visible_rows;
4736 case ALLEGRO_KEY_HOME:
4737 hd->
cursor = (ev->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL) ? 0 : hd->
cursor - (hd->
cursor % (size_t)bpr);
4740 case ALLEGRO_KEY_END:
4741 if (ev->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL) {
4744 size_t eol = hd->
cursor - (hd->
cursor % (size_t)bpr) + (
size_t)bpr - 1;
4749 case ALLEGRO_KEY_INSERT:
4752 case ALLEGRO_KEY_DELETE:
4755 case ALLEGRO_KEY_BACKSPACE:
4815 if (data && len > 0) {
4818 memcpy(hd->
data, data, len);
4932 size_t len = strlen(
text);
4992 if ((
size_t)lo > yd->
len) lo = (int)yd->
len;
4993 if ((
size_t)hi > yd->
len) hi = (int)yd->
len;
4995 if (n <= 0)
return NULL;
4997 Malloc(out,
char, (
size_t)n + 1);
4998 if (!out)
return NULL;
4999 memcpy(out, yd->
text + lo, (
size_t)n);
5015 int len = (int)yd->
len;
5017 if (end < 0) end = 0;
5019 if (end > len) end = len;
5022 if (ctx &&
start != end)
5048 if (!yd->
text || yd->
len == 0)
return;
5049 if (byte_offset < 0) byte_offset = 0;
5050 if ((
size_t)byte_offset > yd->
len) byte_offset = (int)yd->
len;
5054 for (
int it = 0; it < byte_offset; it++) {
5055 if (yd->
text[it] ==
'\n') {
5057 line_start = it + 1;
5065 float content_w = 0.0f, pane_w = w->
w;
5066 int need_hsb = 0,
visible = 1;
5069 if (max_off < 0) max_off = 0;
5071 if (target > max_off) target = max_off;
5072 if (target < 0) target = 0;
5080 float view_w = pane_w - pad * 2.0f;
5081 if (view_w < 1.0f) view_w = 1.0f;
5082 if (x < yd->h_scroll || x > yd->
h_scroll + view_w) {
5125 if (px < 0.0f) px = 0.0f;
5133 if (!s || !*s)
return 0;
5135 if (*s <
'0' || *s >
'9')
return 0;
5146 long la = atol(a), lb = atol(b);
5147 return (la < lb) ? -1 : (la > lb) ? 1
5150 return strcasecmp(a, b);
5157 if (gd->
nb_rows > 0)
return -1;
5163 if (!tmp)
return -1;
5201 if (!gd || gd->
rows_cap == 0)
return 0;
5214 if (gd->
nb_cols == 0)
return -1;
5219 if (!tmp)
return -1;
5227 unsigned char* ts = NULL;
5228 Malloc(ts,
unsigned char, nr);
5238 ALLEGRO_COLOR* tc = NULL;
5239 unsigned char* th = NULL;
5240 Malloc(tc, ALLEGRO_COLOR, nr);
5241 Malloc(th,
unsigned char, nr);
5260 for (c = 0; c < gd->
nb_cols; c++) {
5261 const char* v = (values && values[c]) ? values[c] :
"";
5296 if (
row < 0 || (
size_t)
row >= gd->
nb_rows || col < 0 || (
size_t)col >= gd->
nb_cols)
return NULL;
5351 for (r = 0; r < gd->
nb_rows; r++) {
5353 if (out && n < max) out[n] = (int)r;
5438 if (offset < 0) offset = 0;
5452 for (c = 0; c < gd->
nb_cols; c++) {
5470 if (px < 0.0f) px = 0.0f;
5488 if (!gd || col < 0 || (
size_t)col >= gd->
nb_cols)
return "";
5494 if (!gd || col < 0 || (
size_t)col >= gd->
nb_cols)
return;
5500 if (!gd || col < 0 || (
size_t)col >= gd->
nb_cols)
return 0;
5506 if (!gd || col < 0 || (
size_t)col >= gd->
nb_cols)
return;
5507 gd->
cols[col].
width = width < 16.0f ? 16.0f : width;
5512 if (!gd || col < 0 || (
size_t)col >= gd->
nb_cols)
return 0.0f;
5518 if (!gd || display_pos < 0 || (
size_t)display_pos >= gd->
nb_cols)
return -1;
5524 size_t f, t, moved, i;
5526 if (from < 0 || (
size_t)from >= gd->
nb_cols || to < 0 || (
size_t)to >= gd->
nb_cols || from == to)
return;
5573 int d = (dir < 0) ? -1 : 1;
5575 Malloc(nc,
char*, n* cols);
5581 for (i = 0; i < n; i++) idx[i] = i;
5583 for (i = 1; i < n; i++) {
5584 size_t key = idx[i];
5585 const char* ka = gd->
cells[
key * cols + (size_t)col];
5587 while (j > 0 && d *
_cell_cmp(gd->
cells[idx[j - 1] * cols + (
size_t)col], ka) > 0) {
5588 idx[j] = idx[j - 1];
5593 for (i = 0; i < n; i++)
5594 for (j = 0; j < cols; j++)
5595 nc[i * cols + j] = gd->
cells[idx[i] * cols + j];
5602 ALLEGRO_COLOR* tc = NULL;
5603 unsigned char* th = NULL;
5604 Malloc(tc, ALLEGRO_COLOR, n);
5605 Malloc(th,
unsigned char, n);
5607 for (i = 0; i < n; i++) {
5772 float w = wgt->
w - pad * 2.0f;
5785 float view_h = wgt->
h - pad * 2.0f;
5786 float w_no_bar, most;
5827 md->
text = strdup(
"");
5869 return md ? md->
text : NULL;
5897 md->
scroll_y = y < 0.0f ? 0.0f : y;
5936 item->
text[0] =
'\0';
5985 if (index >= -1 && (index == -1 || (
size_t)index < rd->nb_items)) {
6018 item->
text[0] =
'\0';
6046 if (index >= 0 && (
size_t)index < cd->nb_items) {
6075 if (index == removed)
return -1;
6076 if (index > removed)
return index - 1;
6091 if (index < 0 || (
size_t)index >= cd->
nb_items)
return -1;
6092 if ((
size_t)index < cd->nb_items - 1) {
6093 memmove(&cd->
items[index], &cd->
items[index + 1],
6120 if (index >= -1 && (index == -1 || (
size_t)index < cd->nb_items)) {
6216 if (needed_w) *needed_w = 0.0f;
6217 if (needed_h) *needed_h = 0.0f;
6223 if (!
font || !lb->
text[0])
return 1;
6226 float need_w, need_h;
6231 }
else if (strchr(lb->
text,
'\n')) {
6235 float widest = 0.0f;
6236 for (i = 0; i < lines; i++) {
6239 if (lw > widest) widest = lw;
6241 need_w = widest + pad * 2.0f;
6242 need_h = (float)lines * (
float)al_get_font_line_height(
font);
6245 need_h = (float)al_get_font_line_height(
font);
6247 if (needed_w) *needed_w = need_w;
6248 if (needed_h) *needed_h = need_h;
6251 return (need_w <= wgt->w + 0.5f && need_h <= wgt->
h + 0.5f) ? 1 : 0;
6278 size_t new_cap = (*cap == 0) ? 8 : (*cap) * 2;
6279 if (new_cap < *cap)
return 0;
6283 if (*entries && *nb > 0) {
6297int n_gui_add_dropmenu(
N_GUI_CTX* ctx,
int window_id,
const char* label,
float x,
float y,
float w,
float h,
void (*on_open)(
int,
void*),
void* on_open_user_data) {
6308 dd->
label[0] =
'\0';
6365 snprintf(dd->
label,
sizeof(dd->
label),
"%s", label);
6367 dd->
label[0] =
'\0';
6381 memset(e, 0,
sizeof(*e));
6405 n_log(
LOG_ERR,
"Invalid NULL widget for ctx %p widget_id %d", ctx, widget_id);
6411 n_log(
LOG_ERR,
"Widget has NULL data for ctx %p widget_id %d", ctx, widget_id);
6429 for (
size_t i = 0; i < dd->
nb_entries; i++) {
6444 if (dm_max < 0) dm_max = 0;
6467 if (index < 0 || (
size_t)index >= dd->
nb_entries)
return;
6502 n_log(
LOG_ERR,
"n_gui_dropmenu_set_open: %d is not a dropmenu", widget_id);
6575 if (sb < 10.0f) sb = 10.0f;
6576 if (!
font)
return pw;
6579 if (tw > pw) pw = tw;
6594 n_log(
LOG_WARNING,
"n_gui_window_set_bitmaps: window %d not found", window_id);
6606void n_gui_slider_set_bitmaps(
N_GUI_CTX* ctx,
int widget_id, ALLEGRO_BITMAP* track, ALLEGRO_BITMAP* fill, ALLEGRO_BITMAP* handle, ALLEGRO_BITMAP* handle_hover, ALLEGRO_BITMAP* handle_active) {
6609 n_log(
LOG_WARNING,
"n_gui_slider_set_bitmaps: widget %d is not a slider", widget_id);
6627 n_log(
LOG_WARNING,
"n_gui_scrollbar_set_bitmaps: widget %d is not a scrollbar", widget_id);
6644 n_log(
LOG_WARNING,
"n_gui_checkbox_set_bitmaps: widget %d is not a checkbox", widget_id);
6660 n_log(
LOG_WARNING,
"n_gui_textarea_set_bitmap: widget %d is not a textarea", widget_id);
6674 n_log(
LOG_WARNING,
"n_gui_textarea_set_mask_char: widget %d is not a textarea", widget_id);
6687 n_log(
LOG_WARNING,
"n_gui_textarea_set_placeholder: widget %d is not a textarea", widget_id);
6703 n_log(
LOG_WARNING,
"n_gui_listbox_set_bitmaps: widget %d is not a listbox", widget_id);
6719 n_log(
LOG_WARNING,
"n_gui_radiolist_set_bitmaps: widget %d is not a radiolist", widget_id);
6735 n_log(
LOG_WARNING,
"n_gui_combobox_set_bitmaps: widget %d is not a combobox", widget_id);
6751 n_log(
LOG_WARNING,
"n_gui_dropmenu_set_bitmaps: widget %d is not a dropmenu", widget_id);
6766 n_log(
LOG_WARNING,
"n_gui_label_set_bitmap: widget %d is not a label", widget_id);
6777 float bw = (float)al_get_bitmap_width(bmp);
6778 float bh = (float)al_get_bitmap_height(bmp);
6780 al_draw_scaled_bitmap(bmp, 0, 0, bw, bh, dx, dy, dw, dh, 0);
6782 al_draw_bitmap(bmp, dx + (dw - bw) / 2.0f, dy + (dh - bh) / 2.0f, 0);
6787 float s = (sx < sy) ? sx : sy;
6790 al_draw_scaled_bitmap(bmp, 0, 0, bw, bh, dx + (dw - rw) / 2.0f, dy + (dh - rh) / 2.0f, rw, rh, 0);
6797static ALLEGRO_BITMAP*
_select_state_bitmap(
int state, ALLEGRO_BITMAP* normal_bmp, ALLEGRO_BITMAP* hover_bmp, ALLEGRO_BITMAP* active_bmp) {
6800 if (normal_bmp)
return normal_bmp;
6813 const ALLEGRO_TRANSFORM* tf = al_get_current_transform();
6817 cx[1] = (float)(wx + ww);
6820 cy[2] = (float)(wy + wh);
6821 cx[3] = (float)(wx + ww);
6822 cy[3] = (float)(wy + wh);
6823 for (
int i = 0; i < 4; i++)
6824 al_transform_coordinates(tf, &cx[i], &cy[i]);
6826 float min_x = cx[0], max_x = cx[0];
6827 float min_y = cy[0], max_y = cy[0];
6828 for (
int i = 1; i < 4; i++) {
6829 if (cx[i] < min_x) min_x = cx[i];
6830 if (cx[i] > max_x) max_x = cx[i];
6831 if (cy[i] < min_y) min_y = cy[i];
6832 if (cy[i] > max_y) max_y = cy[i];
6835 int new_x = (int)min_x;
6836 int new_y = (int)min_y;
6837 int new_w = (int)(max_x - min_x);
6838 int new_h = (int)(max_y - min_y);
6841 int pcx, pcy, pcw, pch;
6842 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
6844 int right = new_x + new_w;
6845 int bottom = new_y + new_h;
6846 int prev_right = pcx + pcw;
6847 int prev_bottom = pcy + pch;
6849 if (new_x < pcx) new_x = pcx;
6850 if (new_y < pcy) new_y = pcy;
6852 if (bottom > prev_bottom) bottom = prev_bottom;
6854 new_w =
right - new_x;
6855 new_h = bottom - new_y;
6856 if (new_w < 0) new_w = 0;
6857 if (new_h < 0) new_h = 0;
6859 al_set_clipping_rectangle(new_x, new_y, new_w, new_h);
6865 if ((lead & 0xE0) == 0xC0)
return 2;
6866 if ((lead & 0xF0) == 0xE0)
return 3;
6867 if ((lead & 0xF8) == 0xF0)
return 4;
6875 size_t len = strlen(
text);
6882 if (i >= len)
break;
6883 snprintf(out, out_len,
"...%s",
text + i);
6886 snprintf(out, out_len,
"...");
6891 if (!out || out_len < 1)
return -1;
6893 if (!
font || !
text || out_len < 5)
return -1;
6894 snprintf(out, out_len,
"%s",
text);
6901 const char* at =
text;
6903 const char* next = at;
6904 while (*next && *next !=
'/' && *next !=
'\\') next++;
6905 while (*next ==
'/' || *next ==
'\\') next++;
6908 snprintf(out, out_len,
".../%s", at);
6909 if (
_text_w(
font, out) <= max_w && strlen(at) + 4 < out_len)
return 1;
6923 size_t len = strlen(
text), i = 0, fit = 0;
6927 if (i + step > len || i + step + 4 > out_len)
break;
6928 memcpy(out,
text, i + step);
6929 out[i + step] =
'\0';
6934 memcpy(out,
text, fit);
6935 snprintf(out + fit, out_len - fit,
"...");
6946 al_draw_text(
font, color, x, y, 0,
text);
6952 float avail = max_w - ellipsis_w;
6953 if (avail < 0) avail = 0;
6954 size_t len = strlen(
text);
6960 unsigned char lead = (
unsigned char)
text[i];
6961 if ((lead & 0xE0) == 0xC0)
6963 else if ((lead & 0xF0) == 0xE0)
6965 else if ((lead & 0xF8) == 0xF0)
6967 if (i + step > len || i + step > (
size_t)(
N_GUI_TEXT_MAX - 5))
break;
6968 memcpy(buf + i,
text + i, step);
6969 buf[i + step] =
'\0';
6971 if (cw > avail)
break;
6978 buf[fit + 3] =
'\0';
6979 al_draw_text(
font, color, x, y, 0, buf);
6983#define N_GUI_WRAP_MAX_WORDS 256
6993static int _split_words(
const char*
text, ALLEGRO_FONT*
font,
int* starts,
int* lens,
float* widths,
int max_words,
int* nl_before) {
6994 size_t text_len =
text ? strlen(
text) : 0;
6998 if (!
font)
return 0;
6999 while (i < text_len && n < max_words) {
7002 while (i < text_len && (
text[i] ==
' ' ||
text[i] ==
'\t' ||
text[i] ==
'\n' ||
text[i] ==
'\r')) {
7003 if (
text[i] ==
'\n') pending_nl++;
7006 if (i >= text_len)
break;
7008 while (i < text_len &&
text[i] !=
' ' &&
text[i] !=
'\t' &&
text[i] !=
'\n' &&
text[i] !=
'\r') i++;
7009 if (nl_before) nl_before[n] = pending_nl;
7013 int wlen = (int)(i - ws);
7015 memcpy(tmp, &
text[ws], (
size_t)mlen);
7017 starts[n] = (int)ws;
7024 if (nl_before) nl_before[n] = pending_nl;
7030#define N_GUI_WRAP_MAX_ITEMS (3 * N_GUI_WRAP_MAX_WORDS + 2)
7053 while (k < acc->count && acc->
item_word[k] < 0) k++;
7054 if (acc->
n < acc->
cap) {
7076static int _wrap_words(
const float* word_widths,
const int* nl_before,
int nwords,
float space_w,
float max_w,
int* line_first,
unsigned char* para_end,
int max_lines) {
7080 int n = 0, i, k, lines;
7082 if (nwords <= 0 || max_lines <= 0)
return 0;
7084 for (i = 0; i <= nwords; i++) {
7085 int breaks = nl_before ? nl_before[i] : 0;
7090 if (breaks > room) breaks = room > 0 ? room : 0;
7091 if (breaks > 0 || (i > 0 && i == nwords)) {
7092 for (k = 0; k < breaks; k++) {
7093 items[n].
width = 0.0;
7099 items[n].
width = (double)space_w;
7104 if (i == nwords)
break;
7105 items[n].
width = (double)word_widths[i];
7106 items[n].
flags = 0u;
7110 acc.
first = line_first;
7112 acc.
cap = max_lines;
7116 acc.
count = (size_t)n;
7119 if (lines > max_lines) lines = max_lines;
7120 line_first[lines] = nwords;
7127 if (len < 0) len = 0;
7149 if (nwords == 0)
return;
7151 if (nwords == 1 && nl_before[0] == 0 && nl_before[1] == 0) {
7156 float fh = (float)al_get_font_line_height(
font);
7162 for (li = 0; li < nlines; li++) {
7163 int line_start = line_first[li];
7164 int line_end = line_first[li + 1];
7166 if (cy + fh > y + max_h + 0.5f)
break;
7168 int words_on_line = line_end - line_start;
7170 if (words_on_line == 1) {
7173 _word_text(
text, word_starts[line_start], word_lens[line_start], w1);
7174 if (word_widths[line_start] > max_w) {
7177 al_draw_text(
font, color, x, cy, 0, w1);
7182 int is_last_line = para_end[li];
7183 float gap = space_w;
7185 if (!is_last_line) {
7186 float total_word_w = 0;
7187 for (
int i = line_start; i < line_end; i++) total_word_w += word_widths[i];
7188 float total_space = max_w - total_word_w;
7189 if (total_space < 0) total_space = 0;
7190 gap = total_space / (float)(words_on_line - 1);
7192 for (
int i = line_start; i < line_end; i++) {
7195 al_draw_text(
font, color, cx, cy, 0, wi);
7196 cx += word_widths[i] + gap;
7206 if (c < 0x80)
return 1;
7207 if ((c & 0xE0) == 0xC0)
return 2;
7208 if ((c & 0xF0) == 0xE0)
return 3;
7209 if ((c & 0xF8) == 0xF0)
return 4;
7244 if (i >= len)
return st;
7245 if (
text[i] ==
'\n') {
7250 if (i + (
size_t)st.
clen > len) st.
clen = (int)(len - i);
7260 if (cx + st.
cw > wrap_limit && cx > line_x0) st.
wrapped = 1;
7268 float fh = (float)al_get_font_line_height(
font);
7271 for (
size_t i = 0; i < td->
text_len;) {
7284 i += (size_t)st.
clen;
7302 float view_h = w->
h - pad * 2;
7304 float max_sy = ch - view_h;
7305 if (max_sy < 0) max_sy = 0;
7342 float fh = (float)al_get_font_line_height(
font);
7343 float view_h = w->
h - pad * 2;
7349 float text_area_w = w->
w - sb_size;
7355 size_t target = (byte_offset <= td->
text_len) ? byte_offset : td->
text_len;
7356 for (
size_t i = 0; i < target && i < td->
text_len;) {
7369 i += (size_t)st.
clen;
7374 float max_sy = content_h - view_h;
7375 if (max_sy < 0) max_sy = 0;
7376 float ideal = cy - view_h / 2 + fh / 2;
7377 if (ideal < 0) ideal = 0;
7378 if (ideal > max_sy) ideal = max_sy;
7422 size_t text_len = strlen(
text);
7431 if (nwords == 0)
return 0;
7433 float fh = (float)al_get_font_line_height(
font);
7435 float cy = text_y - scroll_y;
7436 float click_y_content = click_my;
7441 for (li = 0; li < nlines; li++) {
7442 if (click_y_content >= cy && click_y_content < cy + fh) {
7444 int line_start = line_first[li];
7445 int line_end = line_first[li + 1];
7446 int is_last_line = para_end[li];
7447 int words_on_line = line_end - line_start;
7448 float click_x_rel = click_mx - text_x;
7451 if (words_on_line <= 0)
return (line_start < nwords) ? word_starts[line_start] : (int)text_len;
7452 if (click_x_rel < 0)
return word_starts[line_start];
7455 float gap = space_w;
7456 if (!is_last_line && words_on_line > 1) {
7457 float total_word_w = 0;
7458 for (
int j = line_start; j < line_end; j++) total_word_w += word_widths[j];
7459 float total_space = max_w - total_word_w;
7460 if (total_space < 0) total_space = 0;
7461 gap = total_space / (float)(words_on_line - 1);
7466 for (
int j = line_start; j < line_end; j++) {
7468 if (click_x_rel >= cx && click_x_rel < cx + word_widths[j]) {
7472 float best_dist = click_x_rel - cx;
7473 if (best_dist < 0) best_dist = -best_dist;
7474 for (
int k = 0; k < word_lens[j];) {
7476 if (k + clen > word_lens[j]) clen = word_lens[j] - k;
7478 memcpy(ch, &
text[word_starts[j] + k], (
size_t)clen);
7482 float dist = (click_x_rel - cx) - wx;
7483 if (dist < 0) dist = -dist;
7484 if (dist < best_dist) {
7486 best_off = k + clen;
7490 return word_starts[j] + best_off;
7493 if (j < line_end - 1 && click_x_rel >= cx + word_widths[j] && click_x_rel < cx + word_widths[j] + gap) {
7495 float mid = cx + word_widths[j] + gap / 2.0f;
7496 if (click_x_rel < mid)
7497 return word_starts[j] + word_lens[j];
7499 return word_starts[j + 1];
7501 cx += word_widths[j] + gap;
7504 return word_starts[line_end - 1] + word_lens[line_end - 1];
7510 return (
int)text_len;
7517 if (!
font || !
text || !
text[0] || sel_start == sel_end)
return;
7518 int slo = sel_start < sel_end ? sel_start : sel_end;
7519 int shi = sel_start < sel_end ? sel_end : sel_start;
7520 size_t text_len = strlen(
text);
7521 if ((
size_t)slo > text_len) slo = (int)text_len;
7522 if ((
size_t)shi > text_len) shi = (int)text_len;
7533 if (nwords == 0)
return;
7535 float fh = (float)al_get_font_line_height(
font);
7541 for (li = 0; li < nlines; li++) {
7542 int line_start = line_first[li];
7543 int line_end = line_first[li + 1];
7544 if (cy + fh > y + max_h + 0.5f)
break;
7545 int words_on_line = line_end - line_start;
7546 int is_last_line = para_end[li];
7549 float gap = space_w;
7550 if (!is_last_line && words_on_line > 1) {
7551 float total_word_w = 0;
7552 for (
int j = line_start; j < line_end; j++) total_word_w += word_widths[j];
7553 float total_space = max_w - total_word_w;
7554 if (total_space < 0) total_space = 0;
7555 gap = total_space / (float)(words_on_line - 1);
7560 for (
int j = line_start; j < line_end; j++) {
7561 int ws2 = word_starts[j];
7562 int we = ws2 + word_lens[j];
7564 if (slo < we && shi > ws2) {
7566 float sx1 = 0, sx2 = word_widths[j];
7569 int off = slo - ws2;
7570 memcpy(tmp2, &
text[ws2], (
size_t)off);
7576 int off = shi - ws2;
7577 memcpy(tmp2, &
text[ws2], (
size_t)off);
7581 al_draw_filled_rectangle(cx + sx1, cy, cx + sx2, cy + fh, sel_color);
7584 if (j < line_end - 1) {
7586 int gap_end = word_starts[j + 1];
7587 if (slo < gap_end && shi > gap_start) {
7588 al_draw_filled_rectangle(cx + word_widths[j], cy,
7589 cx + word_widths[j] + gap, cy + fh, sel_color);
7592 cx += word_widths[j] + gap;
7607 return (w < 1.0f) ? 1.0f : w;
7615 float fh = (float)al_get_font_line_height(
font);
7625 if (nwords == 0)
return 0;
7626 if (nwords == 1 && nl_before[0] == 0 && nl_before[1] == 0)
return fh;
7651 float ratio = (content > 0.0f) ?
visible / content : 1.0f;
7652 float max_off = content -
visible;
7654 if (ratio > 1.0f) ratio = 1.0f;
7655 if (max_off < 0.0f) max_off = 0.0f;
7656 t.
len = ratio * track_len;
7657 if (t.
len < min_len) t.
len = min_len;
7658 pos_ratio = (max_off > 0.0f) ? offset / max_off : 0.0f;
7659 t.
off = pos_ratio * (track_len - t.
len);
7668 const ALLEGRO_TRANSFORM* tf = al_get_current_transform();
7670 float sx = hypotf(tf->m[0][0], tf->m[0][1]);
7671 float sy = hypotf(tf->m[1][0], tf->m[1][1]);
7673 float scale = (sx > sy) ? sx : sy;
7674 if (scale < 0.01f) scale = 0.01f;
7676 float min_t = 1.0f / scale;
7677 return (requested > min_t) ? requested : min_t;
7740 if (!track || track->
w <= 0.0f || track->
h <= 0.0f)
return 0;
7781 k.
outline = al_map_rgba(0, 0, 0, 0);
7827 if (vertical && bar_h > 2.0f * in) {
7830 }
else if (!vertical && bar_w > 2.0f * in) {
7834 r = (vertical ? bar_w : bar_h) / 2.0f;
7835 al_draw_filled_rounded_rectangle(bar_x, bar_y, bar_x + bar_w, bar_y + bar_h, r, r, skin->
track);
7838 al_draw_filled_rectangle(bar_x, bar_y, bar_x + bar_w, bar_y + bar_h, skin->
track);
7880 if (w < 0.0f ||
h < 0.0f)
return;
7882 al_draw_filled_rounded_rectangle(x, y, x + w, y +
h, r, r, fill);
7884 al_draw_rounded_rectangle(x, y, x + w, y +
h, r, r, skin->
outline,
7887 al_draw_rounded_rectangle(x, y, x + w, y +
h, r, r, edge,
7890 al_draw_filled_rectangle(x, y, x + w, y +
h, fill);
7892 al_draw_rectangle(x, y, x + w, y +
h, skin->
outline,
7895 al_draw_rectangle(x, y, x + w, y +
h, edge,
7929static void _draw_scrollbar_body(
float bar_x,
float bar_y,
float bar_w,
float bar_h,
float thumb_off,
float thumb_len,
int vertical,
int state,
N_GUI_SB_TRACK* track,
const _N_GUI_SB_SKIN* skin,
const N_GUI_THEME* theme) {
7951 state, skin, theme);
7954 state, skin, theme);
7964 float sb_x = area_x + area_w - sb_size;
7968 _draw_scrollbar_body(sb_x, area_y, sb_size, view_h, th.
off, th.
len, 1,
N_GUI_STATE_IDLE, track, &skin, theme);
7979 float ht = thickness * 0.5f;
7981 al_draw_filled_rounded_rectangle(x + ht, y + ht, x + w - ht, y +
h - ht, t->
corner_rx, t->
corner_ry, bg);
7982 al_draw_rounded_rectangle(x + ht, y + ht, x + w - ht, y +
h - ht, t->
corner_rx, t->
corner_ry, bd, thickness);
7984 al_draw_filled_rectangle(x, y, x + w, y +
h, bg);
7985 al_draw_rectangle(x + ht, y + ht, x + w - ht, y +
h - ht, bd, thickness);
8010static void _draw_glyph(
int glyph,
float cx,
float cy,
float s, ALLEGRO_COLOR fg, ALLEGRO_COLOR bg,
float thick) {
8012 float hh = s * 0.8f;
8016 float stroke = s * 0.42f;
8017 if (stroke < thick) stroke = thick;
8021 al_draw_filled_triangle(cx, cy - hh, cx - hw, cy + hh, cx + hw, cy + hh, fg);
8024 al_draw_filled_triangle(cx, cy + hh, cx - hw, cy - hh, cx + hw, cy - hh, fg);
8027 al_draw_filled_triangle(cx - hh, cy, cx + hh, cy - hw, cx + hh, cy + hw, fg);
8030 al_draw_filled_triangle(cx + hh, cy, cx - hh, cy - hw, cx - hh, cy + hw, fg);
8033 al_draw_line(cx - s, cy, cx + s, cy, fg, thick);
8034 al_draw_line(cx, cy - s, cx, cy + s, fg, thick);
8037 al_draw_line(cx - s, cy, cx + s, cy, fg, thick);
8040 al_draw_line(cx - s, cy - s, cx + s, cy + s, fg, thick);
8041 al_draw_line(cx + s, cy - s, cx - s, cy + s, fg, thick);
8046 float off = s * 0.45f;
8047 al_draw_rectangle(cx - s, cy - s, cx + s - off * 2.0f, cy + s - off * 2.0f, fg, thick);
8048 al_draw_filled_rectangle(cx - s + off * 2.0f, cy - s + off * 2.0f, cx + s, cy + s, bg);
8049 al_draw_rectangle(cx - s + off * 2.0f, cy - s + off * 2.0f, cx + s, cy + s, fg, thick);
8059 float ax = ox + wgt->
x;
8060 float ay = oy + wgt->
y;
8061 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
8064 int draw_state = wgt->
state;
8076 ALLEGRO_BITMAP* bmp = bd->
bitmap;
8081 al_draw_scaled_bitmap(bmp, 0, 0,
8082 (
float)al_get_bitmap_width(bmp), (
float)al_get_bitmap_height(bmp),
8083 ax, ay, wgt->
w, wgt->
h, 0);
8092 float smaller = (wgt->
w < wgt->
h) ? wgt->
w : wgt->
h;
8093 float s = smaller * 0.25f;
8094 if (s < 2.0f) s = 2.0f;
8101 int bbx = 0, bby = 0, bbw = 0, bbh = 0;
8103 float tw = (float)bbw;
8104 float th = (float)bbh;
8106 float max_text_w = wgt->
w - pad * 2.0f;
8107 if (tw > max_text_w) {
8110 al_draw_text(
font, tc, ax + (wgt->
w - tw) / 2.0f - (
float)bbx, ay + (wgt->
h - th) / 2.0f - (
float)bby, 0, bd->
label);
8122 if (!sd || !out || !out_len)
return;
8125#pragma GCC diagnostic push
8126#pragma GCC diagnostic ignored "-Wformat-nonliteral"
8128#pragma GCC diagnostic pop
8130 snprintf(out, out_len,
"%.0f%%", value);
8132 snprintf(out, out_len,
"%.1f", value);
8175 float len = along - 2.0f * r;
8178 *
start = along / 2.0f;
8188 float ax = ox + wgt->
x;
8189 float ay = oy + wgt->
y;
8190 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
8193 double ratio = (range > 0) ? (sd->
value - sd->
min_val) / range : 0;
8198 float track_x = ax + (wgt->
w - track_w) / 2.0f;
8202 track_x, ay, track_w, wgt->
h, 0);
8213 float v_start = 0.0f, v_len = 0.0f;
8217 fill_h = v_start + (float)(ratio * (
double)v_len);
8221 track_x, ay + wgt->
h - fill_h, track_w, fill_h, 0);
8227 float hy = ay + wgt->
h - fill_h;
8231 float hd = handle_r * 2.0f;
8232 al_draw_scaled_bitmap(hbmp, 0, 0,
8233 (
float)al_get_bitmap_width(hbmp), (
float)al_get_bitmap_height(hbmp),
8234 ax + wgt->
w / 2.0f - handle_r, hy - handle_r, hd, hd, 0);
8238 al_draw_filled_circle(ax + wgt->
w / 2.0f, hy, handle_r, hc);
8246 int vbbx = 0, vbby = 0, vbbw = 0, vbbh = 0;
8257 float track_y = ay + (wgt->
h - track_h) / 2.0f;
8261 ax, track_y, wgt->
w, track_h, 0);
8268 float h_start = 0.0f, h_len = 0.0f;
8272 fill_w = h_start + (float)(ratio * (
double)h_len);
8276 ax, track_y, fill_w, track_h, 0);
8282 float hx = ax + fill_w;
8286 float hd = handle_r * 2.0f;
8287 al_draw_scaled_bitmap(hbmp, 0, 0,
8288 (
float)al_get_bitmap_width(hbmp), (
float)al_get_bitmap_height(hbmp),
8289 hx - handle_r, ay + wgt->
h / 2.0f - handle_r, hd, hd, 0);
8293 al_draw_filled_circle(hx, ay + wgt->
h / 2.0f, handle_r, hc);
8301 int sbbx = 0, sbby = 0, sbbw = 0, sbbh = 0;
8303 float th = (float)sbbh;
8313 float fh = (float)al_get_font_line_height(
font);
8316 float click_x = mx - (ax + pad) + td->
scroll_x;
8317 if (click_x < 0) click_x = 0;
8330 float best_dist = click_x;
8332 for (
size_t ci = 0; ci < td->
text_len;) {
8335 size_t pos = ci + (size_t)clen;
8339 float dist = click_x - tw;
8340 if (dist < 0) dist = -dist;
8341 if (dist < best_dist) {
8353 float view_h = widget_h - pad * 2;
8355 float sb_size = (content_h > view_h) ? scrollbar_size : 0.0f;
8356 float text_area_w = widget_w - sb_size;
8357 float avail_w = text_area_w - pad * 2;
8358 float click_x_rel = mx - (ax + pad);
8359 float click_y_content = my - (ay + pad) + (
float)td->
scroll_y;
8360 if (click_x_rel < 0) click_x_rel = 0;
8361 if (click_y_content < 0) click_y_content = 0;
8362 int target_line = (int)(click_y_content / fh);
8366 size_t best_pos = 0;
8367 float best_dist = click_x_rel;
8368 int found_line = (target_line == 0) ? 1 : 0;
8370 for (
size_t ci = 0; ci < td->
text_len;) {
8371 if (cur_line > target_line)
break;
8372 if (td->
text[ci] ==
'\n') {
8373 if (cur_line == target_line)
break;
8376 if (cur_line == target_line) {
8379 best_dist = click_x_rel;
8387 memcpy(ch2, &td->
text[ci], (
size_t)clen);
8390 if (cur_cx + cw > avail_w) {
8391 if (cur_line == target_line)
break;
8394 if (cur_line == target_line) {
8397 best_dist = click_x_rel;
8400 if (cur_line == target_line) {
8401 float dist = click_x_rel - (cur_cx + cw);
8402 if (dist < 0) dist = -dist;
8403 if (dist < best_dist) {
8405 best_pos = ci + (size_t)clen;
8411 if (!found_line) best_pos = td->
text_len;
8434 float tr, tg, tb, br, bg, bb;
8440 dim = al_map_rgb_f((tr + br) * 0.5f, (tg + bg) * 0.5f, (tb + bb) * 0.5f);
8447 float ax = ox + wgt->
x;
8448 float ay = oy + wgt->
y;
8449 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
8456 al_draw_scaled_bitmap(td->
bg_bitmap, 0, 0,
8457 (
float)al_get_bitmap_width(td->
bg_bitmap), (
float)al_get_bitmap_height(td->
bg_bitmap),
8458 ax, ay, wgt->
w, wgt->
h, 0);
8468 al_draw_filled_rectangle(ax, ay, ax + wgt->
w, ay + wgt->
h, bg);
8483 float fh = (float)al_get_font_line_height(
font);
8487 int cursor_visible = 0;
8489 double now = al_get_time();
8492 if (period <= 0.0f) period = 1.0f;
8493 double phase = elapsed - (double)(
int)(elapsed / (double)period) * (
double)period;
8494 cursor_visible = (phase < (double)period * 0.5) ? 1 : 0;
8499 float view_h = wgt->
h - pad * 2;
8503 int need_scrollbar = (content_h > view_h) ? 1 : 0;
8505 float text_area_w = wgt->
w - sb_size;
8506 if (need_scrollbar) {
8517 float cw2 = cstep.
cw;
8518 int clen = cstep.
clen;
8533 if (cur_cy < (
float)td->
scroll_y) {
8536 if (cur_cy + fh > (
float)td->
scroll_y + view_h) {
8537 td->
scroll_y = (int)(cur_cy + fh - view_h);
8542 if (need_scrollbar) {
8543 float max_sy = content_h - view_h;
8544 if (max_sy < 0) max_sy = 0;
8552 int pcx, pcy, pcw, pch;
8553 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
8556 size_t sel_lo = 0, sel_hi = 0;
8562 float cx = ax + pad;
8563 float cy = ay + pad - (float)td->
scroll_y;
8565 float cursor_cx = cx;
8566 float cursor_cy = cy;
8578 float run_x = cx, run_y = cy;
8580 for (
size_t i = 0; i < td->
text_len;) {
8585 if (td->
text[i] ==
'\n') {
8588 run[run_len] =
'\0';
8594 if (has_sel && i >= sel_lo && i < sel_hi && cy + fh > ay && cy < ay + wgt->
h) {
8596 al_draw_filled_rectangle(cx, cy, cx + space_w, cy + fh, sel_bg);
8604 int clen = step.
clen;
8610 run[run_len] =
'\0';
8622 int vis = (cy + fh > ay && cy < ay + wgt->
h);
8625 if (has_sel && i >= sel_lo && i < sel_hi) {
8626 al_draw_filled_rectangle(cx, cy, cx + cw, cy + fh, sel_bg);
8635 if (run_len + clen >= (
int)
sizeof(
run) - 1) {
8636 run[run_len] =
'\0';
8642 memcpy(
run + run_len, step.
ch, (
size_t)clen);
8647 for (
int b = 1; b < clen; b++) {
8656 if (run_len > 0 && run_vis) {
8657 run[run_len] =
'\0';
8666 if (cursor_visible) {
8667 al_draw_filled_rectangle(cursor_cx, cursor_cy, cursor_cx + cursor_w, cursor_cy + fh, wgt->
theme.
text_active);
8669 al_set_clipping_rectangle(pcx, pcy, pcw, pch);
8672 if (need_scrollbar) {
8678 float ty = ay + (wgt->
h - fh) / 2.0f;
8679 float inner_w = wgt->
w - pad * 2;
8687 display_text[n] =
'\0';
8697 memcpy(tmp, display_text, cpos);
8707 if (cursor_px - td->
scroll_x < 0) {
8710 if (cursor_px - td->
scroll_x > inner_w - cursor_w) {
8711 td->
scroll_x = cursor_px - inner_w + cursor_w;
8719 int pcx, pcy, pcw, pch;
8720 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
8727 memcpy(stmp, display_text, sl);
8730 memcpy(stmp, display_text, sh);
8733 float sx1 = ax + pad + sel_x1 - td->
scroll_x;
8734 float sx2 = ax + pad + sel_x2 - td->
scroll_x;
8740 if (cursor_visible) {
8741 float cx = ax + pad + cursor_px - td->
scroll_x;
8742 al_draw_filled_rectangle(cx, ty, cx + cursor_w, ty + fh, wgt->
theme.
text_active);
8744 al_set_clipping_rectangle(pcx, pcy, pcw, pch);
8751 float ax = ox + wgt->
x;
8752 float ay = oy + wgt->
y;
8753 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
8756 float box_y = ay + (wgt->
h - box_size) / 2.0f;
8759 ALLEGRO_BITMAP* box_bmp = NULL;
8769 al_draw_scaled_bitmap(box_bmp, 0, 0,
8770 (
float)al_get_bitmap_width(box_bmp), (
float)al_get_bitmap_height(box_bmp),
8771 ax, box_y, box_size, box_size, 0);
8788 al_draw_line(ax + m, box_y + box_size / 2.0f,
8790 al_draw_line(ax + box_size / 2.0f, box_y + box_size - m,
8796 int cbbx = 0, cbby = 0, cbbw = 0, cbbh = 0;
8798 float fh = (float)cbbh;
8821 float ax = ox + wgt->
x;
8822 float ay = oy + wgt->
y;
8826 float track_len = vertical ? wgt->
h : wgt->
w;
8829 float thumb_x, thumb_y, thumb_w, thumb_h;
8830 ALLEGRO_BITMAP* tbmp;
8841 ax, ay, wgt->
w, wgt->
h, 0);
8851 thumb_w = wgt->
w - pad * 2.0f;
8852 thumb_y = ay + th.
off;
8855 thumb_x = ax + th.
off;
8858 thumb_h = wgt->
h - pad * 2.0f;
8863 al_draw_scaled_bitmap(tbmp, 0, 0,
8864 (
float)al_get_bitmap_width(tbmp), (
float)al_get_bitmap_height(tbmp),
8865 thumb_x, thumb_y, thumb_w, thumb_h, 0);
8878 float sb_x = ax + w - sb_w;
8882 _draw_scrollbar_body(sb_x, ay, sb_w,
h, th.
off, th.
len, 1,
N_GUI_STATE_IDLE, track, &skin, theme);
8894 _draw_scrollbar_body(ax, bar_y, track_w, sb_h, th.
off, th.
len, 0,
N_GUI_STATE_IDLE, track, &skin, theme);
8903 float fh =
font ? (float)al_get_font_line_height(
font) : 16.0f;
8906 float data_h = wgt->
h - row_h;
8907 int visible = (int)(data_h / row_h);
8913 for (c = 0; c < gd->
nb_cols; c++) {
8918 if (content_w) *content_w = cw;
8919 if (pane_w) *pane_w = pw;
8920 if (need_hsb) *need_hsb = (cw > pw + 1.0f) ? 1 : 0;
8926 float ax = ox + wgt->
x;
8927 float ay = oy + wgt->
y;
8928 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
8929 float fh =
font ? (float)al_get_font_line_height(
font) : 16.0f;
8931 float row_h = fh + 2.0f;
8933 int nb_rows = (int)((hd->
len + (
size_t)bpr - 1) / (
size_t)bpr);
8934 int visible = (int)((wgt->
h - pad * 2.0f) / row_h);
8935 int need_sb, max_off, i, pcx, pcy, pcw, pch;
8938 al_draw_filled_rectangle(ax, ay, ax + wgt->
w, ay + wgt->
h, wgt->
theme.
bg_normal);
8941 need_sb = (nb_rows >
visible) ? 1 : 0;
8944 if (max_off < 0) max_off = 0;
8948 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
8949 al_set_clipping_rectangle((
int)ax, (
int)ay, (
int)(wgt->
w - sb_w), (
int)wgt->
h);
8950 for (i = 0; i <
visible; i++) {
8952 size_t base = (size_t)
row * (
size_t)bpr;
8955 int n = 0, j, a = 0;
8956 float ty = ay + pad + (float)i * row_h;
8957 if (base >= hd->
len)
break;
8958 n += snprintf(
line + n,
sizeof(
line) - (
size_t)n,
"%08lX ", (
unsigned long)base);
8959 for (j = 0; j < bpr; j++) {
8960 if (base + (
size_t)j < hd->len) {
8961 unsigned char c = hd->
data[base + (size_t)j];
8962 n += snprintf(
line + n,
sizeof(
line) - (
size_t)n,
"%02X ", c);
8963 asc[a++] = (c >= 32 && c < 127) ? (
char)c :
'.';
8965 n += snprintf(
line + n,
sizeof(
line) - (
size_t)n,
" ");
8969 snprintf(
line + n,
sizeof(
line) - (
size_t)n,
" |%s|", asc);
8974 float hx0 = ax + pad + (float)al_get_text_width(
font,
"00000000 ");
8975 float cw = (float)al_get_text_width(
font,
"00 ");
8976 float nw = (float)al_get_text_width(
font,
"0");
8977 float cx = hx0 + (float)(hd->
cursor - base) * cw + (hd->
nibble ? nw : 0.0f);
8978 al_draw_line(cx, ty + (
float)fh, cx + nw, ty + (
float)fh, wgt->
theme.
text_normal, 1.5f);
8981 al_set_clipping_rectangle(pcx, pcy, pcw, pch);
8990 if (!s || !s[0])
return 0;
8993 if (*s ==
'\n') n++;
9029 const int chunk_max = (int)
sizeof(buf) - 1;
9030 if (!r || r->
done || len <= 0)
return;
9032 int take = (len > chunk_max) ? chunk_max : len;
9034 if (len > chunk_max) {
9036 while (take > 0 && ((
unsigned char)s[take] & 0xC0) == 0x80) take--;
9037 if (take == 0) take = chunk_max;
9039 memcpy(buf, s, (
size_t)take);
9043 al_draw_text(r->
font, col, r->
cx, r->
y, 0, buf);
9057 static const char* kw[] = {
"await",
"case",
"delete",
"do",
"else",
"in",
9058 "instanceof",
"new",
"of",
"return",
"throw",
9059 "typeof",
"void",
"yield", NULL};
9060 for (
size_t it = 0; kw[it]; it++) {
9061 if ((
int)strlen(kw[it]) == n && strncmp(s, kw[it], (
size_t)n) == 0)
return 1;
9069 if (c == 0)
return 1;
9070 return strchr(
"(,=:[!&|?;{}<>+-*%~^", c) != NULL;
9075 static const char* kw[] = {
"async",
"await",
"break",
"case",
"catch",
"class",
"const",
9076 "continue",
"debugger",
"default",
"delete",
"do",
"else",
9077 "export",
"extends",
"false",
"finally",
"for",
"function",
9078 "if",
"import",
"in",
"instanceof",
"let",
"new",
"null",
9079 "of",
"return",
"static",
"super",
"switch",
"this",
"throw",
9080 "true",
"try",
"typeof",
"undefined",
"var",
"void",
"while",
9081 "with",
"yield", NULL};
9082 for (
size_t it = 0; kw[it]; it++) {
9083 if ((
int)strlen(kw[it]) == n && strncmp(s, kw[it], (
size_t)n) == 0)
return 1;
9092 return al_map_rgb(64, 160, 72);
9096 return al_map_rgb(200, 72, 72);
9100 return al_map_rgb(96, 148, 200);
9105static void _syntax_draw_line(ALLEGRO_FONT*
font,
N_GUI_THEME* th,
float x,
float y,
const char* s,
int n,
int mode,
int line_idx,
int in_headers,
float x_min,
float x_max) {
9116 if (n >= 2 && s[0] ==
'@' && s[1] ==
'@') {
9118 }
else if (n >= 1 && s[0] ==
'+') {
9120 }
else if (n >= 1 && s[0] ==
'-') {
9128 if (line_idx == 0) {
9132 if (in_headers && n > 0) {
9134 while (c < n && s[c] !=
':') c++;
9135 if (c > 0 && c < n) {
9146 while (i < n && !r.
done) {
9150 while (j < n && s[j] !=
'"') {
9151 if (s[j] ==
'\\' && j + 1 < n) j++;
9157 }
else if ((c >=
'0' && c <=
'9') || (c ==
'-' && i + 1 < n && s[i + 1] >=
'0' && s[i + 1] <=
'9')) {
9159 while (j < n && ((s[j] >=
'0' && s[j] <=
'9') || s[j] ==
'.' || s[j] ==
'e' || s[j] ==
'E' || s[j] ==
'+' || s[j] ==
'-')) j++;
9162 }
else if (c ==
'{' || c ==
'}' || c ==
'[' || c ==
']' || c ==
':' || c ==
',') {
9167 while (j < n && !(s[j] ==
'"' || (s[j] >=
'0' && s[j] <=
'9') || s[j] ==
'{' || s[j] ==
'}' || s[j] ==
'[' || s[j] ==
']' || s[j] ==
':' || s[j] ==
',')) j++;
9176 while (i < n && !r.
done) {
9178 if (i + 4 <= n && memcmp(s + i,
"<!--", 4) == 0) {
9181 while (j + 3 <= n && memcmp(s + j,
"-->", 3) != 0) j++;
9182 j = (j + 3 <= n) ? j + 3 : n;
9189 while (j < n && (s[j] ==
'/' || s[j] ==
'!' || s[j] ==
'?')) j++;
9193 while (j < n && (isalnum((
unsigned char)s[j]) || s[j] ==
':' || s[j] ==
'-' || s[j] ==
'_')) j++;
9197 while (i < n && s[i] !=
'>' && !r.
done) {
9199 if (q ==
'"' || q ==
'\'') {
9201 while (j < n && s[j] != q) j++;
9207 while (j < n && s[j] !=
'>' && s[j] !=
'"' && s[j] !=
'\'') j++;
9218 while (j < n && s[j] !=
'<') j++;
9228 while (i < n && (s[i] ==
' ' || s[i] ==
'\t')) i++;
9230 while (i < n && s[i] ==
'-' && (i + 1 >= n || s[i + 1] ==
' ')) {
9238 if (i < n && s[i] ==
'#') {
9246 for (
int j = i; j < n; j++) {
9248 if (s[j] == q) q = 0;
9251 if (s[j] ==
'"' || s[j] ==
'\'') {
9255 if (s[j] ==
'#')
break;
9256 if (s[j] ==
':' && (j + 1 >= n || s[j + 1] ==
' ')) {
9268 while (i < n && !r.
done) {
9270 if (c ==
'"' || c ==
'\'') {
9272 while (j < n && s[j] != c) j++;
9276 }
else if (c ==
'#') {
9281 while (j < n && s[j] !=
'"' && s[j] !=
'\'' && s[j] !=
'#') j++;
9292 while (i < n && !r.
done) {
9294 if (c ==
'/' && i + 1 < n && s[i + 1] ==
'/') {
9298 if (c ==
'/' && i + 1 < n && s[i + 1] ==
'*') {
9300 while (j + 2 <= n && memcmp(s + j,
"*/", 2) != 0) j++;
9301 j = (j + 2 <= n) ? j + 2 : n;
9310 if (s[j] ==
'\\' && j + 1 < n) {
9315 if (s[j] ==
']') in_class = 0;
9316 }
else if (s[j] ==
'[') {
9318 }
else if (s[j] ==
'/') {
9326 while (j < n && isalpha((
unsigned char)s[j])) j++;
9332 }
else if (c ==
'"' || c ==
'\'' || c ==
'`') {
9334 while (j < n && s[j] != c) {
9335 if (s[j] ==
'\\' && j + 1 < n) j++;
9343 }
else if (c >=
'0' && c <=
'9') {
9345 while (j < n && (isalnum((
unsigned char)s[j]) || s[j] ==
'.')) j++;
9347 last_sig = s[j - 1];
9350 }
else if (isalpha((
unsigned char)c) || c ==
'_' || c ==
'$') {
9352 while (j < n && (isalnum((
unsigned char)s[j]) || s[j] ==
'_' || s[j] ==
'$')) j++;
9354 last_sig = s[j - 1];
9357 }
else if (c ==
'{' || c ==
'}' || c ==
'[' || c ==
']' || c ==
'(' || c ==
')' || c ==
';' || c ==
',' || c ==
':') {
9364 if (c !=
' ' && c !=
'\t') {
9386 const int chunk_max = (int)
sizeof(buf) - 1;
9388 if (!
font || !s || n <= 0)
return 0.0f;
9390 if (limit > 0.0f && w > limit)
break;
9391 int take = (n > chunk_max) ? chunk_max : n;
9392 if (n > chunk_max) {
9394 while (take > 0 && ((
unsigned char)s[take] & 0xC0) == 0x80) take--;
9395 if (take == 0) take = chunk_max;
9397 memcpy(buf, s, (
size_t)take);
9417 if (!yd || !yd->
text || !
font)
return 0;
9418 float fh = (float)al_get_font_line_height(
font);
9419 float row_h = fh + 2.0f;
9420 int row = (int)((my - ay - pad) / row_h);
9423 const char* p = yd->
text;
9425 while (ln < target_line && *p) {
9426 const char* nl = strchr(p,
'\n');
9434 size_t line_start = (size_t)(p - yd->
text);
9435 const char* nl = strchr(p,
'\n');
9436 int dlen = nl ? (int)(nl - p) : (int)strlen(p);
9437 if (dlen > 0 && p[dlen - 1] ==
'\r') dlen--;
9438 float target = mx - (ax + pad) + yd->
h_scroll;
9439 if (target <= 0.0f)
return (
int)line_start;
9445 const int chunk_max = 511;
9447 float base_w = 0.0f, prevw;
9448 while (base + chunk_max < dlen) {
9449 int take = chunk_max;
9451 while (take > 0 && ((
unsigned char)p[base + take] & 0xC0) == 0x80) take--;
9452 if (take == 0) take = chunk_max;
9454 if (base_w + cw >= target)
break;
9459 for (col = 1; base + col <= dlen; col++) {
9462 return (
int)line_start + base + ((target - prevw < ww - target) ? (col - 1) : col);
9466 return (
int)line_start + dlen;
9492 int headers_end = 0x7fffffff;
9493 const char* s = yd->
text;
9497 for (
const char* t = s; *t; t++)
9498 if (*t ==
'\n') nb++;
9503 const char* nl = strchr(q,
'\n');
9504 int len = nl ? (int)(nl - q) : (int)strlen(q);
9505 if (len == 0 || (len == 1 && q[0] ==
'\r')) {
9530 const char* nl = strchr(p,
'\n');
9531 int len = nl ? (int)(nl - p) : (int)strlen(p);
9533 if (len > 0 && p[len - 1] ==
'\r') len--;
9535 if (w > maxw) maxw = w;
9551 float fh =
font ? (float)al_get_font_line_height(
font) : 16.0f;
9552 float row_h = fh + 2.0f;
9555 int vis, need_vsb, hsb;
9561 if (row_h <= 0.0f) row_h = 1.0f;
9562 vis = (int)((wgt->
h - pad * 2.0f) / row_h);
9563 if (vis < 1) vis = 1;
9566 hsb = (cw > pw + 1.0f) ? 1 : 0;
9572 if (vis < 1) vis = 1;
9575 hsb = (cw > pw + 1.0f) ? 1 : 0;
9579 if (content_w) *content_w = cw;
9580 if (pane_w) *pane_w = pw;
9581 if (need_hsb) *need_hsb = hsb;
9587 float max_off = content_w - pane_w;
9588 if (max_off < 0.0f) max_off = 0.0f;
9595 float ax = ox + wgt->
x;
9596 float ay = oy + wgt->
y;
9597 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
9598 float fh =
font ? (float)al_get_font_line_height(
font) : 16.0f;
9600 float row_h = fh + 2.0f;
9602 int need_sb, need_hsb = 0, max_off, headers_end, line_no, drawn, pcx, pcy, pcw, pch;
9603 int has_sel, sel_lo = 0, sel_hi = 0;
9604 float sb_w, sb_h, content_w = 0.0f, pane_w = wgt->
w, text_x;
9612 al_draw_filled_rectangle(ax, ay, ax + wgt->
w, ay + wgt->
h, wgt->
theme.
bg_normal);
9614 need_sb = (nb_lines >
visible) ? 1 : 0;
9618 if (max_off < 0) max_off = 0;
9621 if (!yd->
text)
return;
9631 if ((
size_t)sel_lo > yd->
len) sel_lo = (int)yd->
len;
9632 if ((
size_t)sel_hi > yd->
len) sel_hi = (int)yd->
len;
9635 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
9636 al_set_clipping_rectangle((
int)ax, (
int)ay, (
int)(wgt->
w - sb_w), (
int)(wgt->
h - sb_h));
9640 while (line_no < yd->scroll_offset && p) {
9641 const char* nl = strchr(p,
'\n');
9657 float sel_lim = yd->
h_scroll + pane_w;
9658 for (
int sdrawn = 0; sp && *sp && sdrawn <
visible; sdrawn++) {
9659 const char* nl = strchr(sp,
'\n');
9660 int len = nl ? (int)(nl - sp) : (int)strlen(sp);
9661 float ty = ay + pad + (float)sdrawn * row_h;
9662 if (len > 0 && sp[len - 1] ==
'\r') len--;
9663 int ls = (int)(sp - yd->
text);
9665 int a = sel_lo > ls ? sel_lo : ls;
9666 int b = sel_hi <
le ? sel_hi :
le;
9682 al_hold_bitmap_drawing(
true);
9683 for (drawn = 0; p && *p && drawn <
visible; drawn++, line_no++) {
9684 const char* nl = strchr(p,
'\n');
9685 int len = nl ? (int)(nl - p) : (int)strlen(p);
9686 int in_headers = (line_no <= headers_end);
9687 float ty = ay + pad + (float)drawn * row_h;
9688 if (len > 0 && p[len - 1] ==
'\r') len--;
9689 _syntax_draw_line(
font, &wgt->
theme, text_x, ty, p, len, yd->
mode, line_no, in_headers, ax, ax + pane_w);
9693 al_hold_bitmap_drawing(
false);
9694 al_set_clipping_rectangle(pcx, pcy, pcw, pch);
9711 float ax = ox + wgt->
x;
9712 float ay = oy + wgt->
y;
9714 float view_h, text_w;
9716 int pcx, pcy, pcw, pch;
9735 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
9737 (
int)(wgt->
h - 2.0f));
9739 al_set_clipping_rectangle(pcx, pcy, pcw, pch);
9750 float ax = ox + wgt->
x;
9751 float ay = oy + wgt->
y;
9752 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
9759 al_draw_filled_rounded_rectangle(ax, ay, ax + wgt->
w, ay + wgt->
h, r, r, wgt->
theme.
bg_normal);
9761 fillw = pd->
value * wgt->
w;
9765 al_draw_filled_rounded_rectangle(ax, ay, ax + fillw, ay + wgt->
h, r, r, wgt->
theme.
bg_active);
9768 al_draw_rounded_rectangle(ax, ay, ax + wgt->
w, ay + wgt->
h, r, r, wgt->
theme.
border_normal, 1.0f);
9771 float th = (float)al_get_font_line_height(
font);
9778 float ax = ox + wgt->
x;
9779 float ay = oy + wgt->
y;
9780 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
9781 float fh =
font ? (float)al_get_font_line_height(
font) : 16.0f;
9784 float header_h = row_h;
9785 float data_y = ay + header_h;
9786 float data_h = wgt->
h - header_h;
9787 int visible = (int)(data_h / row_h);
9788 int nb_rows = (int)gd->
nb_rows;
9789 int need_sb, max_off, i, pcx, pcy, pcw, pch, need_hsb = 0;
9790 float sb_w, sb_h = 0.0f, cx, content_w = 0.0f, pane_w = 0.0f, maxh;
9793 al_draw_filled_rectangle(ax, ay, ax + wgt->
w, ay + wgt->
h, wgt->
theme.
bg_normal);
9795 need_sb = (nb_rows >
visible) ? 1 : 0;
9803 visible = (int)(data_h / row_h);
9806 maxh = content_w - pane_w;
9807 if (maxh < 0) maxh = 0;
9811 if (max_off < 0) max_off = 0;
9816 al_draw_filled_rectangle(ax, ay, ax + wgt->
w, ay + header_h, wgt->
theme.
bg_active);
9817 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
9818 al_set_clipping_rectangle((
int)ax, (
int)ay, (
int)(wgt->
w - sb_w), (
int)header_h);
9820 al_hold_bitmap_drawing(
true);
9821 for (c = 0; c < gd->
nb_cols; c++) {
9824 const char* ind =
"";
9827 snprintf(title,
sizeof(title),
"%s%s", gd->
cols[pc].
title, ind);
9831 al_hold_bitmap_drawing(
false);
9832 al_set_clipping_rectangle(pcx, pcy, pcw, pch);
9835 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
9836 al_set_clipping_rectangle((
int)ax, (
int)data_y, (
int)(wgt->
w - sb_w), (
int)data_h);
9839 for (i = 0; i <
visible; i++) {
9841 float ry = data_y + (float)i * row_h;
9843 if (
row >= nb_rows)
break;
9848 al_draw_filled_rectangle(ax, ry, ax + wgt->
w - sb_w, ry + row_h, t);
9854 al_draw_filled_rectangle(ax, ry, ax + wgt->
w - sb_w, ry + row_h, al_map_rgba_f(0.0f, 0.0f, 0.0f, 0.35f));
9855 al_draw_rectangle(ax + 1.0f, ry + 1.0f, ax + wgt->
w - sb_w - 1.0f, ry + row_h - 1.0f, wgt->
theme.
border_active, 2.0f);
9857 al_draw_filled_rectangle(ax, ry, ax + wgt->
w - sb_w, ry + row_h, wgt->
theme.
bg_hover);
9864 al_hold_bitmap_drawing(
true);
9865 for (i = 0; i <
visible; i++) {
9867 float ry = data_y + (float)i * row_h;
9870 if (
row >= nb_rows)
break;
9877 float lum = 0.299f * t.r + 0.587f * t.g + 0.114f * t.b;
9878 tint_text = (lum > 0.55f) ? al_map_rgb(0, 0, 0) : al_map_rgb(255, 255, 255);
9879 if (sel) tint_text = al_map_rgb(255, 255, 255);
9882 for (c = 0; c < gd->
nb_cols; c++) {
9891 al_hold_bitmap_drawing(
false);
9892 al_set_clipping_rectangle(pcx, pcy, pcw, pch);
9900 ALLEGRO_COLOR sep = al_map_rgba_f(0.0f, 0.0f, 0.0f, 0.35f);
9903 for (vc = 0; vc < gd->
nb_cols; vc++) {
9907 if (vx >= ax + wgt->
w - sb_w)
break;
9908 if (vx <= ax)
continue;
9909 al_draw_line(vx, ay, vx, ay + wgt->
h - sb_h, sep, 1.0f);
9912 al_draw_line(ax, ay + header_h, ax + wgt->
w - sb_w, ay + header_h, wgt->
theme.
border_normal, 1.0f);
9915 al_draw_rectangle(ax, ay, ax + wgt->
w, ay + wgt->
h,
9937 float dcx = ax + sd->
ratio * wgt->
w;
9938 return (px >= dcx - band && px <= dcx + band);
9941 float dcy = ay + sd->
ratio * wgt->
h;
9942 return (py >= dcy - band && py <= dcy + band);
9950 float ax = ox + wgt->
x;
9951 float ay = oy + wgt->
y;
9956 float dx = ax + sd->
ratio * wgt->
w - th * 0.5f;
9957 float gx = dx + th * 0.5f;
9958 al_draw_filled_rectangle(dx, ay, dx + th, ay + wgt->
h, wgt->
theme.
bg_normal);
9959 al_draw_line(gx, ay + wgt->
h * 0.5f - th * 1.5f, gx, ay + wgt->
h * 0.5f + th * 1.5f, bar, 2.0f);
9961 float dy = ay + sd->
ratio * wgt->
h - th * 0.5f;
9962 float gy = dy + th * 0.5f;
9963 al_draw_filled_rectangle(ax, dy, ax + wgt->
w, dy + th, wgt->
theme.
bg_normal);
9964 al_draw_line(ax + wgt->
w * 0.5f - th * 1.5f, gy, ax + wgt->
w * 0.5f + th * 1.5f, gy, bar, 2.0f);
9976 float fh =
font ? (float)al_get_font_line_height(
font) : 16.0f;
9978 float cw = 0.0f, pw;
9979 int vis, need_vsb, hsb;
9982 if (ih <= 0.0f) ih = 1.0f;
9983 for (i = 0; i < ld->
nb_items; i++) {
9985 if (tw > cw) cw = tw;
9992 vis = (int)(wgt->
h / ih);
9993 need_vsb = ((int)ld->
nb_items > vis) ? 1 : 0;
9995 hsb = (cw > pw + 1.0f) ? 1 : 0;
9998 if (!need_vsb && (
int)ld->
nb_items > vis) {
10000 hsb = (cw > pw + 1.0f) ? 1 : 0;
10003 if (vis < 0) vis = 0;
10005 if (content_w) *content_w = cw;
10006 if (pane_w) *pane_w = pw;
10007 if (need_hsb) *need_hsb = hsb;
10013 float max_off = content_w - pane_w;
10014 if (max_off < 0.0f) max_off = 0.0f;
10022 float ax = ox + wgt->
x;
10023 float ay = oy + wgt->
y;
10024 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
10028 al_draw_scaled_bitmap(ld->
bg_bitmap, 0, 0,
10029 (
float)al_get_bitmap_width(ld->
bg_bitmap), (
float)al_get_bitmap_height(ld->
bg_bitmap),
10030 ax, ay, wgt->
w, wgt->
h, 0);
10032 al_draw_filled_rectangle(ax, ay, ax + wgt->
w, ay + wgt->
h, wgt->
theme.
bg_normal);
10043 float fh = (float)al_get_font_line_height(
font);
10058 float content_w = 0.0f, pane_w = wgt->
w;
10060 int visible_count = 0;
10064 float rows_h = wgt->
h - hsb_h;
10067 int max_off = (int)ld->
nb_items - visible_count;
10068 if (max_off < 0) max_off = 0;
10072 int need_scrollbar = ((int)ld->
nb_items > visible_count) ? 1 : 0;
10074 float item_area_w = wgt->
w - sb_w;
10080 float iy = ay + (float)i * ih;
10083 int row_hovered = (ld->
hover_row == idx) ? 1 : 0;
10088 }
else if (item->selected) {
10090 }
else if (row_hovered) {
10108 float item_max_w = item_area_w - pad * 2.0f;
10109 int pcx, pcy, pcw, pch;
10111 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
10112 al_set_clipping_rectangle((
int)ax, (
int)ay, (
int)item_area_w, (
int)rows_h);
10114 al_hold_bitmap_drawing(
true);
10117 float iy = ay + (float)i * ih;
10121 al_draw_text(
font, tc, ax + pad - ld->
h_scroll, iy + (ih - fh) / 2.0f, 0, item->text);
10126 al_hold_bitmap_drawing(
false);
10127 if (need_hsb) al_set_clipping_rectangle(pcx, pcy, pcw, pch);
10137 if (need_scrollbar)
10154 float ax = ox + wgt->
x;
10155 float ay = oy + wgt->
y;
10156 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
10164 al_draw_scaled_bitmap(rd->
bg_bitmap, 0, 0,
10165 (
float)al_get_bitmap_width(rd->
bg_bitmap), (
float)al_get_bitmap_height(rd->
bg_bitmap),
10166 ax, ay, wgt->
w, wgt->
h, 0);
10169 al_draw_filled_rectangle(ax, ay, ax + wgt->
w, ay + wgt->
h, bg);
10175 float fh = (float)al_get_font_line_height(
font);
10177 int visible_count = (int)(wgt->
h / ih);
10183 int max_off = (int)rd->
nb_items - visible_count;
10184 if (max_off < 0) max_off = 0;
10188 int need_scrollbar = ((int)rd->
nb_items > visible_count) ? 1 : 0;
10194 float iy = ay + (float)i * ih;
10195 float cy = iy + ih / 2.0f;
10196 float cx = ax + pad + radio_r;
10202 ax, iy, wgt->
w, ih, 0);
10206 ax, iy, wgt->
w, ih, 0);
10218 al_hold_bitmap_drawing(
true);
10221 float iy = ay + (float)i * ih;
10222 float cx = ax + pad + radio_r;
10224 cx + radio_r + pad, iy + (ih - fh) / 2.0f, 0, rd->
items[idx].
text);
10226 al_hold_bitmap_drawing(
false);
10230 if (need_scrollbar)
10238 float ax = ox + wgt->
x;
10239 float ay = oy + wgt->
y;
10240 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
10243 al_draw_scaled_bitmap(cd->
bg_bitmap, 0, 0,
10244 (
float)al_get_bitmap_width(cd->
bg_bitmap), (
float)al_get_bitmap_height(cd->
bg_bitmap),
10245 ax, ay, wgt->
w, wgt->
h, 0);
10255 const char* display_text =
"";
10259 int cbbbx = 0, cbbby = 0, cbbbw = 0, cbbbh = 0;
10260 _text_dims(
font, display_text[0] ? display_text :
"Ay", &cbbbx, &cbbby, &cbbbw, &cbbbh);
10261 float fh = (float)cbbbh;
10264 ax + pad, ay + (wgt->
h - fh) / 2.0f - (
float)cbbby, max_text_w, display_text);
10268 float arrow_y = ay + wgt->
h / 2.0f;
10286 float ay_down = widget_bottom;
10287 float ay_up = widget_top - panel_h;
10288 int fits_down = (ctx->
display_h <= 0) || (ay_down + panel_h <= (
float)ctx->
display_h);
10289 int fits_up = (ay_up >= 0.0f);
10291 return fits_up ? ay_up : (fits_down ? ay_down : ay_up);
10293 if (!fits_down && fits_up)
return ay_up;
10294 if (!fits_down && !fits_up) {
10296 float space_down = (ctx->
display_h > 0) ? ((
float)ctx->
display_h - widget_bottom) : panel_h;
10297 float space_up = widget_top;
10298 return (space_up > space_down) ? ay_up : ay_down;
10318 ALLEGRO_FONT*
font = NULL;
10320 float ox = 0, oy = 0, fh = 0, ih = 0,
h = 0;
10325 if (!owner)
return 0;
10327 if (!
font)
return 0;
10329 fh = (float)al_get_font_line_height(
font);
10333 h = (float)vis * ih;
10335 *out_x = ox + wgt->
x;
10349 ALLEGRO_FONT*
font = NULL;
10351 float ox = 0, oy = 0, ax = 0, ay = 0, pw = 0, ph = 0, ih = 0, pad = 0, fh = 0;
10352 int vis = 0, i = 0;
10353 int prev_cx = 0, prev_cy = 0, prev_cw = 0, prev_ch = 0;
10357 if (!wgt || !wgt->
data) {
10374 fh = (float)al_get_font_line_height(
font);
10377 al_draw_filled_rectangle(ax, ay, ax + pw, ay + ph, wgt->
theme.
bg_normal);
10379 al_get_clipping_rectangle(&prev_cx, &prev_cy, &prev_cw, &prev_ch);
10380 al_set_clipping_rectangle((
int)ax, (
int)ay, (
int)pw, (
int)ph);
10384 float iy = ay + (float)i * ih;
10392 al_hold_bitmap_drawing(
true);
10395 float iy = ay + (float)i * ih;
10402 al_hold_bitmap_drawing(
false);
10403 al_set_clipping_rectangle(prev_cx, prev_cy, prev_cw, prev_ch);
10423 float dropdown_w = widget_w;
10424 float max_item_w = 0, needed, cap;
10428 for (i = 0; i < cd->
nb_items; i++) {
10430 if (tw > max_item_w) max_item_w = tw;
10432 needed = max_item_w + pad * 2;
10433 if (needed > dropdown_w) dropdown_w = needed;
10437 if (dropdown_w > cap) dropdown_w = cap;
10440 dropdown_w = (float)ctx->
display_w - ax;
10441 if (dropdown_w < widget_w) dropdown_w = widget_w;
10449 if (!wgt || !wgt->
data)
return;
10454 float ox = 0, oy = 0;
10456 if (!owner)
return;
10463 float ax = ox + wgt->
x;
10464 float fh = (float)al_get_font_line_height(
font);
10468 float dropdown_h = (float)vis * ih;
10479 if (sb_size < 10.0f) sb_size = 10.0f;
10480 float item_area_w = need_scrollbar ? dropdown_w - sb_size : dropdown_w;
10484 al_draw_scaled_bitmap(cd->
bg_bitmap, 0, 0,
10485 (
float)al_get_bitmap_width(cd->
bg_bitmap), (
float)al_get_bitmap_height(cd->
bg_bitmap),
10486 ax, ay, dropdown_w, dropdown_h, 0);
10490 al_draw_filled_rectangle(ax, ay, ax + dropdown_w, ay + dropdown_h, wgt->
theme.
bg_normal);
10498 int prev_cx = 0, prev_cy = 0, prev_cw = 0, prev_ch = 0;
10499 al_get_clipping_rectangle(&prev_cx, &prev_cy, &prev_cw, &prev_ch);
10500 al_set_clipping_rectangle((
int)ax, (
int)ay, (
int)dropdown_w, (
int)dropdown_h);
10504 float max_text_w = item_area_w - pad * 2;
10507 float iy = ay + (float)i * ih;
10519 }
else if (hovered) {
10529 al_hold_bitmap_drawing(
true);
10532 float iy = ay + (float)i * ih;
10536 al_hold_bitmap_drawing(
false);
10538 al_set_clipping_rectangle(prev_cx, prev_cy, prev_cw, prev_ch);
10550 if (need_scrollbar) {
10551 float sb_x = ax + dropdown_w - sb_size;
10570 float ax = ox + wgt->
x;
10571 float ay = oy + wgt->
y;
10572 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
10574 int draw_state = wgt->
state;
10582 int dbbx = 0, dbby = 0, dbbw = 0, dbbh = 0;
10584 float fh = (float)dbbh;
10593 float arrow_y = ay + wgt->
h / 2.0f;
10604 if (!wgt || !wgt->
data)
return;
10609 float ox = 0, oy = 0;
10611 if (!owner)
return;
10618 float ax = ox + wgt->
x;
10619 float fh = (float)al_get_font_line_height(
font);
10623 float panel_h = (float)vis * ih;
10633 if (sb_size < 10.0f) sb_size = 10.0f;
10634 float item_area_w = need_scrollbar ? panel_w - sb_size : panel_w;
10643 ax, ay, panel_w, panel_h, 0);
10644 }
else if (panel_rounded) {
10645 al_draw_filled_rounded_rectangle(ax, ay, ax + panel_w, ay + panel_h, prx, pry, wgt->
theme.
bg_normal);
10647 al_draw_filled_rectangle(ax, ay, ax + panel_w, ay + panel_h, wgt->
theme.
bg_normal);
10655 float max_text_w = item_area_w - pad * 2.0f;
10658 float iy = ay + (float)i * ih;
10672 al_hold_bitmap_drawing(
true);
10675 float iy = ay + (float)i * ih;
10680 al_hold_bitmap_drawing(
false);
10683 if (need_scrollbar) {
10684 float sb_x = ax + panel_w - sb_size;
10703 float ax = ox + wgt->
x;
10704 float ay = oy + wgt->
y;
10709 if (!id->
bitmap)
return;
10710 float bw = (float)al_get_bitmap_width(id->
bitmap);
10711 float bh = (float)al_get_bitmap_height(id->
bitmap);
10714 al_draw_scaled_bitmap(id->
bitmap, 0, 0, bw, bh, ax, ay, wgt->
w, wgt->
h, 0);
10716 float dx = ax + (wgt->
w - bw) / 2.0f;
10717 float dy = ay + (wgt->
h - bh) / 2.0f;
10718 al_draw_bitmap(id->
bitmap, dx, dy, 0);
10721 float scale_x = wgt->
w / bw;
10722 float scale_y = wgt->
h / bh;
10723 float scale = (scale_x < scale_y) ? scale_x : scale_y;
10724 float dw = bw * scale;
10725 float dh = bh * scale;
10726 float dx = ax + (wgt->
w - dw) / 2.0f;
10727 float dy = ay + (wgt->
h - dh) / 2.0f;
10728 al_draw_scaled_bitmap(id->
bitmap, 0, 0, bw, bh, dx, dy, dw, dh, 0);
10738 if (!
font || !lb->
text[0])
return -1;
10739 if (click_x <= 0)
return 0;
10740 size_t len = strlen(lb->
text);
10743 float best_dist = click_x;
10744 for (
size_t i = 0; i < len;) {
10746 if (i + (
size_t)clen > len) clen = (int)(len - i);
10747 size_t pos = i + (size_t)clen;
10748 memcpy(tmp, lb->
text, pos);
10751 float dist = click_x - tw;
10752 if (dist < 0) dist = -dist;
10753 if (dist < best_dist) {
10757 if (tw > click_x)
break;
10772 float effective_w = wgt_w;
10773 float max_from_win = win_w - wgt_x;
10775 if (!(win_w > 0) || !(max_from_win > effective_w))
return effective_w;
10777 float widest = 0.0f;
10779 if (
font && strchr(lb->
text,
'\n')) {
10783 for (
int i = 0; i < lines; i++) {
10786 if (lw > widest) widest = lw;
10791 if (widest <= wgt_w - label_padding * 2.0f)
return effective_w;
10793 return max_from_win;
10801 int lbbx = 0, lbby = 0, lbbw = 0, lbbh = 0;
10803 float tw = (float)lbbw;
10804 float max_text_w = effective_w - label_padding * 2;
10806 if (tw > max_text_w)
return ax + label_padding;
10807 return ax + (effective_w - tw) / 2.0f - (
float)lbbx;
10810 if (tw > max_text_w)
return ax + label_padding;
10811 return ax + effective_w - tw - label_padding - (float)lbbx;
10814 return ax + label_padding;
10827 al_draw_text(
font, color, x, y, 0, shown);
10835 if (*
text ==
'\n') n++;
10844 const char* end = NULL;
10848 if (!
text || !out || out_len == 0)
return -1;
10849 for (; index > 0; index--) {
10851 if (!
start)
return -1;
10854 end = strchr(
start,
'\n');
10855 len = end ? (size_t)(end -
start) : strlen(
start);
10856 if (len > 0 &&
start[len - 1] ==
'\r') len--;
10857 if (len >= out_len) len = out_len - 1;
10858 memcpy(out,
start, len);
10866 float max_w = effective_w - pad * 2.0f;
10868 if (line_w > max_w)
return ax + pad;
10877 float top = ay + (
h - (float)lines * fh) / 2.0f;
10878 return top < ay ? ay : top;
10885 float fh = (float)al_get_font_line_height(
font);
10888 float max_w = effective_w - pad * 2.0f;
10889 int slo = -1, shi = -1;
10893 int pcx, pcy, pcw, pch;
10902 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
10904 for (i = 0; i < lines; i++) {
10906 float y = top + (float)i * fh;
10907 float lw = 0.0f, x = 0.0f;
10910 if (
start < 0)
break;
10911 llen = (int)strlen(
line);
10915 if (slo >= 0 && slo < start + llen + 1 && shi >
start) {
10918 int b = shi <
start + llen ? shi -
start : llen;
10919 float x1 = 0.0f, x2 = 0.0f;
10921 memcpy(part,
line, (
size_t)a);
10924 memcpy(part,
line, (
size_t)b);
10927 if (x2 > x1) al_draw_filled_rectangle(x + x1, y, x + x2, y + fh, sel_color);
10929 if (!
line[0])
continue;
10933 al_draw_text(
font, tc, x, y, 0,
line);
10935 al_set_clipping_rectangle(pcx, pcy, pcw, pch);
10940 float fh = (float)al_get_font_line_height(
font);
10943 int index = (int)((my - top) / fh);
10947 int start = 0, best = 0;
10948 size_t len = 0, i = 0;
10949 float x = 0.0f, best_dist = 0.0f;
10951 if (index < 0) index = 0;
10952 if (index >= lines) index = lines - 1;
10954 if (
start < 0)
return -1;
10956 len = strlen(
line);
10957 best_dist = mx - x;
10958 if (best_dist < 0) best_dist = -best_dist;
10959 for (i = 0; i < len;) {
10963 if (i + (
size_t)clen > len) clen = (int)(len - i);
10965 memcpy(part,
line, i);
10968 if (dist < 0) dist = -dist;
10969 if (dist < best_dist) {
10974 return start + best;
10979 float ax = ox + wgt->
x;
10980 float ay = oy + wgt->
y;
10981 ALLEGRO_FONT*
font = wgt->
font ? wgt->
font : default_font;
10985 al_draw_scaled_bitmap(lb->
bg_bitmap, 0, 0,
10986 (
float)al_get_bitmap_width(lb->
bg_bitmap), (
float)al_get_bitmap_height(lb->
bg_bitmap),
10987 ax, ay, wgt->
w, wgt->
h, 0);
10990 if (!
font || !lb->
text[0])
return;
10992 int lbbbx = 0, lbbby = 0, lbbbw = 0, lbbbh = 0;
10994 float fh = (float)lbbbh;
11000 int is_link = (lb->
link[0] !=
'\0') ? 1 : 0;
11013 float tw = (float)lbbbw;
11019 float view_h = wgt->
h - lpad;
11022 int need_scrollbar = (content_h > view_h) ? 1 : 0;
11024 float text_w = wrap_w - sb_size;
11027 if (need_scrollbar) {
11028 float max_sy = content_h - view_h;
11029 if (max_sy < 0) max_sy = 0;
11037 int pcx, pcy, pcw, pch;
11038 al_get_clipping_rectangle(&pcx, &pcy, &pcw, &pch);
11041 float text_y = ay + lpad / 2.0f - lb->
scroll_y;
11052 float draw_w = tw < text_w ? tw : text_w;
11056 al_set_clipping_rectangle(pcx, pcy, pcw, pch);
11059 if (need_scrollbar) {
11067 if (strchr(lb->
text,
'\n')) {
11073 float ty = ay + (wgt->
h - fh) / 2.0f - (
float)lbbby;
11076 if (tw > max_text_w) {
11080 tx = ax + (effective_w - tw) / 2.0f - (
float)lbbbx;
11081 al_draw_text(
font, tc, tx, ty, 0, lb->
text);
11084 if (tw > max_text_w) {
11088 tx = ax + effective_w - tw - style->
label_padding - (float)lbbbx;
11089 al_draw_text(
font, tc, tx, ty, 0, lb->
text);
11094 if (tw > max_text_w) {
11097 al_draw_text(
font, tc, tx, ty, 0, lb->
text);
11105 size_t tlen = strlen(lb->
text);
11106 if ((
size_t)slo > tlen) slo = (int)tlen;
11107 if ((
size_t)shi > tlen) shi = (int)tlen;
11109 memcpy(stmp, lb->
text, (
size_t)slo);
11112 memcpy(stmp, lb->
text, (
size_t)shi);
11120 float draw_w = tw < max_text_w ? tw : max_text_w;
11132 if (!cd || !cd->
draw)
return;
11144 float ax = ox + wgt->
x, ay = oy + wgt->
y;
11148 if (t < 2.0f) t = 2.0f;
11150 if (wgt->
w <= in * 2.0f || wgt->
h <= in * 2.0f)
return;
11152 al_draw_rounded_rectangle(ax + in, ay + in, ax + wgt->
w - in, ay + wgt->
h - in, r, wgt->
theme.
corner_ry,
11155 al_draw_rectangle(ax + in, ay + in, ax + wgt->
w - in, ay + wgt->
h - in, wgt->
theme.
border_active, t);
11159 if (!wgt || !wgt->
visible)
return;
11162 int saved_state = wgt->
state;
11167 switch (wgt->
type) {
11196 _draw_label(wgt, ox, oy, default_font, win_w, style);
11235 wgt->
state = saved_state;
11236 float dx = ox + wgt->
x;
11237 float dy = oy + wgt->
y;
11238 al_draw_filled_rectangle(dx, dy, dx + wgt->
w, dy + wgt->
h,
11239 al_map_rgba(0, 0, 0, 120));
11258 if (count == 0)
return 0.0f;
11275 if (!(win->
flags & flag))
return 0;
11292 *out_x = right_edge - sz - (float)pos * (sz + style->
tb_btn_spacing);
11302 for (
int i = 0; i < 3; i++) {
11303 int bt = btn_types[i];
11304 float bx, by, bw, bh;
11318 ALLEGRO_BITMAP* bmp = NULL;
11343 al_draw_scaled_bitmap(bmp, 0, 0,
11344 (
float)al_get_bitmap_width(bmp), (
float)al_get_bitmap_height(bmp),
11345 bx, by, bw, bh, 0);
11352 float cx = bx + bw / 2.0f;
11353 float cy = by + bh / 2.0f;
11354 float g = bw * 0.22f;
11359 al_draw_line(cx - g, cy + g * 0.5f, cx + g, cy + g * 0.5f, gc, thick);
11363 float off = g * 0.4f;
11364 al_draw_rectangle(cx - g + off, cy - g, cx + g, cy + g - off, gc, thick);
11365 al_draw_rectangle(cx - g, cy - g + off, cx + g - off, cy + g, gc, thick);
11368 al_draw_rectangle(cx - g, cy - g, cx + g, cy + g, gc, thick);
11371 al_draw_line(cx - g, cy - g, cx + g, cy + g, gc, thick);
11372 al_draw_line(cx + g, cy - g, cx - g, cy + g, gc, thick);
11382 ALLEGRO_FONT*
font = win->
font ? win->
font : default_font;
11384 float tbh = frameless ? 0.0f : win->
titlebar_h;
11391 win->
x, win->
y, win->
w, tbh, 0);
11394 al_draw_filled_rounded_rectangle(win->
x, win->
y, win->
x + win->
w, win->
y + tbh,
11399 if (
font && shown_title[0]) {
11400 int tbbx = 0, tbby = 0, tbbw = 0, tbbh = 0;
11402 float fh = (float)tbbh;
11406 win->
x + style->
title_padding, win->
y + (tbh - fh) / 2.0f - (
float)tbby, max_title_w, shown_title);
11415 float body_y = win->
y + tbh;
11416 float body_h = win->
h - tbh;
11419 int need_vscroll = 0;
11420 int need_hscroll = 0;
11425 if (win->
content_h > body_h) need_vscroll = 1;
11426 if (win->
content_w > win->
w) need_hscroll = 1;
11428 if (need_vscroll && win->
content_w > (win->
w - scrollbar_size)) need_hscroll = 1;
11429 if (need_hscroll && win->
content_h > (body_h - scrollbar_size)) need_vscroll = 1;
11438 float content_area_w = win->
w - (need_vscroll ? scrollbar_size : 0);
11439 float content_area_h = body_h - (need_hscroll ? scrollbar_size : 0);
11442 if (need_vscroll) {
11443 float max_sy = win->
content_h - content_area_h;
11444 if (max_sy < 0) max_sy = 0;
11450 if (need_hscroll) {
11451 float max_sx = win->
content_w - content_area_w;
11452 if (max_sx < 0) max_sx = 0;
11467 float bg_top = frameless ? body_y : body_y - 1.0f;
11473 al_draw_filled_rounded_rectangle(win->
x, bg_top, win->
x + win->
w, win->
y + win->
h,
11477 al_draw_filled_rectangle(win->
x, bg_top, win->
x + win->
w, win->
y + win->
h,
11480 al_draw_rounded_rectangle(win->
x, win->
y, win->
x + win->
w, win->
y + win->
h,
11486 float oy = body_y - win->
scroll_y;
11489 int prev_cx, prev_cy, prev_cw, prev_ch;
11490 al_get_clipping_rectangle(&prev_cx, &prev_cy, &prev_cw, &prev_ch);
11496 (
int)content_area_w - clip_pad, (
int)content_area_h);
11503 float label_win_w = 0;
11507 label_win_w = win->
w;
11513 al_set_clipping_rectangle(prev_cx, prev_cy, prev_cw, prev_ch);
11520 if (need_vscroll) {
11521 float sb_x = win->
x + win->
w - scrollbar_size;
11522 float sb_y = body_y;
11523 float sb_h = content_area_h;
11538 NULL, &skin, &win->
theme);
11540 if (need_hscroll) {
11541 float sb_x = win->
x;
11542 float sb_y = win->
y + win->
h - scrollbar_size;
11543 float sb_w = content_area_w;
11554 NULL, &skin, &win->
theme);
11559 float rx = win->
x + win->
w;
11560 float ry = win->
y + win->
h;
11562 ALLEGRO_COLOR grip_color = style->
grip_color;
11565 al_draw_line(rx - grip_size, ry - 2, rx - 2, ry - grip_size, grip_color, grip_thick);
11566 al_draw_line(rx - grip_size + 4, ry - 2, rx - 2, ry - grip_size + 4, grip_color, grip_thick);
11567 al_draw_line(rx - grip_size + 8, ry - 2, rx - 2, ry - grip_size + 8, grip_color, grip_thick);
11570 al_draw_rounded_rectangle(win->
x, win->
y, win->
x + win->
w, win->
y + tbh,
11578 float max_r = 0, max_b = 0;
11585 float r = win->
x + win->
w;
11586 float b = win->
y + win->
h;
11587 if (r > max_r) max_r = r;
11588 if (b > max_b) max_b = b;
11603 if (eff_w > 0 && eff_h > 0) {
11612 if (need_v) *need_v = v;
11613 if (need_h) *need_h =
h;
11653 float ox = 0.0f, oy = 0.0f;
11655 ALLEGRO_DISPLAY* owner = tip_win ? tip_win->
native : NULL;
11661 float disp_w = (owner ? (float)al_get_display_width(owner) : (float)ctx->
display_w);
11662 float disp_h = (owner ? (float)al_get_display_height(owner) : (float)ctx->
display_h);
11672 float cl = 0.0f, ct = 0.0f, cr = disp_w, cb = disp_h;
11673 if (tip_win && owner) {
11674 if (tip_win->
x > cl) cl = tip_win->
x;
11675 if (tip_win->
y > ct) ct = tip_win->
y;
11676 if (disp_w > 0.0f && tip_win->
x + tip_win->
w < cr) cr = tip_win->
x + tip_win->
w;
11677 if (disp_h > 0.0f && tip_win->
y + tip_win->
h < cb) cb = tip_win->
y + tip_win->
h;
11678 if (cr - cl < 8.0f || cb - ct < 8.0f) {
11686 float line_h = (float)al_get_font_line_height(ctx->
default_font) + 2.0f;
11687 float max_text_w = (cr - cl) - 4.0f - 16.0f;
11688 float natural_w, text_w, bw, bh, bx, by;
11694 if (max_text_w < 1.0f) max_text_w = 1.0f;
11696 if (natural_w <= max_text_w) {
11697 text_w = natural_w;
11699 text_w = max_text_w;
11702 if (nlines < 1) nlines = 1;
11704 bw = text_w + 16.0f;
11705 bh = (float)nlines * line_h + 10.0f;
11706 bx = (float)ctx->
mouse_x + 14.0f;
11707 by = (float)ctx->
mouse_y + 20.0f;
11710 if (bx + bw > cr) bx = cr - bw;
11711 if (bx < cl) bx = cl;
11712 if (by + bh > cb) by = (float)ctx->
mouse_y - bh - 6.0f;
11713 if (by + bh > cb) by = cb - bh;
11714 if (by < ct) by = ct;
11715 al_draw_filled_rounded_rectangle(bx, by, bx + bw, by + bh, 4.0f, 4.0f, ctx->
style.
tooltip_bg);
11716 al_draw_rounded_rectangle(bx, by, bx + bw, by + bh, 4.0f, 4.0f, ctx->
style.
tooltip_border, 1.0f);
11747 ALLEGRO_BITMAP* target = al_get_target_bitmap();
11750 float tw = (float)al_get_bitmap_width(target);
11751 float th = (float)al_get_bitmap_height(target);
11756 "n_gui: no display size was set, using the draw target's %.0fx%.0f; "
11757 "call n_gui_set_display_size() at start up and on resize",
11758 (
double)tw, (
double)th);
11775 int need_global_vscroll = 0;
11776 int need_global_hscroll = 0;
11783 if (eff_w > 0 && eff_h > 0) {
11787 float view_w = eff_w - (need_global_vscroll ? scrollbar_size : 0);
11788 float view_h = eff_h - (need_global_hscroll ? scrollbar_size : 0);
11789 if (need_global_vscroll) {
11791 if (max_sy < 0) max_sy = 0;
11797 if (need_global_hscroll) {
11799 if (max_sx < 0) max_sx = 0;
11808 ALLEGRO_TRANSFORM global_tf, prev_tf;
11809 al_copy_transform(&prev_tf, al_get_current_transform());
11810 al_identity_transform(&global_tf);
11816 al_compose_transform(&global_tf, &prev_tf);
11817 al_use_transform(&global_tf);
11820 int prev_cx, prev_cy, prev_cw, prev_ch;
11822 if (need_global_vscroll || need_global_hscroll) {
11823 al_get_clipping_rectangle(&prev_cx, &prev_cy, &prev_cw, &prev_ch);
11825 float clip_vw = eff_w - (need_global_vscroll ? scrollbar_size : 0);
11826 float clip_vh = eff_h - (need_global_hscroll ? scrollbar_size : 0);
11832 al_set_clipping_rectangle(0, 0, (
int)clip_vw, (
int)clip_vh);
11864 al_set_clipping_rectangle(prev_cx, prev_cy, prev_cw, prev_ch);
11869 if (need_global_vscroll || need_global_hscroll) {
11870 ALLEGRO_TRANSFORM sb_tf;
11871 al_identity_transform(&sb_tf);
11876 al_compose_transform(&sb_tf, &prev_tf);
11877 al_use_transform(&sb_tf);
11886 if (need_global_vscroll) {
11887 float sb_x = eff_w - scrollbar_size;
11888 float sb_h = eff_h - (need_global_hscroll ? scrollbar_size : 0);
11896 if (need_global_hscroll) {
11897 float sb_y = eff_h - scrollbar_size;
11898 float sb_w = eff_w - (need_global_vscroll ? scrollbar_size : 0);
11911 al_use_transform(&prev_tf);
11936 ALLEGRO_BITMAP* prev_target = al_get_target_bitmap();
11957 if (!victim)
break;
11976 if (!win || !win->
native)
continue;
11983 if (al_get_display_flags(win->
native) & ALLEGRO_MINIMIZED)
continue;
11985 al_set_target_backbuffer(win->
native);
11987 ALLEGRO_TRANSFORM id_tf, prev_tf;
11988 al_copy_transform(&prev_tf, al_get_current_transform());
11989 al_identity_transform(&id_tf);
11990 al_use_transform(&id_tf);
12010 al_use_transform(&prev_tf);
12014 if (prev_target) al_set_target_bitmap(prev_target);
12029 if ((w > 0) != (
h > 0)) {
12030 n_log(
LOG_ERR,
"n_gui_set_virtual_size: both dimensions must be > 0 (got w=%.1f, h=%.1f); virtual canvas not changed", w,
h);
12149 if (!win)
return 0;
12227 if (w < 1.0f) w = 1.0f;
12228 if (
h < 1.0f)
h = 1.0f;
12237 if (!wgt)
continue;
12241 }
else if (w > 0.0f) {
12249 }
else if (
h > 0.0f) {
12271 if (new_w <= 0 || new_h <= 0)
return;
12277 if (win->
native)
continue;
12281 win->
x = win->
norm_x * new_w;
12282 win->
y = win->
norm_y * new_h;
12287 win->
x = win->
norm_x * new_w;
12288 win->
y = win->
norm_y * new_h;
12289 win->
w = win->
norm_w * new_w;
12290 win->
h = win->
norm_h * new_h;
12388 if (scale < 0.25f) scale = 0.25f;
12389 if (scale > 8.0f) scale = 8.0f;
12424 float scale = 1.0f;
12429 int logical_w = al_get_display_width(
display);
12430 int logical_h = al_get_display_height(
display);
12431 ALLEGRO_BITMAP* backbuffer = al_get_backbuffer(
display);
12432 if (backbuffer && logical_w > 0 && logical_h > 0) {
12433 int physical_w = al_get_bitmap_width(backbuffer);
12434 int physical_h = al_get_bitmap_height(backbuffer);
12435 float scale_x = (float)physical_w / (
float)logical_w;
12436 float scale_y = (float)physical_h / (
float)logical_h;
12437 scale = (scale_x > scale_y) ? scale_x : scale_y;
12438 if (scale < 0.5f) scale = 1.0f;
12441#ifdef ALLEGRO_ANDROID
12444 int dpi = al_get_display_option(
display, ALLEGRO_DEFAULT_DISPLAY_ADAPTER);
12448 float android_scale = (float)dpi / 160.0f;
12449 if (android_scale >= 0.5f) scale = android_scale;
12453 if (scale < 0.25f) scale = 0.25f;
12454 if (scale > 8.0f) scale = 8.0f;
12464 if (wgt->
w <= 0)
return;
12465 if (wgt->
h <= 0)
return;
12471 float travel_start = 0.0f, travel_len = 0.0f;
12474 if (travel_len <= 0.0f)
return;
12477 float ay = win_content_y + wgt->
y;
12478 float local_y = my - ay;
12480 ratio = 1.0 - (double)(local_y - travel_start) / (double)travel_len;
12482 float ax = win_x + wgt->
x;
12483 float local_x = mx - ax;
12484 ratio = (double)(local_x - travel_start) / (double)travel_len;
12486 if (ratio < 0.0) ratio = 0.0;
12487 if (ratio > 1.0) ratio = 1.0;
12489 if (sd->
step > 0.0)
12493 if (new_val != sd->
value) {
12494 sd->
value = new_val;
12504 float ax = win_x + wgt->
x;
12505 float ay = win_content_y + wgt->
y;
12508 if (ratio_viewport > 1.0) ratio_viewport = 1.0;
12510 if (max_scroll < 0) max_scroll = 0;
12514 float thumb_h = (float)(ratio_viewport * (
double)wgt->
h);
12516 float track_range = wgt->
h - thumb_h;
12517 if (track_range <= 0)
return;
12518 pos_ratio = (double)(my - ay - thumb_h / 2.0f) / (double)track_range;
12520 float thumb_w = (float)(ratio_viewport * (
double)wgt->
w);
12522 float track_range = wgt->
w - thumb_w;
12523 if (track_range <= 0)
return;
12524 pos_ratio = (double)(mx - ax - thumb_w / 2.0f) / (double)track_range;
12526 if (pos_ratio < 0.0) pos_ratio = 0.0;
12527 if (pos_ratio > 1.0) pos_ratio = 1.0;
12541 out[0] = (char)(0xC0 | (cp >> 6));
12542 out[1] = (char)(0x80 | (cp & 0x3F));
12545 if (cp < 0x10000) {
12546 out[0] = (char)(0xE0 | (cp >> 12));
12547 out[1] = (char)(0x80 | ((cp >> 6) & 0x3F));
12548 out[2] = (char)(0x80 | (cp & 0x3F));
12551 if (cp < 0x110000) {
12552 out[0] = (char)(0xF0 | (cp >> 18));
12553 out[1] = (char)(0x80 | ((cp >> 12) & 0x3F));
12554 out[2] = (char)(0x80 | ((cp >> 6) & 0x3F));
12555 out[3] = (char)(0x80 | (cp & 0x3F));
12573 size_t del_len = hi - lo;
12586 size_t len = hi - lo;
12588 Malloc(tmp,
char, len + 1);
12589 if (!tmp)
return 0;
12590 memcpy(tmp, &td->
text[lo], len);
12606 size_t clip_len = strlen(clip);
12611 for (
size_t ci = 0; ci < clip_len && flen <
N_GUI_TEXT_MAX - 1; ci++) {
12612 if (clip[ci] ==
'\r') {
12614 }
else if (clip[ci] ==
'\n') {
12615 if (td->
multiline) filtered[flen++] =
'\n';
12616 }
else if ((
unsigned char)clip[ci] >= 32 || ((
unsigned char)clip[ci] & 0xC0) == 0x80) {
12617 filtered[flen++] = clip[ci];
12618 }
else if (((
unsigned char)clip[ci] & 0xC0) == 0xC0) {
12619 filtered[flen++] = clip[ci];
12622 filtered[flen] =
'\0';
12623 if (flen > 0 && td->
text_len + flen <= td->char_limit) {
12653 size_t tlen = strlen(lb->
text);
12654 if ((
size_t)slo > tlen) slo = (int)tlen;
12655 if ((
size_t)shi > tlen) shi = (int)tlen;
12656 int len = shi - slo;
12658 Malloc(sel,
char, (
size_t)len + 1);
12660 memcpy(sel, &lb->
text[slo], (
size_t)len);
12675 size_t len = hi - lo;
12676 Malloc(sel,
char, len + 1);
12678 memcpy(sel, &td->
text[lo], len);
12731 if (*s == c)
return 1;
12749 while (s < td->text_len && (td->
text[s] ==
' ' || td->
text[s] ==
'\t')) s++;
12780 size_t start = 0, end = 0, len = 0;
12789 if (len >=
sizeof(prefix)) len =
sizeof(prefix) - 1;
12791 prefix[len] =
'\0';
12825 const char* pick = NULL;
12826 size_t start = 0, end = 0, pick_len = 0, tail_len = 0;
12831 pick_len = strlen(pick);
12842 memmove(td->
text +
start + pick_len, td->
text + end, tail_len);
12843 memcpy(td->
text +
start, pick, pick_len);
12857 n_log(
LOG_WARNING,
"n_gui_textarea_set_suggest: widget %d is not a textarea", widget_id);
12865 separators ? separators :
"");
12893 int shift = (ev->keyboard.modifiers & ALLEGRO_KEYMOD_SHIFT) ? 1 : 0;
12894 int ctrl = (ev->keyboard.modifiers & ALLEGRO_KEYMOD_CTRL) ? 1 : 0;
12897 if (ctrl && ev->keyboard.keycode == ALLEGRO_KEY_A) {
12906 if (ctrl && ev->keyboard.keycode == ALLEGRO_KEY_C) {
12914 if (ctrl && ev->keyboard.keycode == ALLEGRO_KEY_X) {
12923 if (ctrl && ev->keyboard.keycode == ALLEGRO_KEY_V) {
12934 if (ev->keyboard.keycode == ALLEGRO_KEY_BACKSPACE) {
12939 int cont_count = 0;
12943 }
while (erase_start > 0 && cont_count <= 3 && ((
unsigned char)td->
text[erase_start] & 0xC0) == 0x80);
12944 size_t erase_len = td->
cursor_pos - erase_start;
12953 if (ev->keyboard.keycode == ALLEGRO_KEY_DELETE) {
12966 if (ev->keyboard.keycode == ALLEGRO_KEY_LEFT) {
12988 if (ev->keyboard.keycode == ALLEGRO_KEY_RIGHT) {
13009 if (ev->keyboard.keycode == ALLEGRO_KEY_HOME) {
13020 if (ev->keyboard.keycode == ALLEGRO_KEY_END) {
13033 if (ev->keyboard.keycode == ALLEGRO_KEY_UP || ev->keyboard.keycode == ALLEGRO_KEY_DOWN) {
13041 float base_wrap_w = wgt->
w - pad * 2;
13042 float text_area_h = wgt->
h - pad * 2;
13044 float wrap_w = (content_h > text_area_h)
13045 ? (wgt->
w - sb_size - pad * 2)
13051 int cursor_line = 0;
13052 float cursor_x = 0;
13054 for (
size_t i = 0; i < td->
text_len;) {
13056 cursor_line =
line;
13059 if (td->
text[i] ==
'\n') {
13070 cursor_line =
line;
13075 i += (size_t)step.
clen;
13078 cursor_line =
line;
13081 int total_lines =
line;
13085 if (ev->keyboard.keycode == ALLEGRO_KEY_UP) {
13086 if (cursor_line <= 0) {
13090 target_line = cursor_line - 1;
13092 if (cursor_line >= total_lines) {
13096 target_line = cursor_line + 1;
13102 size_t best_pos = 0;
13103 float best_dist = 1e9f;
13106 if (
line == target_line) {
13107 best_dist = (cursor_x >= 0) ? cursor_x : -cursor_x;
13111 for (
size_t i = 0; i < td->
text_len;) {
13112 if (td->
text[i] ==
'\n') {
13113 if (
line >= target_line)
break;
13116 if (
line == target_line) {
13117 float dist = (cursor_x >= cx) ? (cursor_x - cx) : (cx - cursor_x);
13118 if (dist < best_dist) {
13127 int clen = step.
clen;
13128 float cw = step.
cw;
13130 if (
line >= target_line)
break;
13133 if (
line == target_line) {
13134 float dist = (cursor_x >= cx) ? (cursor_x - cx) : (cx - cursor_x);
13135 if (dist < best_dist) {
13143 if (
line == target_line) {
13144 float dist = (cursor_x >= cx) ? (cursor_x - cx) : (cx - cursor_x);
13145 if (dist < best_dist) {
13147 best_pos = i + (size_t)clen;
13162 if (ev->keyboard.keycode == ALLEGRO_KEY_ENTER) {
13181 if (ev->keyboard.unichar >= 32) {
13187 int utf8_len =
_utf8_encode(ev->keyboard.unichar, utf8);
13188 if (utf8_len > 0 && td->
text_len + (
size_t)utf8_len <= td->char_limit) {
13201#define _N_GUI_HELD_LCTRL 0x01
13202#define _N_GUI_HELD_RCTRL 0x02
13203#define _N_GUI_HELD_LSHIFT 0x04
13204#define _N_GUI_HELD_RSHIFT 0x08
13205#define _N_GUI_HELD_ALT 0x10
13206#define _N_GUI_HELD_ALTGR 0x20
13215 case ALLEGRO_KEY_LCTRL:
13217 case ALLEGRO_KEY_RCTRL:
13219 case ALLEGRO_KEY_LSHIFT:
13221 case ALLEGRO_KEY_RSHIFT:
13223 case ALLEGRO_KEY_ALT:
13225 case ALLEGRO_KEY_ALTGR:
13243 int bit = 0, mods = 0;
13245 switch (event->type) {
13246 case ALLEGRO_EVENT_KEY_DOWN:
13249 case ALLEGRO_EVENT_KEY_UP:
13252 case ALLEGRO_EVENT_KEY_CHAR:
13253 mods = (int)event->keyboard.modifiers;
13255 if (!(mods & ALLEGRO_KEYMOD_CTRL))
13260 if (!(mods & ALLEGRO_KEYMOD_SHIFT))
13264 if (mods & ALLEGRO_KEYMOD_ALT)
13268 if (mods & ALLEGRO_KEYMOD_ALTGR)
13273 case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT:
13282 int held = 0, mods = 0;
13284 if (!ctx)
return 0;
13342 if (!highlight || !scroll || nb <= 0)
13352 hi = (delta >= 0) ? -1 : nb;
13363 else if (max_visible > 0 && hi >= *scroll + max_visible)
13364 *scroll = hi - max_visible + 1;
13388 if (!highlight || !scroll || nb <= 0)
13390 most = (max_visible > 0 && nb > max_visible) ? nb - max_visible : 0;
13391 *scroll += notches;
13392 if (*scroll > most)
13396 if (
row >= 0 && *scroll +
row < nb)
13397 *highlight = *scroll +
row;
13413 int kc = ev->keyboard.keycode;
13415 if (!td || !td->
suggest)
return 0;
13417 if (kc == ALLEGRO_KEY_DOWN) {
13424 case ALLEGRO_KEY_ESCAPE:
13427 case ALLEGRO_KEY_UP:
13428 case ALLEGRO_KEY_DOWN:
13431 kc == ALLEGRO_KEY_DOWN ? 1 : -1, -1);
13433 case ALLEGRO_KEY_ENTER:
13434 case ALLEGRO_KEY_PAD_ENTER:
13435 case ALLEGRO_KEY_TAB:
13445#define N_GUI_COLRESIZE_GRAB 4.0f
13463 if (border_col) *border_col = -1;
13464 if (cell_col) *cell_col = -1;
13465 for (c = 0; c < gd->
nb_cols; c++) {
13471 if (border_col) *border_col = (int)pc;
13474 if (x >= bx && x <
right) {
13475 if (cell_col) *cell_col = (int)pc;
13499 ALLEGRO_FONT*
font;
13500 float ax, ay, fh, row_h;
13507 fh =
font ? (float)al_get_font_line_height(
font) : 16.0f;
13512 if (py < ay + row_h) {
13515 over = (border_col >= 0);
13529 if (!ctx)
return -1;
13532 float ox, oy, win_h;
13614 int event_consumed = 0;
13633 if (src && src != ctx->
display) {
13636 if (pwin && pwin->
native == src) {
13656 switch (event.type) {
13657 case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
13658 case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
13659 case ALLEGRO_EVENT_KEY_DOWN:
13660 case ALLEGRO_EVENT_KEY_CHAR:
13661 case ALLEGRO_EVENT_KEY_UP:
13662 case ALLEGRO_EVENT_MOUSE_WARPED:
13663 case ALLEGRO_EVENT_DISPLAY_RESIZE:
13664 case ALLEGRO_EVENT_DISPLAY_EXPOSE:
13665 case ALLEGRO_EVENT_DISPLAY_CLOSE:
13666 case ALLEGRO_EVENT_DISPLAY_SWITCH_IN:
13667 case ALLEGRO_EVENT_DISPLAY_SWITCH_OUT:
13668 case ALLEGRO_EVENT_DISPLAY_HALT_DRAWING:
13669 case ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING:
13688 if (nwin && event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
13713 if (nwin && event.type == ALLEGRO_EVENT_DISPLAY_HALT_DRAWING) {
13715 al_acknowledge_drawing_halt(nwin->
native);
13719 if (nwin && event.type == ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING) {
13720 al_acknowledge_drawing_resume(nwin->
native);
13725 if (nwin && event.type == ALLEGRO_EVENT_DISPLAY_RESIZE) {
13726 al_acknowledge_resize(nwin->
native);
13727 float new_w = (float)al_get_display_width(nwin->
native);
13728 float new_h = (float)al_get_display_height(nwin->
native);
13734 if (new_w > 0.0f) {
13741 if (new_w > 0.0f && new_h > 0.0f) {
13745 if (!wgt)
continue;
13746 wgt->
x = wgt->
norm_x * new_w;
13747 wgt->
y = wgt->
norm_y * new_h;
13748 wgt->
w = wgt->
norm_w * new_w;
13749 wgt->
h = wgt->
norm_h * new_h;
13770 if (event.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) {
13789 if (event.type == ALLEGRO_EVENT_MOUSE_AXES) {
13790 ctx->
mouse_x =
event.mouse.x;
13791 ctx->
mouse_y =
event.mouse.y;
13846 if (divider == 1) {
13847 want = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_E;
13848 }
else if (divider == 2) {
13849 want = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_N;
13851 want = ALLEGRO_SYSTEM_MOUSE_CURSOR_RESIZE_E;
13863 if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
13865 if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN && event.mouse.button == 1) {
13868 ctx->
mouse_x =
event.mouse.x;
13869 ctx->
mouse_y =
event.mouse.y;
13871 if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP && event.mouse.button == 1) {
13880 ctx->
mouse_x =
event.mouse.x;
13881 ctx->
mouse_y =
event.mouse.y;
13906 if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN && event.mouse.button == 2) {
13910 ctx->
mouse_x =
event.mouse.x;
13911 ctx->
mouse_y =
event.mouse.y;
13916 (event.type == ALLEGRO_EVENT_MOUSE_AXES || event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)) {
13918 if (drag_wgt && drag_wgt->
data) {
13919 float d_ox = 0, d_oy = 0;
13927 float d_fh = d_font ? (float)al_get_font_line_height(d_font) : 16.0f;
13928 float d_my = (float)ctx->
mouse_y;
13929 float d_mx = (float)ctx->
mouse_x;
13930 switch (drag_wgt->
type) {
13935 float d_ay = d_oy + drag_wgt->
y + drag_wgt->
h;
13945 float d_ay = d_oy + drag_wgt->
y + drag_wgt->
h;
13953 float d_ax = d_ox + drag_wgt->
x;
13954 float d_ay = d_oy + drag_wgt->
y;
13955 float lb_content_w = 0.0f, lb_pane_w = drag_wgt->
w;
13956 int lb_need_hsb = 0,
visible = 0;
13970 float d_ay = d_oy + drag_wgt->
y;
13971 int visible = (int)(drag_wgt->
h / ih);
13979 float ta_view_h = drag_wgt->
h - ta_pad * 2;
13981 float ta_text_w = drag_wgt->
w - ta_sb_w;
13983 float d_ay = d_oy + drag_wgt->
y + ta_pad;
13985 d_my, d_ay, ta_view_h,
13986 ta_view_h, ta_content_h,
13993 float d_ax = d_ox + drag_wgt->
x;
13994 float d_ay = d_oy + drag_wgt->
y;
13997 r = (drag_wgt->
w > 0) ? ((
float)ctx->
mouse_x - d_ax) / drag_wgt->
w : spd->
ratio;
13999 r = (drag_wgt->
h > 0) ? (d_my - d_ay) / drag_wgt->
h : spd->
ratio;
14000 if (r < spd->min_ratio) r = spd->
min_ratio;
14008 float row_h = d_fh + 2.0f;
14010 int nb_rows = (int)((hd->
len + (
size_t)bpr - 1) / (
size_t)bpr);
14012 float d_ay = d_oy + drag_wgt->
y;
14020 float mview_h = drag_wgt->
h - mpad * 2.0f;
14021 float d_ay2 = d_oy + drag_wgt->
y + mpad;
14030 float d_ax = d_ox + drag_wgt->
x;
14031 float d_ay = d_oy + drag_wgt->
y;
14032 float sv_content_w = 0.0f, sv_pane_w = drag_wgt->
w;
14033 int sv_need_hsb = 0,
visible = 1;
14047 float header_h = row_h;
14048 float data_h = drag_wgt->
h - header_h;
14049 int visible = (int)(data_h / row_h);
14050 float d_ay = d_oy + drag_wgt->
y + header_h;
14055 if (nw < 16.0f) nw = 16.0f;
14060 float d_ax = d_ox + drag_wgt->
x;
14061 float dg_content_w = 0.0f, dg_pane_w = 0.0f;
14078 float screen_mx = (float)ctx->
mouse_x;
14079 float screen_my = (float)ctx->
mouse_y;
14085 float virtual_mx = screen_mx;
14086 float virtual_my = screen_my;
14092 float mx = virtual_mx;
14093 float my = virtual_my;
14099 event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
14103 event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
14107 int just_right_pressed = (
event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN &&
14108 event.mouse.button == 2)
14113 int just_middle_pressed = (
event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN &&
14114 event.mouse.button == 3)
14135 if (ctx->
mouse_b1 && (event.type == ALLEGRO_EVENT_MOUSE_AXES || event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)) {
14139 int need_hscroll = 0;
14141 float sb_h = eff_h - (need_hscroll ? scrollbar_size : 0);
14142 float view_h = sb_h;
14144 if (ratio > 1.0f) ratio = 1.0f;
14145 float thumb_h = ratio * sb_h;
14148 float track_range = sb_h - thumb_h;
14149 if (track_range > 0 && max_scroll > 0) {
14150 float pos_ratio = (virtual_my - thumb_h / 2.0f) / track_range;
14151 if (pos_ratio < 0) pos_ratio = 0;
14152 if (pos_ratio > 1) pos_ratio = 1;
14157 int need_vscroll = 0;
14159 float sb_w = eff_w - (need_vscroll ? scrollbar_size : 0);
14160 float view_w = sb_w;
14162 if (ratio > 1.0f) ratio = 1.0f;
14163 float thumb_w = ratio * sb_w;
14166 float track_range = sb_w - thumb_w;
14167 if (track_range > 0 && max_scroll > 0) {
14168 float pos_ratio = (virtual_mx - thumb_w / 2.0f) / track_range;
14169 if (pos_ratio < 0) pos_ratio = 0;
14170 if (pos_ratio > 1) pos_ratio = 1;
14176 if (just_released) {
14184 if (just_pressed && eff_w > 0 && eff_h > 0) {
14187 int need_vscroll = 0, need_hscroll = 0;
14190 if (need_vscroll) {
14191 float sb_x = eff_w - scrollbar_size;
14192 float sb_h = eff_h - (need_hscroll ? scrollbar_size : 0);
14193 if (
_point_in_rect(virtual_mx, virtual_my, sb_x, 0, scrollbar_size, sb_h)) {
14198 if (need_hscroll) {
14199 float sb_y = eff_h - scrollbar_size;
14200 float sb_w = eff_w - (need_vscroll ? scrollbar_size : 0);
14201 if (
_point_in_rect(virtual_mx, virtual_my, 0, sb_y, sb_w, scrollbar_size)) {
14213 (just_pressed || event.type == ALLEGRO_EVENT_MOUSE_AXES)) {
14216 if (sg_wgt && sg_wgt->
data) {
14218 float sg_x = 0, sg_y = 0, sg_w = 0, sg_h = 0, sg_ih = 0;
14223 if (!just_pressed) {
14224 if (event.type == ALLEGRO_EVENT_MOUSE_AXES && event.mouse.dz != 0) {
14227 -event.mouse.dz, -1);
14231 if (sg_hi >= 0 && sg_hi < sgd->suggest_count)
14239 if (sg_hi >= 0 && sg_hi < sgd->suggest_count) {
14248 if (just_pressed) {
14262 (just_pressed || event.type == ALLEGRO_EVENT_MOUSE_AXES)) {
14264 if (cb_wgt && cb_wgt->
data) {
14268 float cb_ox = 0, cb_oy = 0;
14272 float cb_fh = cb_font ? (float)al_get_font_line_height(cb_font) : 16.0f;
14274 float cb_ax = cb_ox + cb_wgt->
x;
14278 float cb_dd_h = (float)cb_vis * cb_ih;
14285 if (!just_pressed) {
14291 if (event.type == ALLEGRO_EVENT_MOUSE_AXES && event.mouse.dz != 0) {
14294 -event.mouse.dz, (
int)((my - cb_ay) / cb_ih));
14296 int cb_hi = cbd->
scroll_offset + (int)((my - cb_ay) / cb_ih);
14297 if (cb_hi >= 0 && (
size_t)cb_hi < cbd->nb_items) cbd->
highlight_index = cb_hi;
14301 }
else if (
_point_in_rect(mx, my, cb_ax, cb_ay, cb_dd_w, cb_dd_h)) {
14305 if (cb_sb_size < 10.0f) cb_sb_size = 10.0f;
14306 float cb_item_w = cb_need_sb ? cb_dd_w - cb_sb_size : cb_dd_w;
14308 if (cb_need_sb && mx >= cb_ax + cb_item_w) {
14316 int clicked_idx = cbd->
scroll_offset + (int)((my - cb_ay) / cb_ih);
14317 if (clicked_idx >= 0 && (
size_t)clicked_idx < cbd->nb_items) {
14332 if (
_point_in_rect(mx, my, cb_ox + cb_wgt->
x, cb_oy + cb_wgt->
y, cb_wgt->
w, cb_wgt->
h)) {
14348 (just_pressed || event.type == ALLEGRO_EVENT_MOUSE_AXES)) {
14350 if (dm_wgt && dm_wgt->
data) {
14354 float dm_ox = 0, dm_oy = 0;
14358 float dm_fh = dm_font ? (float)al_get_font_line_height(dm_font) : 16.0f;
14360 float dm_ax = dm_ox + dm_wgt->
x;
14363 float dm_panel_h = (float)dm_vis * dm_ih;
14368 int over_panel =
_point_in_rect(mx, my, dm_ax, dm_ay, dm_panel_w, dm_panel_h);
14370 if (!just_pressed) {
14377 if (event.type == ALLEGRO_EVENT_MOUSE_AXES && event.mouse.dz != 0) {
14380 -event.mouse.dz, (
int)((my - dm_ay) / dm_ih));
14382 int dm_hi = dmd->
scroll_offset + (int)((my - dm_ay) / dm_ih);
14383 if (dm_hi >= 0 && (
size_t)dm_hi < dmd->nb_entries) dmd->
highlight_index = dm_hi;
14387 }
else if (over_panel) {
14391 if (dm_sb_size < 10.0f) dm_sb_size = 10.0f;
14392 float dm_item_w = dm_need_sb ? dm_panel_w - dm_sb_size : dm_panel_w;
14394 if (dm_need_sb && mx >= dm_ax + dm_item_w) {
14402 int clicked_idx = dmd->
scroll_offset + (int)((my - dm_ay) / dm_ih);
14403 if (clicked_idx >= 0 && (
size_t)clicked_idx < dmd->nb_entries) {
14417 float dm_btn_ax = dm_ox + dm_wgt->
x;
14418 float dm_btn_ay = dm_oy + dm_wgt->
y;
14431 if (event.type == ALLEGRO_EVENT_MOUSE_AXES ||
14432 event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN ||
14433 event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
14444 if (!wgt)
continue;
14472 captured_wnode = wnode;
14495 event_consumed = 1;
14499 if (!captured_wnode) {
14501 if (just_pressed) {
14505 if (!win)
return 1;
14518 int auto_scrollbar_hit = 0;
14520 float vr[4], hr[4];
14524 if (just_pressed) {
14526 auto_scrollbar_hit = 1;
14530 }
else if (
_point_in_rect(mx, my, hr[0], hr[1], hr[2], hr[3])) {
14532 if (just_pressed) {
14534 auto_scrollbar_hit = 1;
14544 float rx = win->
x + win->
w - grip;
14545 float ry = win->
y + win->
h - grip;
14547 int in_resize_area = 0;
14551 int need_vscroll = 0, need_hscroll = 0;
14553 if (win->
content_h > body_h) need_vscroll = 1;
14554 if (win->
content_w > win->
w) need_hscroll = 1;
14555 if (need_vscroll && win->
content_w > (win->
w - scrollbar_size)) need_hscroll = 1;
14556 if (need_hscroll && win->
content_h > (body_h - scrollbar_size)) need_vscroll = 1;
14557 if (need_vscroll || need_hscroll) {
14559 float corner_x = win->
x + win->
w - scrollbar_size;
14560 float corner_y = win->
y + win->
h - scrollbar_size;
14561 in_resize_area = just_pressed &&
_point_in_rect(mx, my, corner_x, corner_y, scrollbar_size, scrollbar_size);
14563 in_resize_area = just_pressed &&
_point_in_rect(mx, my, rx, ry, grip, grip);
14566 in_resize_area = just_pressed &&
_point_in_rect(mx, my, rx, ry, grip, grip);
14568 if (in_resize_area) {
14580 float tbx, tby, tbw, tbhh;
14617 float content_x = win->
x - win->
scroll_x;
14619 int widget_took_press = 0;
14629 float ax = content_x + wgt->
x;
14630 float ay = content_y + wgt->
y;
14651 if (just_pressed || just_right_pressed) {
14653 }
else if (event.type == ALLEGRO_EVENT_MOUSE_AXES && !ctx->
mouse_b1 &&
14654 (event.mouse.dx != 0 || event.mouse.dy != 0)) {
14678 int row_in_view = (int)((my - ay) / ih);
14687 if (just_pressed) {
14741 float ta_view_h = wgt->
h - text_pad * 2;
14743 int ta_need_sb = (ta_content_h > ta_view_h) ? 1 : 0;
14745 if (ta_need_sb && mx > ax + wgt->
w - ta_sb_w) {
14747 float ta_text_w = wgt->
w - ta_sb_w;
14750 my, ay + text_pad, ta_view_h,
14751 ta_view_h, ta_content_h,
14754 goto textarea_click_done;
14758 ax, ay, wgt->
w, wgt->
h,
14764 textarea_click_done:;
14787 float view_h = wgt->
h - lpad;
14789 float tw2 = wrap_w - sb_sz;
14791 ax + lpad, ay + lpad / 2.0f, click_lb->
scroll_y, mx, my);
14798 if (strchr(click_lb->
text,
'\n')) {
14803 float click_x = mx - text_ox;
14807 if (char_pos >= 0) {
14809 click_lb->
sel_end = char_pos;
14840 if (click_yd && yf && click_yd->
text) {
14842 float cl_content_w = 0.0f, cl_pane_w = wgt->
w, cl_rows_h;
14843 int cl_need_hsb = 0, cl_visible = 1;
14849 on_bar = (cl_need_hsb && my > ay + cl_rows_h) ||
14870 if (target < 0) target = 0;
14872 if (target > max_off) target = max_off;
14884 float lfh = lf ? (float)al_get_font_line_height(lf) : 16.0f;
14886 float lb_content_w = 0.0f, lb_pane_w = wgt->
w;
14887 int lb_need_hsb = 0;
14888 int lb_visible = 0;
14892 int lb_need_sb = ((int)lbd->
nb_items > lb_visible) ? 1 : 0;
14895 int lb_max_off = (int)lbd->
nb_items - lb_visible;
14896 if (lb_max_off < 0) lb_max_off = 0;
14900 if (lb_need_hsb && my > ay + lb_rows_h) {
14906 }
else if (lb_need_sb && mx > ax + wgt->
w - lb_sb_w) {
14911 int clicked_idx = lbd->
scroll_offset + (int)((my - ay) / lih);
14912 if (clicked_idx >= 0 && (
size_t)clicked_idx < lbd->nb_items) {
14933 float hfh = hf ? (float)al_get_font_line_height(hf) : 16.0f;
14934 float row_h = hfh + 2.0f;
14936 int nb_rows = (int)((hd->
len + (
size_t)bpr - 1) / (
size_t)bpr);
14940 if (hv_visible < 1) hv_visible = 1;
14941 hv_need_sb = (nb_rows > hv_visible) ? 1 : 0;
14943 if (hv_need_sb && mx > ax + wgt->
w - hv_sb_w) {
14953 float hx0 = ax + pad + (hf ? (float)al_get_text_width(hf,
"00000000 ") : 0.0f);
14954 float cw = hf ? (float)al_get_text_width(hf,
"00 ") : 1.0f;
14955 if (
row >= 0 && cw > 0.0f) {
14956 int col = (int)((mx - hx0) / cw);
14958 if (col < 0) col = 0;
14959 if (col >= bpr) col = bpr - 1;
14960 at = (size_t)
row * (
size_t)bpr + (size_t)col;
14969 float yv_content_w = 0.0f, yv_pane_w = wgt->
w, yv_rows_h;
14970 int yv_need_hsb = 0, yv_visible = 1, yv_need_sb;
14976 if (yv_need_hsb && my > ay + yv_rows_h) {
14982 }
else if (yv_need_sb && mx > ax + wgt->
w - yv_sb_w) {
14990 float gfh = gf ? (float)al_get_font_line_height(gf) : 16.0f;
14992 float header_h = row_h;
14993 float data_h = wgt->
h - header_h;
14994 int dg_visible = (int)(data_h / row_h);
14997 if (dg_visible < 1) dg_visible = 1;
14998 float dg_content_w = 0.0f, dg_pane_w = 0.0f, dg_hsb_h;
14999 int dg_need_hsb = 0;
15000 dg_need_sb = ((int)gd->
nb_rows > dg_visible) ? 1 : 0;
15004 if (dg_need_hsb && my > ay + wgt->
h - dg_hsb_h && mx < ax + dg_pane_w) {
15009 }
else if (dg_need_sb && mx > ax + wgt->
w - dg_sb_w && my >= ay + header_h) {
15012 }
else if (my < ay + header_h) {
15016 int hit, resize_col;
15018 if (resize_col >= 0) {
15023 }
else if (hit >= 0) {
15028 int clicked = gd->
scroll_offset + (int)((my - (ay + header_h)) / row_h);
15029 if (clicked >= 0 && (
size_t)clicked < gd->nb_rows) {
15033 int ctrl = 0, shift = 0;
15034 if (al_is_keyboard_installed()) {
15035 ALLEGRO_KEYBOARD_STATE kb;
15036 al_get_keyboard_state(&kb);
15037 ctrl = al_key_down(&kb, ALLEGRO_KEY_LCTRL) || al_key_down(&kb, ALLEGRO_KEY_RCTRL);
15038 shift = al_key_down(&kb, ALLEGRO_KEY_LSHIFT) || al_key_down(&kb, ALLEGRO_KEY_RSHIFT);
15047 for (rr = lo; rr <= hi; rr++) gd->
row_sel[rr] = 1;
15066 float rfh = rf ? (float)al_get_font_line_height(rf) : 16.0f;
15068 int rl_visible = (int)(wgt->
h / rih);
15069 int rl_need_sb = ((int)rld->
nb_items > rl_visible) ? 1 : 0;
15072 int rl_max_off = (int)rld->
nb_items - rl_visible;
15073 if (rl_max_off < 0) rl_max_off = 0;
15077 if (rl_need_sb && mx > ax + wgt->
w - rl_sb_w) {
15082 int clicked_idx = rld->
scroll_offset + (int)((my - ay) / rih);
15083 if (clicked_idx >= 0 && (
size_t)clicked_idx < rld->nb_items) {
15098 float mview_h = wgt->
h - mpad * 2.0f;
15099 int mneed_bar = mvd->
content_h > mview_h;
15114 mx, my, url,
sizeof(url)))
15149 float gfh = gf ? (float)al_get_font_line_height(gf) : 16.0f;
15151 float header_h = row_h;
15152 if (my >= ay + header_h) {
15153 int clicked = gdc->
scroll_offset + (int)((my - (ay + header_h)) / row_h);
15154 if (clicked >= 0 && (
size_t)clicked < gdc->nb_rows) {
15204 int nx = 0, ny = 0;
15205 int have_target = 0;
15207 int cx = 0, cy = 0;
15208 if (al_get_mouse_cursor_position(&cx, &cy)) {
15214 if (!have_target) {
15218 int dx = (int)(mx - win->
drag_ox);
15219 int dy = (int)(my - win->
drag_oy);
15220 if (dx != 0 || dy != 0) {
15221 int wx = 0, wy = 0;
15222 al_get_window_position(win->
native, &wx, &wy);
15231 al_set_window_position(win->
native, nx, ny);
15247 int wx = 0, wy = 0;
15248 al_get_window_position(win->
native, &wx, &wy);
15259 float new_w = (mx - win->
x) + win->
drag_ox;
15260 float new_h = (my - win->
y) + win->
drag_oy;
15261 if (new_w < win->min_w) new_w = win->
min_w;
15262 if (new_h < win->min_h) new_h = win->
min_h;
15267 int nw = (int)(new_w + 0.5f);
15268 int nh = (int)(new_h + 0.5f);
15269 if (nw != (
int)(win->
w + 0.5f) || nh != (
int)(win->
h + 0.5f)) {
15270 al_resize_display(win->
native, nw, nh);
15294 int need_vscroll = 0, need_hscroll = 0;
15296 if (win->
content_h > body_h) need_vscroll = 1;
15297 if (win->
content_w > win->
w) need_hscroll = 1;
15298 if (need_vscroll && win->
content_w > (win->
w - scrollbar_size)) need_hscroll = 1;
15299 if (need_hscroll && win->
content_h > (body_h - scrollbar_size)) need_vscroll = 1;
15300 float content_area_w = win->
w - (need_vscroll ? scrollbar_size : 0);
15301 float content_area_h = body_h - (need_hscroll ? scrollbar_size : 0);
15304 float sb_y = body_y;
15305 float sb_h = content_area_h;
15310 float sb_x = win->
x;
15311 float sb_w = content_area_w;
15321 if (just_pressed) {
15331 if (ctx->
mouse_b1 && event.type == ALLEGRO_EVENT_MOUSE_AXES) {
15337 float content_x = win->
x - win->
scroll_x;
15341 if (!wgt)
continue;
15356 if (yf && drag_yd->
text) {
15357 float yax = content_x + wgt->
x;
15358 float yay = content_y + wgt->
y;
15368 float lax = content_x + wgt->
x;
15369 float lay = content_y + wgt->
y;
15375 float view_h = wgt->
h - lpad;
15377 float tw2 = wrap_w - sb_sz;
15379 lax + lpad, lay + lpad / 2.0f, drag_lb->
scroll_y, mx, my);
15386 if (strchr(drag_lb->
text,
'\n')) {
15391 float click_x = mx - text_ox;
15395 if (char_pos >= 0) {
15404 if (tf && drag_td) {
15405 float ta_ax = content_x + wgt->
x;
15406 float ta_ay = content_y + wgt->
y;
15409 ta_ax, ta_ay, wgt->
w, wgt->
h,
15422 if (just_released) {
15430 int pending_click_id = -1;
15433 int pending_toggle_id = -1;
15440 if (!wgt)
continue;
15444 float content_x = win->
x - win->
scroll_x;
15446 float ax = content_x + wgt->
x;
15447 float ay = content_y + wgt->
y;
15454 if (bd->
on_click && !pending_click) {
15455 pending_click = bd;
15456 pending_click_id = wgt->
id;
15462 float content_x = win->
x - win->
scroll_x;
15464 if (
_point_in_rect(mx, my, content_x + wgt->
x, content_y + wgt->
y, wgt->
w, wgt->
h)) {
15467 if (ckd->
on_toggle && !pending_toggle) {
15468 pending_toggle = ckd;
15469 pending_toggle_id = wgt->
id;
15486 float up_x = win->
x - win->
scroll_x + wgt->
x;
15494 if (pending_click && pending_click->
on_click)
15496 if (pending_toggle && pending_toggle->
on_toggle)
15509 if (!event_consumed && event.type == ALLEGRO_EVENT_KEY_CHAR &&
15511 int kc =
event.keyboard.keycode;
15517 if (kc == ALLEGRO_KEY_UP) {
15519 event_consumed = 1;
15520 }
else if (kc == ALLEGRO_KEY_DOWN) {
15522 event_consumed = 1;
15523 }
else if (kc == ALLEGRO_KEY_HOME) {
15525 event_consumed = 1;
15526 }
else if (kc == ALLEGRO_KEY_END) {
15528 event_consumed = 1;
15529 }
else if (kc == ALLEGRO_KEY_ENTER || kc == ALLEGRO_KEY_PAD_ENTER) {
15536 event_consumed = 1;
15537 }
else if (kc == ALLEGRO_KEY_ESCAPE) {
15540 event_consumed = 1;
15549 if (kc == ALLEGRO_KEY_UP) {
15551 event_consumed = 1;
15552 }
else if (kc == ALLEGRO_KEY_DOWN) {
15554 event_consumed = 1;
15555 }
else if (kc == ALLEGRO_KEY_HOME) {
15557 event_consumed = 1;
15558 }
else if (kc == ALLEGRO_KEY_END) {
15560 event_consumed = 1;
15561 }
else if (kc == ALLEGRO_KEY_ENTER || kc == ALLEGRO_KEY_PAD_ENTER) {
15568 event_consumed = 1;
15569 }
else if (kc == ALLEGRO_KEY_ESCAPE) {
15572 event_consumed = 1;
15578 if (!event_consumed && event.type == ALLEGRO_EVENT_KEY_CHAR && event.keyboard.keycode == ALLEGRO_KEY_TAB) {
15579 int ctrl = (
event.keyboard.modifiers & ALLEGRO_KEYMOD_CTRL) ? 1 : 0;
15580 int shift = (
event.keyboard.modifiers & ALLEGRO_KEYMOD_SHIFT) ? 1 : 0;
15583 int is_ctrl_tab_in_textarea = 0;
15587 is_ctrl_tab_in_textarea = 1;
15596 is_ctrl_tab_in_textarea = 1;
15599 if (!is_ctrl_tab_in_textarea) {
15620 int focusable_ids[512];
15621 int nfocusable = 0;
15625 focusable_ids[nfocusable++] = w->
id;
15628 if (nfocusable > 0) {
15631 for (
int i = 0; i < nfocusable; i++) {
15639 next_idx = (cur_idx <= 0) ? nfocusable - 1 : cur_idx - 1;
15641 next_idx = (cur_idx < 0 || cur_idx >= nfocusable - 1) ? 0 : cur_idx + 1;
15646 event_consumed = 1;
15651 if (!event_consumed && event.type == ALLEGRO_EVENT_KEY_CHAR && ctx->
focused_widget_id != -1) {
15661 event_consumed = 1;
15663 event_consumed = 1;
15669 if (event.keyboard.modifiers & ALLEGRO_KEYMOD_SHIFT)
15677 if (!event_consumed && event.type == ALLEGRO_EVENT_KEY_CHAR && ctx->
focused_widget_id != -1) {
15681 float hfh = hf ? (float)al_get_font_line_height(hf) : 16.0f;
15684 event_consumed = 1;
15689 if (!event_consumed && event.type == ALLEGRO_EVENT_KEY_CHAR && ctx->
focused_widget_id >= 0) {
15692 int kc =
event.keyboard.keycode;
15697 if (kc == ALLEGRO_KEY_ENTER || kc == ALLEGRO_KEY_PAD_ENTER || kc == ALLEGRO_KEY_SPACE) {
15701 int forward = (kc == ALLEGRO_KEY_RIGHT || kc == ALLEGRO_KEY_DOWN) ? 1 : 0;
15705 event_consumed = 1;
15712 double new_val = sd->
value;
15716 if (kc == ALLEGRO_KEY_RIGHT) {
15719 }
else if (kc == ALLEGRO_KEY_LEFT) {
15724 if (kc == ALLEGRO_KEY_UP) {
15727 }
else if (kc == ALLEGRO_KEY_DOWN) {
15732 if (kc == ALLEGRO_KEY_HOME) {
15735 }
else if (kc == ALLEGRO_KEY_END) {
15741 if (sd->
step > 0.0)
15745 if (new_val != sd->
value) {
15746 sd->
value = new_val;
15749 event_consumed = 1;
15761 for (
size_t i = 0; i < ld->
nb_items; i++) {
15768 int new_sel = cur_sel;
15769 if (kc == ALLEGRO_KEY_UP && cur_sel > 0) {
15770 new_sel = cur_sel - 1;
15772 }
else if (kc == ALLEGRO_KEY_DOWN && cur_sel < (
int)ld->
nb_items - 1) {
15773 new_sel = cur_sel + 1;
15775 }
else if (kc == ALLEGRO_KEY_DOWN && cur_sel < 0) {
15778 }
else if (kc == ALLEGRO_KEY_HOME) {
15781 }
else if (kc == ALLEGRO_KEY_END) {
15792 float lfh = lf ? (float)al_get_font_line_height(lf) : 16.0f;
15795 if (new_sel < ld->scroll_offset) ld->
scroll_offset = new_sel;
15797 event_consumed = 1;
15808 float mview_h = fw->
h - mpad * 2.0f;
15810 float page = mview_h >
line * 2.0f ? mview_h -
line : mview_h;
15813 if (most < 0.0f) most = 0.0f;
15814 if (kc == ALLEGRO_KEY_UP)
15816 else if (kc == ALLEGRO_KEY_DOWN)
15818 else if (kc == ALLEGRO_KEY_PGUP)
15820 else if (kc == ALLEGRO_KEY_PGDN)
15822 else if (kc == ALLEGRO_KEY_HOME)
15824 else if (kc == ALLEGRO_KEY_END)
15831 event_consumed = 1;
15841 float gfh = gf ? (float)al_get_font_line_height(gf) : 16.0f;
15843 int visible = (int)((fw->
h - row_h) / row_h);
15850 if (kc == ALLEGRO_KEY_UP) {
15851 new_sel = (cur > 0) ? cur - 1 : 0;
15853 }
else if (kc == ALLEGRO_KEY_DOWN) {
15854 new_sel = (cur < 0) ? 0 : (cur <
last ? cur + 1 :
last);
15856 }
else if (kc == ALLEGRO_KEY_PGUP) {
15857 new_sel = (cur < 0) ? 0 : cur -
visible;
15858 if (new_sel < 0) new_sel = 0;
15860 }
else if (kc == ALLEGRO_KEY_PGDN) {
15861 new_sel = (cur < 0) ? 0 : cur +
visible;
15862 if (new_sel >
last) new_sel =
last;
15864 }
else if (kc == ALLEGRO_KEY_HOME) {
15867 }
else if (kc == ALLEGRO_KEY_END) {
15873 int shift = (
event.keyboard.modifiers & ALLEGRO_KEYMOD_SHIFT) ? 1 : 0;
15880 int lo = anchor < new_sel ? anchor : new_sel;
15881 int hi = anchor < new_sel ? new_sel : anchor;
15883 for (rr = lo; rr <= hi; rr++) gd->
row_sel[rr] = 1;
15892 if (new_sel < gd->scroll_offset) gd->
scroll_offset = new_sel;
15894 if (new_sel != cur) {
15898 event_consumed = 1;
15899 }
else if (kc == ALLEGRO_KEY_LEFT || kc == ALLEGRO_KEY_RIGHT) {
15900 float content_w = 0.0f, pane_w = 0.0f;
15904 float step = pane_w * 0.25f;
15905 float max_scroll = content_w - pane_w;
15906 if (step < row_h) step = row_h;
15907 if (max_scroll < 0.0f) max_scroll = 0.0f;
15908 gd->
h_scroll += (kc == ALLEGRO_KEY_LEFT) ? -step : step;
15911 event_consumed = 1;
15921 int new_sel = cur_sel;
15923 if (kc == ALLEGRO_KEY_UP && cur_sel > 0) {
15924 new_sel = cur_sel - 1;
15926 }
else if (kc == ALLEGRO_KEY_DOWN && cur_sel < (
int)rd->
nb_items - 1) {
15927 new_sel = cur_sel + 1;
15929 }
else if (kc == ALLEGRO_KEY_DOWN && cur_sel < 0) {
15932 }
else if (kc == ALLEGRO_KEY_HOME) {
15935 }
else if (kc == ALLEGRO_KEY_END) {
15940 if (handled && new_sel != cur_sel) {
15945 float rfh = rf ? (float)al_get_font_line_height(rf) : 16.0f;
15948 if (new_sel < rd->scroll_offset) rd->
scroll_offset = new_sel;
15950 event_consumed = 1;
15960 int new_sel = cur_sel;
15962 if (kc == ALLEGRO_KEY_UP && cur_sel > 0) {
15963 new_sel = cur_sel - 1;
15965 }
else if (kc == ALLEGRO_KEY_DOWN && cur_sel < (
int)cd->
nb_items - 1) {
15966 new_sel = cur_sel + 1;
15968 }
else if (kc == ALLEGRO_KEY_DOWN && cur_sel < 0) {
15971 }
else if (kc == ALLEGRO_KEY_HOME) {
15974 }
else if (kc == ALLEGRO_KEY_END) {
15979 if (handled && new_sel != cur_sel) {
15982 event_consumed = 1;
15991 if (max_scroll > 0) {
15992 double step = max_scroll / 20.0;
15993 if (step <= 0) step = 1.0;
15997 if (kc == ALLEGRO_KEY_UP) {
16000 }
else if (kc == ALLEGRO_KEY_DOWN) {
16005 if (kc == ALLEGRO_KEY_LEFT) {
16008 }
else if (kc == ALLEGRO_KEY_RIGHT) {
16013 if (kc == ALLEGRO_KEY_HOME) {
16016 }
else if (kc == ALLEGRO_KEY_END) {
16017 new_pos = max_scroll;
16022 if (new_pos < 0) new_pos = 0;
16023 if (new_pos > max_scroll) new_pos = max_scroll;
16028 event_consumed = 1;
16035 if (kc == ALLEGRO_KEY_SPACE || kc == ALLEGRO_KEY_ENTER) {
16039 event_consumed = 1;
16046 if (!event_consumed && event.type == ALLEGRO_EVENT_KEY_DOWN &&
16047 (event.keyboard.modifiers & ALLEGRO_KEYMOD_CTRL) &&
16056 size_t tlen = strlen(lb->
text);
16057 if ((
size_t)slo > tlen) slo = (int)tlen;
16058 if ((
size_t)shi > tlen) shi = (int)tlen;
16059 int len = shi - slo;
16062 memcpy(clip, &lb->
text[slo], (
size_t)len);
16065 event_consumed = 1;
16072 if (!event_consumed && event.type == ALLEGRO_EVENT_KEY_DOWN &&
16073 (event.keyboard.modifiers & ALLEGRO_KEYMOD_CTRL) &&
16075 (event.keyboard.keycode == ALLEGRO_KEY_C || event.keyboard.keycode == ALLEGRO_KEY_A)) {
16076 if (event.keyboard.keycode == ALLEGRO_KEY_A) {
16079 event_consumed = 1;
16085 event_consumed = 1;
16098 if (event.type == ALLEGRO_EVENT_KEY_DOWN && !event_consumed) {
16099 int kc =
event.keyboard.keycode;
16103 for (
LIST_NODE* wnode = ctx->
windows->
end; wnode && !event_consumed; wnode = wnode->prev) {
16124 if (!focus_match) {
16132 if (!focus_match) {
16145 event_consumed = 1;
16148 if (event_consumed) {
16159 if (!event_consumed) {
16160 int widget_focused = 0;
16167 if (ftd && (ftd->
multiline || kc != ALLEGRO_KEY_ENTER)) {
16168 widget_focused = 1;
16171 widget_focused = 1;
16176 widget_focused = 1;
16180 if (!widget_focused) {
16183 for (
LIST_NODE* wnode = ctx->
windows->
end; wnode && !event_consumed; wnode = wnode->prev) {
16211 event_consumed = 1;
16215 if (event_consumed) {
16228 if (event.type == ALLEGRO_EVENT_MOUSE_AXES && event.mouse.dz != 0) {
16229 int scroll_consumed = 0;
16238 if (cb_wgt && cb_wgt->
data) {
16244 scroll_consumed = 1;
16251 if (dm_wgt && dm_wgt->
data) {
16256 -event.mouse.dz, -1);
16257 scroll_consumed = 1;
16261 if (scroll_consumed)
return 1;
16269 float win_h = win->
h;
16272 float content_x = win->
x;
16273 float content_y = win->
y +
_win_tbh(win);
16279 float ax = content_x + wgt->
x - win->
scroll_x;
16280 float ay = content_y + wgt->
y - win->
scroll_y;
16287 scroll_consumed = 1;
16293 float lb_content_w = 0.0f, lb_pane_w = wgt->
w;
16294 int lb_need_hsb = 0, visible_count = 0;
16298 if (lb_need_hsb && event.mouse.dw != 0) {
16314 max_off = (int)ld->
nb_items - visible_count;
16315 if (max_off < 0) max_off = 0;
16318 scroll_consumed = 1;
16323 float hfh = hf ? (float)al_get_font_line_height(hf) : 16.0f;
16324 float row_h = hfh + 2.0f;
16326 int nb_rows = (int)((hd->
len + (
size_t)bpr - 1) / (
size_t)bpr);
16329 if (visible_count < 1) visible_count = 1;
16330 max_off = nb_rows - visible_count;
16331 if (max_off < 0) max_off = 0;
16335 scroll_consumed = 1;
16340 float sv_content_w = 0.0f, sv_pane_w = wgt->
w;
16341 int sv_need_hsb = 0, visible_count = 1;
16345 if (sv_need_hsb && event.mouse.dw != 0) {
16356 if (max_off < 0) max_off = 0;
16361 scroll_consumed = 1;
16366 float gfh = gf ? (float)al_get_font_line_height(gf) : 16.0f;
16368 float data_h = wgt->
h - row_h;
16369 int visible_count = (int)(data_h / row_h);
16371 if (visible_count < 1) visible_count = 1;
16372 max_off = (int)gd->
nb_rows - visible_count;
16373 if (max_off < 0) max_off = 0;
16379 if (al_is_keyboard_installed()) {
16380 ALLEGRO_KEYBOARD_STATE kb;
16381 al_get_keyboard_state(&kb);
16382 dg_shift = al_key_down(&kb, ALLEGRO_KEY_LSHIFT) || al_key_down(&kb, ALLEGRO_KEY_RSHIFT);
16385 gd->
h_scroll -= (float)event.mouse.dz * (row_h * 2.0f);
16393 scroll_consumed = 1;
16400 float rfh = rf ? (float)al_get_font_line_height(rf) : 16.0f;
16402 int visible_count = (int)(wgt->
h / rih);
16403 int max_off = (int)rd->
nb_items - visible_count;
16404 if (max_off < 0) max_off = 0;
16406 scroll_consumed = 1;
16412 std->
scroll_y -= (int)((
float)event.mouse.dz * scroll_step);
16415 scroll_consumed = 1;
16421 double new_val = sd->
value + (double)event.mouse.dz * step;
16422 if (sd->
step > 0.0)
16426 if (new_val != sd->
value) {
16427 sd->
value = new_val;
16432 scroll_consumed = 1;
16435 scroll_consumed = 1;
16443 int max_off = (int)cbd->
nb_items - max_vis;
16444 if (max_off < 0) max_off = 0;
16446 scroll_consumed = 1;
16455 int max_off = (int)dmd->
nb_entries - max_vis;
16456 if (max_off < 0) max_off = 0;
16458 scroll_consumed = 1;
16465 float view_h = wgt->
h - pad * 2.0f;
16467 if (most < 0.0f) most = 0.0f;
16468 mvd->
scroll_y -= (float)event.mouse.dz * step;
16471 scroll_consumed = 1;
16477 sld->
scroll_y -= (float)event.mouse.dz * scroll_step;
16479 scroll_consumed = 1;
16487 if (scroll_consumed)
break;
16496 scroll_consumed = 1;
16501 win->
scroll_y -= (float)event.mouse.dz * scroll_step;
16503 scroll_consumed = 1;
16505 if (scroll_consumed) event_consumed = 1;
16511 if (!scroll_consumed && eff_w > 0 && eff_h > 0) {
16512 int need_v = 0, need_h = 0;
16516 if (need_v || need_h) {
16520 event_consumed = 1;
16530 if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN && event.mouse.button == 1) {
16532 double now = al_get_time();
16533 int dx =
event.mouse.x - ctx->
click_x;
16534 int dy =
event.mouse.y - ctx->
click_y;
16561 ctx->
click_x =
event.mouse.x;
16562 ctx->
click_y =
event.mouse.y;
16566 return event_consumed;
16577 float mx = (float)ctx->
mouse_x;
16578 float my = (float)ctx->
mouse_y;
16590 if (win->
native)
continue;
16612 int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
16615 FILE* f = fdopen(fd,
mode);
16621#define _gui_fopen_write(path, mode) fopen((path), (mode))
16626 unsigned char r, g, b, a;
16627 al_unmap_rgba(c, &r, &g, &b, &a);
16628 cJSON* arr = cJSON_CreateArray();
16629 cJSON_AddItemToArray(arr, cJSON_CreateNumber(r));
16630 cJSON_AddItemToArray(arr, cJSON_CreateNumber(g));
16631 cJSON_AddItemToArray(arr, cJSON_CreateNumber(b));
16632 cJSON_AddItemToArray(arr, cJSON_CreateNumber(a));
16633 cJSON_AddItemToObject(parent, name, arr);
16637static ALLEGRO_COLOR
_json_get_color(cJSON* parent,
const char* name, ALLEGRO_COLOR fallback) {
16638 cJSON* arr = cJSON_GetObjectItemCaseSensitive(parent, name);
16639 if (!arr || !cJSON_IsArray(arr) || cJSON_GetArraySize(arr) < 4)
return fallback;
16640 int r = (int)cJSON_GetArrayItem(arr, 0)->valuedouble;
16641 int g = (int)cJSON_GetArrayItem(arr, 1)->valuedouble;
16642 int b = (int)cJSON_GetArrayItem(arr, 2)->valuedouble;
16643 int a = (int)cJSON_GetArrayItem(arr, 3)->valuedouble;
16644 return al_map_rgba((
unsigned char)r, (
unsigned char)g, (
unsigned char)b, (
unsigned char)a);
16649 cJSON* item = cJSON_GetObjectItemCaseSensitive(parent, name);
16650 if (!item || !cJSON_IsNumber(item))
return fallback;
16651 return (
float)item->valuedouble;
16656 cJSON* item = cJSON_GetObjectItemCaseSensitive(parent, name);
16657 if (!item || !cJSON_IsNumber(item))
return fallback;
16658 return (
int)item->valuedouble;
16671 cJSON* root = cJSON_CreateObject();
16672 if (!root)
return -1;
16675 cJSON* theme = cJSON_CreateObject();
16688 cJSON_AddNumberToObject(theme,
"corner_rx", t->
corner_rx);
16689 cJSON_AddNumberToObject(theme,
"corner_ry", t->
corner_ry);
16690 cJSON_AddItemToObject(root,
"theme", theme);
16693 cJSON* sty = cJSON_CreateObject();
16695 cJSON_AddNumberToObject(sty,
"titlebar_h", s->
titlebar_h);
16696 cJSON_AddNumberToObject(sty,
"min_win_w", s->
min_win_w);
16697 cJSON_AddNumberToObject(sty,
"min_win_h", s->
min_win_h);
16698 cJSON_AddNumberToObject(sty,
"title_padding", s->
title_padding);
16701 cJSON_AddNumberToObject(sty,
"tb_btn_size", s->
tb_btn_size);
16702 cJSON_AddNumberToObject(sty,
"tb_btn_spacing", s->
tb_btn_spacing);
16706 cJSON_AddNumberToObject(sty,
"scrollbar_size", s->
scrollbar_size);
16722 cJSON_AddNumberToObject(sty,
"grip_size", s->
grip_size);
16753 cJSON_AddNumberToObject(sty,
"shape_mode", s->
shape_mode);
16764 cJSON_AddNumberToObject(sty,
"label_padding", s->
label_padding);
16769 cJSON_AddNumberToObject(sty,
"scroll_step", s->
scroll_step);
16772 cJSON_AddItemToObject(root,
"style", sty);
16775 char* json_str = cJSON_Print(root);
16776 cJSON_Delete(root);
16777 if (!json_str)
return -1;
16781 cJSON_free(json_str);
16784 fprintf(fp,
"%s\n", json_str);
16786 cJSON_free(json_str);
16800 FILE* fp = fopen(filepath,
"r");
16801 if (!fp)
return -1;
16803 fseek(fp, 0, SEEK_END);
16804 long fsize = ftell(fp);
16805 fseek(fp, 0, SEEK_SET);
16806 if (fsize <= 0 || fsize > 1024 * 1024) {
16812 Malloc(buf,
char, (
size_t)fsize + 1);
16817 size_t nread = fread(buf, 1, (
size_t)fsize, fp);
16821 cJSON* root = cJSON_Parse(buf);
16823 if (!root)
return -1;
16826 cJSON* theme = cJSON_GetObjectItemCaseSensitive(root,
"theme");
16849 if (wgt) wgt->
theme = *t;
16855 cJSON* sty = cJSON_GetObjectItemCaseSensitive(root,
"style");
16937 cJSON_Delete(root);
16942#define _N_GUI_WIN_STATE_PERSIST_MASK (N_GUI_WIN_OPEN | N_GUI_WIN_MINIMISED | N_GUI_WIN_MAXIMISED)
16954 cJSON* root = cJSON_CreateObject();
16955 if (!root)
return -1;
16957 cJSON_AddNumberToObject(root,
"version", 1);
16963 cJSON_AddNumberToObject(root,
"display_w", ctx->
display_w);
16964 cJSON_AddNumberToObject(root,
"display_h", ctx->
display_h);
16965 cJSON* wins = cJSON_CreateArray();
16967 cJSON_Delete(root);
16973 if (!win)
continue;
16988 cJSON* wj = cJSON_CreateObject();
16994 int detached = (win->
native != NULL);
16995 float px = detached ? win->
saved_x : win->
x;
16996 float py = detached ? win->
saved_y : win->
y;
16997 float pw = detached ? win->
saved_w : win->
w;
16998 float ph = detached ? win->
saved_h : win->
h;
17005 al_get_window_position(win->
native, &npx, &npy);
17006 nw = (float)al_get_display_width(win->
native);
17007 nh = (float)al_get_display_height(win->
native);
17009 cJSON_AddStringToObject(wj,
"title", win->
title);
17010 cJSON_AddNumberToObject(wj,
"x", px);
17011 cJSON_AddNumberToObject(wj,
"y", py);
17012 cJSON_AddNumberToObject(wj,
"w", pw);
17013 cJSON_AddNumberToObject(wj,
"h", ph);
17015 cJSON_AddNumberToObject(wj,
"flags", pflags);
17017 cJSON_AddNumberToObject(wj,
"native", 1);
17018 cJSON_AddNumberToObject(wj,
"detach_flags", win->
detach_flags);
17019 if (nw > 0.0f && nh > 0.0f) {
17020 cJSON_AddNumberToObject(wj,
"native_w", nw);
17021 cJSON_AddNumberToObject(wj,
"native_h", nh);
17023 if (npx != INT_MIN && npy != INT_MIN) {
17024 cJSON_AddNumberToObject(wj,
"native_pos_x", npx);
17025 cJSON_AddNumberToObject(wj,
"native_pos_y", npy);
17028 cJSON_AddNumberToObject(wj,
"z_order", win->
z_order);
17029 cJSON_AddNumberToObject(wj,
"z_value", win->
z_value);
17030 cJSON_AddNumberToObject(wj,
"norm_x", win->
norm_x);
17031 cJSON_AddNumberToObject(wj,
"norm_y", win->
norm_y);
17032 cJSON_AddNumberToObject(wj,
"norm_w", win->
norm_w);
17033 cJSON_AddNumberToObject(wj,
"norm_h", win->
norm_h);
17034 cJSON_AddNumberToObject(wj,
"autofit_flags", win->
autofit_flags);
17035 cJSON_AddNumberToObject(wj,
"autofit_border", win->
autofit_border);
17036 cJSON_AddNumberToObject(wj,
"resize_policy", win->
resize_policy);
17041 cJSON* warr = NULL;
17049 if (!warr && !(warr = cJSON_CreateArray()))
17051 w2 = cJSON_CreateObject();
17054 cJSON_AddStringToObject(w2,
"key", wgt->
persist_key);
17056 cJSON_AddStringToObject(w2,
"kind",
"splitpane");
17066 cJSON_AddStringToObject(w2,
"kind",
"datagrid");
17067 cJSON_AddNumberToObject(w2,
"ncols", nc);
17068 jo = cJSON_AddArrayToObject(w2,
"order");
17069 jv = cJSON_AddArrayToObject(w2,
"visible");
17070 jw = cJSON_AddArrayToObject(w2,
"width");
17071 for (c = 0; c < nc; c++) {
17073 if (jo) cJSON_AddItemToArray(jo, cJSON_CreateNumber(phys >= 0 ? phys : c));
17078 cJSON_AddItemToArray(warr, w2);
17081 cJSON_AddItemToObject(wj,
"widgets", warr);
17083 cJSON_AddItemToArray(wins, wj);
17085 cJSON_AddItemToObject(root,
"windows", wins);
17087 char* json_str = cJSON_Print(root);
17088 cJSON_Delete(root);
17089 if (!json_str)
return -1;
17093 cJSON_free(json_str);
17096 fprintf(fp,
"%s\n", json_str);
17098 cJSON_free(json_str);
17112 FILE* fp = fopen(filepath,
"r");
17114 n_log(
LOG_DEBUG,
"n_gui_load_layout_json: %s not found (first run?)", filepath);
17118 fseek(fp, 0, SEEK_END);
17119 long fsize = ftell(fp);
17120 fseek(fp, 0, SEEK_SET);
17121 if (fsize <= 0 || fsize > 4 * 1024 * 1024) {
17127 Malloc(buf,
char, (
size_t)fsize + 1);
17132 size_t nread = fread(buf, 1, (
size_t)fsize, fp);
17136 cJSON* root = cJSON_Parse(buf);
17138 if (!root)
return -1;
17140 cJSON* wins = cJSON_GetObjectItemCaseSensitive(root,
"windows");
17141 if (!wins || !cJSON_IsArray(wins)) {
17142 cJSON_Delete(root);
17153 float sx = 1.0f, sy = 1.0f;
17159 int n_entries = cJSON_GetArraySize(wins);
17160 int* consumed = NULL;
17161 if (n_entries > 0) {
17162 Malloc(consumed,
int, (
size_t)n_entries);
17164 cJSON_Delete(root);
17167 memset(consumed, 0,
sizeof(
int) * (
size_t)n_entries);
17182 for (
int i = 0; i < n_entries; i++) {
17183 if (consumed[i])
continue;
17184 cJSON* wi = cJSON_GetArrayItem(wins, i);
17186 cJSON* state_i = cJSON_GetObjectItemCaseSensitive(wi,
"state");
17187 int is_open_i = state_i && cJSON_IsNumber(state_i) &&
17189 if (is_open_i)
continue;
17190 cJSON* ti = cJSON_GetObjectItemCaseSensitive(wi,
"title");
17191 if (!ti || !cJSON_IsString(ti) || !ti->valuestring)
continue;
17192 for (
int j = i + 1; j < n_entries; j++) {
17193 cJSON* wj = cJSON_GetArrayItem(wins, j);
17195 cJSON* state_j = cJSON_GetObjectItemCaseSensitive(wj,
"state");
17196 int is_open_j = state_j && cJSON_IsNumber(state_j) &&
17198 if (!is_open_j)
continue;
17199 cJSON* tj = cJSON_GetObjectItemCaseSensitive(wj,
"title");
17200 if (tj && cJSON_IsString(tj) && tj->valuestring &&
17201 strcmp(ti->valuestring, tj->valuestring) == 0) {
17210 if (!win)
continue;
17211 cJSON* match = NULL;
17212 int match_idx = -1;
17215 cJSON_ArrayForEach(wj, wins) {
17216 if (!consumed || consumed[idx] == 0) {
17217 cJSON* t = cJSON_GetObjectItemCaseSensitive(wj,
"title");
17218 if (t && cJSON_IsString(t) && t->valuestring &&
17227 if (!match)
continue;
17228 if (consumed) consumed[match_idx] = 1;
17252 if (win->
x < 0.0f || win->
x > ctx->
display_w) win->
x = 0.0f;
17253 if (win->
w < 20.0f) win->
w = 20.0f;
17257 if (win->
y < 0.0f || win->
y > ctx->
display_h) win->
y = 0.0f;
17258 if (win->
h < 20.0f) win->
h = 20.0f;
17310 if (n_entries > 0) {
17312 for (
int i = 0; i < n_entries; i++)
17313 if (consumed && !consumed[i]) npend++;
17318 for (
int i = 0; i < n_entries && k < npend; i++) {
17319 if (consumed && consumed[i])
continue;
17320 cJSON* wi = cJSON_GetArrayItem(wins, i);
17321 cJSON* t = wi ? cJSON_GetObjectItemCaseSensitive(wi,
"title") : NULL;
17322 if (!t || !cJSON_IsString(t) || !t->valuestring || !t->valuestring[0])
17333 if (live)
continue;
17359 cJSON_ArrayForEach(wi, wins) {
17360 cJSON* warr = cJSON_GetObjectItemCaseSensitive(wi,
"widgets");
17361 if (warr && cJSON_IsArray(warr))
17362 nw += cJSON_GetArraySize(warr);
17369 cJSON_ArrayForEach(wi2, wins) {
17370 cJSON* t = cJSON_GetObjectItemCaseSensitive(wi2,
"title");
17371 cJSON* warr = cJSON_GetObjectItemCaseSensitive(wi2,
"widgets");
17373 const char* title = (t && cJSON_IsString(t) && t->valuestring) ? t->valuestring :
"";
17374 if (!warr || !cJSON_IsArray(warr) || !title[0])
17376 cJSON_ArrayForEach(we, warr) {
17377 cJSON* jk = cJSON_GetObjectItemCaseSensitive(we,
"key");
17378 cJSON* jkind = cJSON_GetObjectItemCaseSensitive(we,
"kind");
17383 if (!jk || !cJSON_IsString(jk) || !jk->valuestring || !jk->valuestring[0])
17385 if (!jkind || !cJSON_IsString(jkind) || !jkind->valuestring)
17387 kind = jkind->valuestring;
17389 memset(p, 0,
sizeof(*p));
17392 if (strcmp(kind,
"splitpane") == 0) {
17395 }
else if (strcmp(kind,
"datagrid") == 0) {
17396 cJSON* jo = cJSON_GetObjectItemCaseSensitive(we,
"order");
17397 cJSON* jv = cJSON_GetObjectItemCaseSensitive(we,
"visible");
17398 cJSON* jw = cJSON_GetObjectItemCaseSensitive(we,
"width");
17402 if (nc < 0) nc = 0;
17405 for (c = 0; c < nc; c++) {
17406 const cJSON* eo = (jo && cJSON_IsArray(jo)) ? cJSON_GetArrayItem(jo, c) : NULL;
17407 const cJSON* ev = (jv && cJSON_IsArray(jv)) ? cJSON_GetArrayItem(jv, c) : NULL;
17408 const cJSON* ew = (jw && cJSON_IsArray(jw)) ? cJSON_GetArrayItem(jw, c) : NULL;
17409 p->
order[c] = eo ? (int)eo->valuedouble : c;
17410 p->
visible[c] = (ev && ((int)ev->valuedouble)) ? 1 : (ev ? 0 : 1);
17411 p->
width[c] = ew ? (float)ew->valuedouble : 0.0f;
17425 cJSON_Delete(root);
17440 n_log(
LOG_ERR,
"n_gui_save_theme_json: cJSON not available (compile with -DHAVE_CJSON)");
17453 n_log(
LOG_ERR,
"n_gui_load_theme_json: cJSON not available (compile with -DHAVE_CJSON)");
17466 n_log(
LOG_ERR,
"n_gui_save_layout_json: cJSON not available (compile with -DHAVE_CJSON)");
17479 n_log(
LOG_ERR,
"n_gui_load_layout_json: cJSON not available (compile with -DHAVE_CJSON)");
17487 if (!panel)
return;
17489 for (
int i = 0; i < panel->
nb_tabs; i++) {
17495 if (clicked < 0)
return;
17501 if (!ctx)
return NULL;
17504 if (!panel)
return NULL;
17525 float bx = panel->
x + (float)idx * panel->
button_w;
17530 if (btn_id < 0)
return -1;
17538 if (!panel || tab_index < 0 || tab_index >= panel->
nb_tabs)
return;
17543 if (!panel || index < 0 || index >= panel->
nb_tabs)
return;
17544 for (
int i = 0; i < panel->
nb_tabs; i++) {
17577 if (!panel)
return;
17581 if (button_w > 0.0f) panel->
button_w = button_w;
17582 if (button_h > 0.0f) panel->
button_h = button_h;
17583 for (
int i = 0; i < panel->
nb_tabs; i++) {
17585 if (!wgt)
continue;
17586 wgt->
x = panel->
x + (float)i * panel->
button_w;
17596 if (!panel || !*panel)
return;
17606 if (!tree || !selected)
return;
17607 if (index < 0 || index >= tree->
nb_visible)
return;
17609 if (node_idx < 0 || node_idx >= tree->
nb_nodes)
return;
17616 if (!ctx)
return NULL;
17619 if (!tree)
return NULL;
17657 for (
int i = 0; i < tree->
nb_nodes; i++) {
17661 int pad = node->
depth * 2;
17662 const char* marker = NULL;
17665 if (pad >= (
int)
sizeof(indent) - 1) pad = (int)
sizeof(indent) - 2;
17666 memset(indent,
' ', (
size_t)pad);
17667 indent[pad] =
'\0';
17684 if (parent_index >= tree->
nb_nodes)
return -1;
17687 snprintf(node->
label,
sizeof(node->
label),
"%s", label);
17694 if (parent_index < 0) {
17714 if (node_index < 0 || node_index >= tree->
nb_nodes)
return;
17720 memset(removed, 0, (
size_t)tree->
nb_nodes);
17721 removed[node_index] = 1;
17725 for (
int i = 0; i < tree->
nb_nodes; i++) {
17726 if (removed[i])
continue;
17728 if (p >= 0 && removed[p]) {
17738 for (
int i = 0; i < tree->
nb_nodes; i++) {
17739 remap[i] = removed[i] ? -1 : new_count++;
17743 for (
int i = 0; i < tree->
nb_nodes; i++) {
17744 if (removed[i])
continue;
17745 int dst = remap[i];
17746 if (dst != i) tree->
nodes[dst] = tree->
nodes[i];
17755 for (
int i = 0; i < tree->
nb_nodes; i++) {
17758 for (
int i = 0; i < tree->
nb_nodes; i++) {
17767 if (!tree || !new_label)
return;
17768 if (node_index < 0 || node_index >= tree->
nb_nodes)
return;
17770 sizeof(tree->
nodes[node_index].
label),
"%s", new_label);
17775 if (!tree)
return -1;
17783 if (node_index < 0 || node_index >= tree->
nb_nodes)
return;
17804 if (!tree || !ptr)
return -1;
17805 for (
int i = 0; i < tree->
nb_nodes; i++) {
17837 if (!tree || node_index < 0 || node_index >= tree->
nb_nodes)
return;
17847 if (!tree || node_index < 0 || node_index >= tree->
nb_nodes)
return;
17859 if (!tree || node_index < 0 || node_index >= tree->
nb_nodes)
return;
17883 if (saved_node >= 0) {
17893 if (saved_scroll > 0) {
17899 if (!tree || !*tree)
return;
17927 if (!tree || !buf || bufsz == 0)
return -1;
17928 if (node_index < 0 || node_index >= tree->
nb_nodes)
return -1;
17932 chain[depth++] = i;
17937 for (i = depth - 1; i >= 0; i--) {
17939 const char* label = tree->
nodes[chain[i]].
label;
17940 size_t len = strlen(label);
17941 size_t need = len + (used > 0 ? 1u : 0u);
17942 if (used + need + 1 > bufsz)
return -1;
17944 memcpy(buf + used, label, len);
17954 if (!tree || !path)
return -1;
17955 for (i = 0; i < tree->
nb_nodes; i++) {
17957 if (strcmp(buf, path) == 0)
return i;
17966 if (!tree || !out)
return -1;
17967 memset(out, 0,
sizeof(*out));
17990 if (!tree || !state)
return;
18000 for (i = 0; i < tree->
nb_nodes; i++) {
18025 if (!state)
return;
18036#define _N_GUI_TREE_DRAG_THRESHOLD_PX 4.0f
18062 float* out_item_area_w,
18065 int* out_scroll_off) {
18066 if (!tree)
return 0;
18070 if (!win)
return 0;
18074 *out_x = win->
x + w->
x;
18085 int visible_count = (int)(w->
h / *out_item_h);
18086 int need_scrollbar = ((int)ld->
nb_items > visible_count) ? 1 : 0;
18088 *out_item_area_w = w->
w - sb_w;
18098 float lx, ly, lw, lh, iw, inset, ih;
18101 &iw, &inset, &ih, &scroll))
18105 if (mx < lx || mx > lx + iw || my < ly || my > ly + lh)
return 0;
18107 int row_in_view = (int)((my - ly) / ih);
18108 int actual_row = row_in_view + scroll;
18109 if (actual_row < 0 || actual_row >= tree->
nb_visible)
return 0;
18112 if (node_idx < 0 || node_idx >= tree->
nb_nodes)
return 0;
18119 float y_in_row = (my - ly) - (
float)row_in_view * ih;
18121 if (y_in_row < ih * 0.4f)
18123 else if (y_in_row > ih * 0.6f)
18128 *out_node_idx = node_idx;
18129 *out_drop_pos = pos;
18134 if (!tree || !tree->
ctx)
return;
18142 float mx = (float)ctx->
mouse_x;
18143 float my = (float)ctx->
mouse_y;
18150 if (b1 && !b1_prev) {
18181 if (!b1 && b1_prev) {
18196 if (!tree || !tree->
ctx)
return;
18199 float lx, ly, lw, lh, iw, inset, ih;
18202 &iw, &inset, &ih, &scroll))
18208 int row_in_view = -1;
18211 row_in_view =
row - scroll;
18215 if (row_in_view < 0)
return;
18217 float row_y = ly + (float)row_in_view * ih;
18226 float left = lx + inset;
18227 float right = lx + iw - inset;
18232 const float thickness = 2.0f;
18233 const float half = thickness * 0.5f;
18241 al_draw_rectangle(left + half,
row_y + half,
18243 colour, thickness);
18252 al_draw_line(left, line_y,
18254 colour, thickness);
18263 if (!table)
return;
18269 if (!table)
return;
18270 for (
int i = 0; i < table->
nb_rows; i++) {
18281 if (!table)
return;
18282 for (
int i = 0; i < table->
nb_rows; i++) {
18292 if (!table)
return;
18293 for (
int i = 0; i < table->
nb_rows; i++) {
18303 if (!table)
return;
18304 for (
int i = 0; i < table->
nb_rows; i++) {
18323 return strdup(t ? t :
"");
18351 for (
int i = 0; i < table->
nb_rows; i++) {
18362 for (
int p = 0; p < n; p++) {
18376 if (!table || table->
frac_cols < 2)
return;
18387 if (!table || table->
frac_cols != 3)
return;
18389 table->
col_frac[2] = 1.0f - ratio;
18400 if (!table)
return;
18420 float pad_x = table->
padding * sx;
18421 float pad_y = table->
padding * sy;
18424 float gap = 6.0f * sx;
18426 float total_w = win->
w - pad_x * 2.0f;
18427 if (total_w < 0.0f) total_w = 0.0f;
18429 float rh_inner = row_h - 4.0f * sy;
18430 if (rh_inner < 1.0f) rh_inner = 1.0f;
18431 float rw_inner = table->
row_height * sx - 4.0f * sx;
18432 if (rw_inner < 1.0f) rw_inner = 1.0f;
18433 float lbl_h = 18.0f * sy;
18434 if (lbl_h < 1.0f) lbl_h = 1.0f;
18435 float chk_w = rw_inner;
18436 float rem_w = rw_inner;
18437 float act_w = rw_inner;
18444 float trailing = (table->
show_enabled ? (chk_w + gap) : 0.0f) + gap + rem_w +
18446 float text_w = total_w - trailing;
18447 if (text_w < 0.0f) text_w = 0.0f;
18452 for (
int c = 0; c < 3; c++)
18453 table->
col_frac[c] = (c < text_cols) ? 1.0f / (float)text_cols : 0.0f;
18458 float min_frac = (text_w > 0.0f) ? (40.0f * sx) / text_w : 0.1f;
18459 if (min_frac * (
float)text_cols > 0.9f) min_frac = 0.9f / (float)text_cols;
18464 float r2 = (text_cols == 3) ? (table->
col_frac[0] + table->
col_frac[1]) : 1.0f;
18465 if (text_cols == 3 && r2 > 1.0f - min_frac) r2 = 1.0f - min_frac;
18466 if (text_cols >= 2) {
18467 float hi = (text_cols == 3) ? (r2 - min_frac) : (1.0f - min_frac);
18468 if (r1 < min_frac) r1 = min_frac;
18469 if (r1 > hi) r1 = hi;
18471 table->
col_frac[1] = ((text_cols == 3) ? r2 : 1.0f) - r1;
18472 if (text_cols == 3) table->
col_frac[2] = 1.0f - r2;
18477 float colx[3] = {pad_x, 0.0f, 0.0f};
18478 float colw[3] = {text_w, 0.0f, 0.0f};
18479 if (text_cols >= 2) {
18480 float hg = 5.0f * sx;
18481 float bx1 = pad_x + r1 * text_w;
18482 colw[0] = bx1 - hg - pad_x;
18483 colx[1] = bx1 + hg;
18484 if (text_cols == 2) {
18485 colw[1] = pad_x + text_w - colx[1];
18487 float bx2 = pad_x + r2 * text_w;
18488 colw[1] = bx2 - hg - colx[1];
18489 colx[2] = bx2 + hg;
18490 colw[2] = pad_x + text_w - colx[2];
18493 for (
int c = 0; c < text_cols; c++)
18494 if (colw[c] < 1.0f) colw[c] = 1.0f;
18495 float tx_end = pad_x + text_w;
18542 w->
x = tx_end + gap;
18551 float cy = top + hdr_h_outer;
18552 for (
int i = 0; i < table->
nb_rows; i++) {
18608 const int act_ids[3] = {
row->up_id,
row->down_id,
row->dup_id};
18609 for (
int a = 0; a < 3; a++) {
18639 float btn_w = 30.0f * sx;
18651 float tbl_h = cy - top;
18652 if (tbl_h < 1.0f) tbl_h = 1.0f;
18653 int show_a = (text_cols >= 2 && text_w > 1.0f) ? 1 : 0;
18654 int show_b = (text_cols == 3 && text_w > 1.0f) ? 1 : 0;
18667 min_frac, (text_cols == 3) ? (r2 - min_frac) : (1.0f - min_frac));
18683 r1 + min_frac, 1.0f - min_frac);
18690 if (!ctx)
return NULL;
18693 if (!table)
return NULL;
18694 memset(table, 0,
sizeof(*table));
18730 float rh_inner = row_height - 4.0f;
18731 if (rh_inner < 1.0f) rh_inner = 1.0f;
18732 float hdr_h_label = 18.0f;
18743 "+", padding, padding, 30.0f, rh_inner,
18753 const char* description,
18755 if (!table)
return -1;
18760 if (rh < 1.0f) rh = 1.0f;
18765 for (
int i = 0; i < table->
nb_rows; i++) {
18837 if (!table || row_index < 0 || row_index >= table->
nb_rows)
return;
18855 if (!table)
return;
18856 for (
int i = 0; i < table->
nb_rows; i++) {
18876 if (!table)
return;
18898 if (!table)
return;
18900 for (
int i = 0; i < table->
nb_rows; i++) {
18931 int n, pos = -1, target;
18933 if (!table || row_index < 0 || row_index >= table->
nb_rows)
return -1;
18934 if (!table->
rows[row_index].
active || direction == 0)
return -1;
18937 for (
int p = 0; p < n; p++) {
18938 if (order[p] == row_index) {
18943 if (pos < 0)
return -1;
18944 target = (direction < 0) ? pos - 1 : pos + 1;
18945 if (target < 0 || target >= n)
return -1;
18956 return order[target];
18976 int n, pos = -1, added;
18977 if (!table || row_index < 0 || row_index >= table->
nb_rows)
return -1;
18978 if (!table->
rows[row_index].
active)
return -1;
18981 for (
int p = 0; p < n; p++) {
18982 if (order[p] == row_index) {
18987 if (pos < 0)
return -1;
19000 int copy_slot = -1;
19001 for (
int p = 0; p < n2; p++) {
19002 int src = (p <= pos) ? p : p - 1;
19003 if (src >= n) src = n - 1;
19005 if (p == pos + 1) copy_slot = order2[p];
19015 if (!table)
return;
19020 for (
int i = 0; i < table->
nb_rows; i++) {
19029 if (!table)
return;
19043 if (!table || !*table)
return;
19045 FreeNoLog((*table)->value_placeholder);
19062 snprintf(label,
sizeof(label),
"%s %s", s->
folded ?
"+" :
"-", s->
title);
19081N_GUI_SECTIONLIST*
n_gui_sectionlist_create(
N_GUI_CTX* ctx,
int window_id,
float x,
float y0,
float width,
float header_h,
float gap,
void (*
on_toggle)(
int,
int,
void*),
void* user_data) {
19082 if (!ctx)
return NULL;
19085 if (!sl)
return NULL;
19086 memset(sl, 0,
sizeof(*sl));
19104 memset(s, 0,
sizeof(*s));
19105 strncpy(s->
title, title,
sizeof(s->
title) - 1);
19107 s->
folded = folded ? 1 : 0;
19111 snprintf(label,
sizeof(label),
"%s %s", s->
folded ?
"+" :
"-", s->
title);
19114 sl->
order[idx] = idx;
19121 if (!sl || section_index < 0 || section_index >= sl->
nb_sections)
return -1;
19131 if (!w || !hdr)
return -1;
19135 float dy = w->
y - content_top0;
19139 float bottom = dy + w->
h;
19146 if (!sl || section_index < 0 || section_index >= sl->
nb_sections)
return -1;
19149 if (s->
widget_ids[k] == widget_id)
return k;
19171 if (width > 0.0f) sl->
width = width;
19172 if (header_h > 0.0f) sl->
header_h = header_h;
19173 if (gap >= 0.0f) sl->
gap = gap;
19184 float cur = sl->
y0;
19186 for (
int pos = 0; pos < sl->
nb_sections; pos++) {
19187 int i = sl->
order[pos];
19201 float inset = (shown == 0) ? sl->
first_inset : 0.0f;
19202 hdr->
x = sl->
x + inset;
19204 hdr->
w = sl->
width - inset;
19218 float natural = 0.0f;
19223 if (bottom > natural) natural = bottom;
19237 if (!s->
folded) cur += natural + sl->
gap;
19248 memset(used, 0,
sizeof(used));
19249 for (
int k = 0; order && k < count && n < sl->
nb_sections; k++) {
19250 int idx = order[k];
19251 if (idx < 0 || idx >= sl->
nb_sections || used[idx])
continue;
19253 sl->
order[n++] = idx;
19256 for (
int idx = 0; idx < sl->
nb_sections; idx++) {
19257 if (!used[idx]) sl->
order[n++] = idx;
19263 if (!sl || position < 0 || position >= sl->
nb_sections)
return -1;
19264 return sl->
order[position];
19268 if (!sl || section_index < 0 || section_index >= sl->
nb_sections)
return;
19274 if (!sl || section_index < 0 || section_index >= sl->
nb_sections)
return 0;
19279 if (!sl || section_index < 0 || section_index >= sl->
nb_sections)
return;
19285 if (!sl || section_index < 0 || section_index >= sl->
nb_sections)
return 0;
19290 if (!sl)
return 0.0f;
19291 float cur = sl->
y0;
19305 if (!sl || !*sl)
return;
ALLEGRO_DISPLAY * display
void on_link_click(int widget_id, const char *link, void *user_data)
void on_scroll(int widget_id, double pos, void *user_data)
static void on_toggle(int widget_id, int checked, void *user_data)
the checkbox callback
static void on_change(const float rgba[4], void *user_data)
the picker's callback
static int row_y(int row)
The screen y of the middle of one row of the open list.
static void mouse(N_GUI_CTX *gui, int type, int x, int y)
Send one mouse event.
static void right(N_GUI_CTX *gui, float cx, float cy)
right press
static int on_mouse(int widget_id, const N_GUI_MOUSE_EVENT *ev, void *user_data)
the widget's mouse callback
static N_GUI_MOUSE_EVENT last
the last event the widget was told of, and how many
static void on_select(int widget_id, int row, void *user_data)
Record a row selection, to prove the keyboard path fires the same callback a click does.
static void draw(N_GUI_CTX *gui)
draw the whole context into a memory bitmap
static void visible(int widget_id, size_t first, size_t last, void *user_data)
the range to prepare
static void type(N_GUI_CTX *gui, const char *s)
Type a whole string into whatever has focus.
static void on_expand(int node, void *user_data)
the expand callback: a "folder" gets two subfolders, both themselves openable, except the one that st...
static const char * row(N_GUI_TREE *tree, int index)
the text of a visible row, "" past the end
an in-memory sink for n_http_response_write()
static int h(void *ctx, const N_ROUTE_MATCH *m)
a handler that does nothing (the test only routes)
static char pending[200000]
leftover bytes between responses on one connection
static N_HTTP_RESP * text(int status, const char *body)
text response
static N_HTTP_SERVER * start(N_HTTP_SERVER_CONFIG *cfg, char *port, int base)
start a server on the first free port from base
void line(BITMAP *bmp, int x1, int y1, int x2, int y2, int color)
draw a line
volatile char key[227]
TRUE while the key is held.
FONT * font
the default 8x8 font, valid after allegro_init()
#define FreeNoLog(__ptr)
Free Handler without log.
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
char title[128]
column header title
int expandable
1 if the node can be opened before it has children: its children are added by the expand callback
char title[128]
window title.
ALLEGRO_BITMAP * thumb_bitmap
optional bitmap for the thumb/handle, normal state (NULL = color theme)
float scroll_y
vertical scroll offset for overflowing text (pixels)
float scroll_y
vertical scroll offset for auto-scrollbar (pixels)
int visible
visibility flag
float cached_content_w
cached pixel width of the widest line, valid when width_valid
ALLEGRO_BITMAP * panel_bitmap
optional bitmap for the dropdown panel background (NULL = color theme)
int saved_flags
embedded feature flags saved by n_gui_window_detach (a detached window is forced frameless because th...
char * text
owned copy of the text, or NULL
size_t * col_order
display order: display_pos -> physical column index (sized cols_cap), or NULL when the display order ...
ALLEGRO_BITMAP * handle_hover_bitmap
optional bitmap for the handle on hover (NULL = fallback to handle_bitmap)
int window_id
owning window for coord math
float button_h
height of each tab button
int is_open
is dropdown currently open
int show_actions
1 to show the per-row move-up / move-down / duplicate buttons (default 0)
int content_window_ids[16]
content window IDs (-1 = none)
int cursor_want_shape
the cursor the application asked for with n_gui_set_cursor(), shown wherever the GUI has no cursor of...
int w
bounding box width in pixels
int native_drag_wx
native window x at the drag grab, the move is native_drag_wx plus the desktop cursor travel since the...
float gap
vertical gap between rows
int wheel_scrollbar
the scrollbar the wheel moves anywhere over the window when no widget under the pointer takes it,...
int open_combobox_id
id of the combobox whose dropdown is currently open, or -1
ALLEGRO_COLOR scrollbar_track_color
scrollbar track colour
int folded
1 = collapsed (members hidden), 0 = expanded
int max_visible
max visible items in dropdown
int selected_index
currently selected index (-1 = none)
void(* on_remove)(int, void *)
callback on row removal
ALLEGRO_BITMAP * minimize_active_bitmap
optional bitmap for minimize button active state
int sort_col
column index used for sorting, or -1
int scroll_offset
first visible row
size_t items_capacity
allocated capacity
ALLEGRO_COLOR grip_color
grip line colour
float dropdown_border_thickness
dropdown panel border thickness
char * text
text content (dynamically allocated, text_alloc bytes)
int nb_rows
total rows (including removed)
float slider_handle_edge_offset
handle circle offset from edge
int bytes_per_row
bytes shown per row
int selected_row
selected data row (the primary / last-clicked row), or -1
int parent_index
parent node index, or -1 for root
int shape
shape type: N_GUI_SHAPE_RECT or N_GUI_SHAPE_ROUNDED
float x
saved x (already display-scaled)
float content_h
total content height computed from widgets (internal)
float global_scrollbar_thumb_padding
global thumb inset from track edge
char label[128]
menu label (shown on the button)
size_t items_capacity
allocated capacity
N_GUI_TREE_NODE nodes[2048]
node storage
float y
pointer y from the widget's top edge; outside 0..h during a DRAG
float x
position x on screen
float scrollbar_size
scrollbar track width/height
float norm_y
normalized position y (0.0-1.0 fraction of reference display height)
void(* on_select)(int widget_id, int index, void *user_data)
callback on selection change (widget_id, selected_index, user_data)
float scrollbar_thumb_corner_r
thumb corner radius
void(* on_change)(int widget_id, float ratio, void *user_data)
callback fired while the divider is dragged (widget_id, ratio, user_data)
int nb_widgets
number of member widgets
int is_dynamic
is this entry dynamic (rebuilt via callback each time menu opens)
float title_padding
padding left of title text
float min_win_h
minimum window height (for resize)
float dropdown_arrow_half_w
horizontal half-extent of the arrow chevron
int nibble
which half of the cursor byte a typed hex digit lands in: 0 high, 1 low
int toggled
toggle state: 0 = off/unclicked, 1 = on/clicked (only used when toggle_mode=1)
char ** cells
row-major cell strings (nb_rows * nb_cols owned char*)
int lbl_enabled
label widget ID for "On" header
ALLEGRO_BITMAP * item_bg_bitmap
optional bitmap for per-item background, normal state (NULL = color theme)
int scroll_offset
scroll offset in items
float ref_display_h
reference display height at the time normalized values were last captured
float slider_track_corner_r
track corner radius
int y
bounding box y offset from draw origin
float titlebar_h
title bar height
int frac_cols
visible text column count col_frac was computed for; when it changes the fractions reset to equal wid...
ALLEGRO_BITMAP * handle_active_bitmap
optional bitmap for the handle while dragging (NULL = fallback to handle_bitmap)
void(* on_tab_change)(int, void *)
callback on tab switch (may be NULL)
int display_size_warned
non-zero once the fallback above has logged that it is in use
int selected_syntaxview_id
id of the syntax-view widget with the most recent text selection, or -1
int filled
1 once the expand callback has run for this node
float top_offset
unscaled y offset of the header row from the window top (default 0), to reserve space above the table...
float norm_y
normalized position y (fraction of parent window h, used for SCALE resize)
int dropmenu_max_visible
default max visible items for dropmenu panel
float norm_x
normalized position x (0.0-1.0 fraction of reference display width)
int sel_start
selection start byte offset into text, or -1 when nothing is selected
ALLEGRO_BITMAP * bg_bitmap
optional bitmap for the label background (NULL = no background)
float item_height
item height
N_GUI_THEME theme
color theme for this widget
float title_max_w_reserve
pixels reserved right of title for truncation
int multiselect
1 = multi-row selection enabled (Ctrl/Shift-click), 0 = single-select
double anim_until
deadline (al_get_time seconds) until which a transient animation is in progress (button key-press fla...
int double_click_radius
how far the pointer may move between the two presses and still count, in pixels.
size_t rows_cap
allocated row capacity (in rows)
int want_native
1 when the window should live in a native OS window: set by n_gui_window_detach and by a loaded layou...
char text[128]
item display text
int nb_tabs
number of tabs
int key_sources[8]
widget IDs that can trigger this focused key binding.
float checkbox_label_gap
gap between box and label text
int open_dropmenu_id
id of the dropdown menu whose panel is currently open, or -1
float global_scrollbar_thumb_corner_r
global thumb corner radius
N_GUI_THEME default_theme
default theme (applied to new widgets/windows)
int flags
bitmask of N_GUI_DROPMENU_* flags
float saved_y
embedded y saved by n_gui_window_detach, restored by n_gui_window_attach
int hovered
non-zero while the pointer is inside the rectangle above, and while a drag that began inside it is st...
float dpi_scale
DPI scale factor (1.0 = normal, 1.25 = 125%, 2.0 = HiDPI, etc.).
void * user_data
user data for callback
int scroll_from_wheel
set to 1 when scroll was changed by mouse wheel, cleared on key input
float tooltip_max_w
widest a tooltip bubble's text may get before it word-wraps, in pixels (0 = wrap only at the display ...
ALLEGRO_COLOR tooltip_fg
tooltip text color
int btn_add
button widget ID for "+" add row
ALLEGRO_BITMAP * bg_bitmap
optional bitmap for the window body background (NULL = color fill)
float scrollbar_thumb_padding
thumb inset from track edge
ALLEGRO_COLOR text_normal
text normal
int remove_id
button widget ID for the remove action
int pressed
which button is currently pressed (N_GUI_TB_BTN_*)
void * on_maximize_user_data
user data for on_maximize callback
int order[16]
display order: order[k] is the index of the section stacked k-th; indices themselves never change
int drop_position
N_GUI_DROP_BEFORE / INTO / AFTER.
int open_suggest_id
id of the textarea whose completion panel is currently open, or -1.
int combobox_max_visible
default max visible items for combobox dropdown
ALLEGRO_BITMAP * item_bg_bitmap
optional bitmap for per-item background, normal state (NULL = color theme)
float norm_h
normalized height (fraction of parent window h)
void * user_data
user data for callback
int sel_dragging
1 while a mouse drag is extending the selection, 0 otherwise
float scroll_y
how far down the content the view is, in pixels
void(* on_open)(int widget_id, void *user_data)
callback to rebuild dynamic entries each time the menu is opened.
size_t cursor
byte the cursor sits on (<= len)
size_t cols_cap
allocated column capacity
int mouse_b1_prev
previous mouse button 1 state
int listbox_id
listbox widget ID
float corner_rx
corner radius for rounded shapes
ALLEGRO_COLOR selection_color
text selection highlight colour (semi-transparent recommended)
int drag_hover_node
current hover node, or -1
ALLEGRO_BITMAP * bitmap
optional bitmap for the button (NULL = color theme)
int click_y
pointer y at that press
int flags
bitmask of N_GUI_COMBOBOX_* flags
ALLEGRO_MOUSE_CURSOR * cursor_custom
the custom cursor currently applied to the display, or NULL when a system cursor is (cursor_shape the...
float gui_offset_x
horizontal letterbox offset for virtual canvas
int h_scroll_dragging
1 while the user is dragging the horizontal scrollbar thumb (so the shared scrollbar-drag handler rou...
int pending_layout_count
number of valid entries in pending_layout
int state
saved minimised/maximised bits, applied on create
float tooltip_delay
inner padding
int key_focus_only
if 1, keycode fires only when the button itself or a source widget has focus.
int value_visible
draw the built-in value label next to/below the handle.
int ncols
column count (kind == DATAGRID)
N_GUI_KV_ROW rows[128]
row storage
char * tooltip
owned tooltip text shown after the pointer rests on the widget (NULL = none); heap-allocated with no ...
int type
widget type (N_GUI_TYPE_*)
int state
current state flags (N_GUI_STATE_*)
float scroll_step
pixels per mouse wheel notch for window auto-scroll
int widget_hidden[96]
1 = the caller keeps this member hidden whatever the fold state, and it does not count towards natura...
int h_scroll_dragging
1 while the user is dragging the horizontal scrollbar thumb, so the shared scrollbar-drag handler rou...
int multiline
0 = single line, 1 = multiline
int lines_valid
0 when cached_nb_lines / cached_headers_end are stale (rebuild on next use).
int key_id
textarea widget ID for the key
N_GUI_LISTITEM * suggest_items
what the provider last answered, allocated on the first ask
ALLEGRO_BITMAP * bitmap_hover
optional bitmap for hover state
char suggest_separators[8]
characters that end a word, so a field holding a list completes the one the cursor is in rather than ...
int kind
N_GUI_TYPE_SPLITPANE or N_GUI_TYPE_DATAGRID.
int button_ids[16]
toggle button widget IDs
int max_visible
max visible items
int suggest_scroll
first item the panel shows
float widget_dy[96]
each member's y offset from the section content top, captured at add time and settable with n_gui_sec...
float gui_bounds_w
total bounding box width of all windows (computed internally)
double key_press_until
absolute al_get_time() deadline until which the button is rendered in its pressed (N_GUI_STATE_ACTIVE...
float x
position x relative to parent window
float drag_press_x
mouse x at press time
float global_scrollbar_size
global scrollbar track width/height
int highlight_index
open-panel navigation cursor for the wheel and Up/Down keys (-1 = none).
void(* on_toggle)(int, int, void *)
callback(section_index, folded, user_data) on a header click (may be NULL)
float textarea_cursor_width
cursor width in pixels
char text[4096]
text to display
N_GUI_MD_STYLE style
colours and metrics, the caller's to change through n_gui_markdownview_style()
void * user_data
user data for callback
int held_modifier_keys
the modifier keys held down, one bit per key (left and right apart, so letting go of one Ctrl while t...
char title[128]
owning window title to match on
float tb_btn_size
titlebar button size (0 = auto: titlebar_h - 4)
float norm_h
normalized height (fraction of reference display height, used in SCALE mode)
char value_format[32]
printf-style format string applied to the numeric value when the built-in readout draws.
float min_win_w
minimum window width (for resize)
ALLEGRO_BITMAP * bg_bitmap
optional bitmap for the combobox background (NULL = color theme)
ALLEGRO_BITMAP * maximize_bitmap
optional bitmap for maximize button normal state (NULL = color theme)
void(* on_change)(int widget_id, double value, void *user_data)
callback on value change
float item_height
item height in pixels
int native_drag_wy
native window y at the drag grab (see native_drag_wx)
float drag_ox
drag offset x (internal)
void * user_data
user data for on_link
int dup_id
button widget ID for the duplicate action (row actions only)
int scroll_offset
first visible row
void(* on_click)(int widget_id, void *user_data)
callback on click (widget_id passed)
float row_height
unscaled row height in pixels
int expanded
1 if expanded
N_GUI_LISTITEM * items
dynamic array of items
char label[128]
display text
int mode
highlighting mode: N_GUI_SYNTAX_*
int drag_armed_node
pressed-but-not-yet-dragging
ALLEGRO_BITMAP * close_hover_bitmap
optional bitmap for close button hover state
int show_enabled
1 to show the enabled-checkbox column (default 1)
N_GUI_THEME theme
color theme for this window chrome
int display_size_set
non-zero once n_gui_set_display_size() has been called.
int sel_end
selection end byte offset (tracks the cursor while a drag is in progress)
int native_close_pending
1 when the native window must be released at the next safe point (an ALLEGRO_EVENT_DISPLAY_CLOSE arri...
int sort_dir
sort direction: 1 ascending, -1 descending
float saved_w
embedded width saved by n_gui_window_detach, restored by n_gui_window_attach
char title[64]
section title (header label minus the fold glyph)
float width
column width in pixels
int next_window_id
next window id to assign
float item_selection_inset
item highlight inset from left/right edges
int header_id
clickable header button widget id
float saved_h
embedded height saved by n_gui_window_detach, restored by n_gui_window_attach
ALLEGRO_COLOR border_normal
border normal
void(* on_click)(int widget_id, int entry_index, int tag, void *user_data)
callback when this entry is clicked (widget_id, entry_index, tag, user_data)
float h_scroll
horizontal scroll offset in pixels: how far the item text is scrolled to the left when the widest ite...
N_GUI_SECTION sections[16]
section storage
void(* on_content_draw)(int window_id, void *user_data)
optional callback invoked during n_gui_draw immediately after this window's own content is drawn,...
float init_win_w
parent window width at create time
int has_children
1 if node has children
N_GUI_THEME close_theme
theme for close button (defaults to red hover/active)
void * user_data
user data for callback
float value
progress fraction, clamped to 0.0 .
int scroll_offset
scroll offset
ALLEGRO_COLOR tooltip_bg
tooltip bubble background color
ALLEGRO_COLOR text_hover
text hover
float restore_x
saved x position before maximise (for restore)
float dropdown_arrow_half_h
vertical half-extent of the arrow chevron
int z_value
z-value for N_GUI_ZORDER_FIXED mode (lower = behind, higher = on top)
ALLEGRO_BITMAP * item_bg_bitmap
optional bitmap for per-item background, normal state (NULL = color theme)
char * expanded[512]
paths of the expanded nodes
int highlight_index
open-panel navigation cursor for the wheel and Up/Down keys (-1 = none).
double cursor_time
timestamp of last cursor activity (for blink reset)
int click_widget_id
widget the previous primary press landed on, for double click detection (-1 = none yet)
size_t entries_capacity
allocated capacity
int mouse_y
mouse state tracking
float grip_line_thickness
grip line thickness
int window_id
window holding the headers and members
float w
width; zero when no bar was painted
int has_default
non-zero once n_gui_slider_set_default() gave the slider a default, which a double click on it puts b...
int lbl_key
label widget ID for "Key" header
char key[128]
widget persist key to match on
N_GUI_CUSTOM_MOUSE on_mouse
mouse callback (NULL = the widget takes no mouse input)
size_t sel_end
selection end position (tracks cursor during selection)
int resize_policy
per-window resize policy: N_GUI_WIN_RESIZE_NONE, _MOVE, or _SCALE
N_GUI_THEME default_tb_close_theme
default theme for titlebar close button
size_t nb_items
number of items
char suggest_prefix[128]
the word the answers are for, so the provider is asked once per word rather than once per key
char persist_key[128]
optional stable key for persisting this widget's user-adjustable state (splitpane divider ratio,...
int native_drag_cx
desktop x of the mouse cursor when a native (N_GUI_DETACH_OWN_CHROME) title bar drag started.
void(* on_close)(int window_id, void *user_data)
callback on close button click (NULL = default: clear N_GUI_WIN_OPEN)
char title[128]
window title to match on
void * suggest_user_data
user data handed back to the provider
void * user_data
user data for callback
float first_inset
content-local left inset applied to the FIRST header only, so a button can sit before it on the same ...
int double_clicked_widget_id
widget the press just processed double clicked, or -1.
float h
height; zero when no bar was painted
int cached_nb_lines
cached line count (matches _text_line_count), valid when lines_valid
float padding
unscaled padding in pixels
unsigned char * data
owned copy of the bytes, or NULL
int detach_flags
options the window was detached with (N_GUI_DETACH_*), remembered so a close/open cycle and a restore...
n_gui_tree_on_drop_t on_drop
drag-reorder state (managed by n_gui_tree_tick)
void * mouse_user_data
opaque user pointer handed back to on_mouse (not owned by n_gui)
void(* on_select)(int, void *)
selection callback
int shape
shape type: N_GUI_SHAPE_RECT, N_GUI_SHAPE_ROUNDED, N_GUI_SHAPE_BITMAP
int z_order
z-order mode (N_GUI_ZORDER_NORMAL, _ALWAYS_ON_TOP, _ALWAYS_BEHIND, _FIXED)
int theme_derived
1 while the style is still the one derived from the widget's theme, so a palette change is followed; ...
float max_ratio
upper clamp applied to ratio
int tag
user-defined tag for the entry (e.g.
int mouse_b1
mouse button 1 state
float button_w
width of each tab button
float display_w
display/viewport width (set via n_gui_set_display_size)
double click_time
time of that press, from al_get_time()
int nb_sections
number of sections
N_GUI_LISTITEM * items
dynamic array of items
ALLEGRO_BITMAP * box_hover_bitmap
optional bitmap for the checkbox square on hover (NULL = fallback to box_bitmap/box_checked_bitmap)
float col_frac[3]
width fraction of each visible text column over the text area, summing to 1; user-adjusted by the col...
int h
bounding box height in pixels
float grip_size
grip area size
void * user_data
opaque user pointer handed back to the callback (not owned by n_gui)
float radio_label_gap
gap between circle and label text
N_GUI_CTX * ctx
GUI context.
ALLEGRO_DISPLAY * display
display pointer for clipboard operations (set via n_gui_set_display)
void * drop_user_data
user data for on_drop
float saved_x
embedded x saved by n_gui_window_detach, restored by n_gui_window_attach
float norm_w
normalized width (fraction of reference display width, used in SCALE mode)
float content_w
total content width computed from widgets (internal)
N_GUI_PENDING_WIDGET * pending_widgets
saved widget state for keyed widgets that did NOT exist when the layout was loaded; n_gui_widget_set_...
void * user_data
user data for this node
float norm_x
normalized position x (fraction of parent window w, used for SCALE resize)
ALLEGRO_COLOR global_scrollbar_thumb_color
global scrollbar thumb colour
float content_h
the height the whole document last measured at
int width_valid
0 when cached_content_w is stale.
int selected_label_id
id of the label widget with the most recent text selection, or -1
float radio_inner_offset
inner filled circle shrink from outer
float min_ratio
lower clamp applied to ratio
unsigned char * row_sel
per-row selection flags (1 = selected), sized rows_cap; NULL until needed
int selected_index
currently selected index (-1 = none)
void(* destroy)(void *user_data)
called with user_data when the widget is destroyed, for a caller that hands its state to the widget (...
N_GUI_MD_FONTS fonts
the faces, borrowed: the caller owns them and they must outlive the widget, the same rule every ALLEG...
ALLEGRO_BITMAP * track_bitmap
optional bitmap for the track/rail background (NULL = color theme)
int mouse_x
mouse state tracking
N_GUI_TB_BUTTONS tb_buttons
titlebar button state (minimize, maximize, close)
int order[64]
display position -> physical column
ALLEGRO_COLOR scrollbar_thumb_color
scrollbar thumb colour
int active_tab
currently active tab index
float native_h
last known native window height (see native_w)
float checkbox_max_size
maximum box size
double default_value
the value a double click puts back, when has_default is set
size_t nb_entries
number of entries
int visible_map[2048]
visible row to node index
int tooltip_anchor_x
pointer x when the tooltip was last armed (movement re-arms)
float checkbox_mark_thickness
checkmark line thickness
int nb_expanded
number of paths stored
unsigned char * row_has_color
per-row tint flags (1 = row_color[row] is painted), sized rows_cap; NULL until a row color is set
ALLEGRO_BITMAP * close_bitmap
optional bitmap for close button normal state (NULL = color theme)
int sel_start
selection start byte offset (-1 = no selection)
N_GUI_SUGGEST_FN suggest
completion provider, NULL when the field offers none
ALLEGRO_BITMAP * bitmap
bitmap to display (not owned, not freed)
ALLEGRO_BITMAP * fill_bitmap
optional bitmap for the filled portion of the track (NULL = color theme)
ALLEGRO_COLOR tooltip_border
tooltip bubble border color
void * on_close_user_data
user data for on_close callback
N_GUI_THEME default_tb_btn_theme
default theme for titlebar minimize/maximize buttons
int tooltip_widget_id
widget the pointer is resting on for tooltip purposes (-1 = none)
float header_height
unscaled column-header row height
float global_scroll_step
pixels per mouse wheel notch for global scroll
double key_step
increment applied by the arrow keys and the mouse wheel, when it should differ from step.
int click_x
pointer x at that press
float item_height
item height in dropdown
int hover_row
index of the row the mouse is currently over, or -1.
void * user_data
user data for callback
double scroll_pos
current scroll position
void(* on_change)(int widget_id, const char *text, void *user_data)
callback on text change
char * text
the source, owned, NUL-terminated; never NULL after creation
ALLEGRO_BITMAP * item_selected_bitmap
optional bitmap for per-item background, selected/highlighted (NULL = color theme)
void * user_data
user data for callback
float autofit_origin_y
original insertion point y for N_GUI_AUTOFIT_CENTER (set by n_gui_window_set_autofit)
N_GUI_DATAGRID_COL * cols
column definitions (physical/storage order; cells are indexed by these)
int scroll_offset
scroll offset in items
int native_drag_cy
desktop y of the mouse cursor at the drag grab (see native_drag_cx)
float h_scroll
horizontal scroll offset in pixels: the view does not wrap, so a line wider than the widget is reache...
size_t len
number of bytes
int selected
selection state (for listbox)
ALLEGRO_BITMAP * minimize_hover_bitmap
optional bitmap for minimize button hover state
int dirty
set when the text, the faces or the style changed under a measure
ALLEGRO_BITMAP * item_hover_bitmap
optional bitmap for the hovered entry background (NULL = color theme)
float virtual_h
virtual canvas height (0 = disabled / identity transform)
int drag_active
1 once past threshold
N_GUI_SB_TRACK sb_v
the vertical scrollbar this widget draws inside itself, if it draws one, so the pointer can be tested...
float y0
content-local y of the first header
N_GUI_CTX * ctx
GUI context.
int shape_mode
global widget shape override: N_GUI_SHAPE_ROUNDED forces a rounded GUI, N_GUI_SHAPE_RECT forces a squ...
int visible
1 = drawn, 0 = hidden (kept in storage, skipped in the header and rows)
float global_scroll_x
global horizontal scroll offset (when GUI exceeds display)
int cached_headers_end
cached first blank-line index (HTTP headers end), or INT_MAX; valid when lines_valid
int dz
wheel steps for WHEEL, positive away from the user; 0 otherwise
int native_pos_x
last known native window position on the desktop, applied when the native window is re-created.
float init_win_h
parent window height at create time
float checkbox_mark_margin
checkmark inset from box edge
ALLEGRO_BITMAP * track_bitmap
optional bitmap for the scrollbar track background (NULL = color theme)
ALLEGRO_DISPLAY * native
native OS window backing this pseudo-window, or NULL (the default) when the window is drawn as a pop-...
float checkbox_label_offset
horizontal offset from box edge to label text
int button
1 left, 2 right for DOWN; 1 for UP and DRAG; 0 otherwise
N_GUI_CUSTOM_DRAW draw
paint callback invoked during n_gui_draw (NULL = draw nothing)
void(* on_columns_changed)(int widget_id, void *user_data)
callback fired after the user resizes a column by dragging its header border (widget_id,...
ALLEGRO_BITMAP * maximize_active_bitmap
optional bitmap for maximize button active state
ALLEGRO_BITMAP * titlebar_bitmap
optional bitmap for the titlebar background (NULL = color fill)
int scroll_offset
scroll offset in dropdown
int h_scroll_dragging
1 while the horizontal scrollbar thumb is being dragged (so the shared scrollbar-drag handler routes ...
N_GUI_CTX * ctx
GUI context.
int mouse_b1_prev
previous frame's b1 state
void * data
widget-specific data (union via void pointer)
void(* on_link)(int widget_id, const char *url, void *user_data)
called when a link is clicked, or NULL
int suggest_open
the panel is up
double value
current value (always snapped to step)
N_GUI_DROPMENU_ENTRY * entries
dynamic array of entries
float x
left edge, in the coordinates the paint drew in
float drag_oy
drag offset y (internal)
float slider_track_border_thickness
track outline thickness
int pending_widgets_count
number of valid entries in pending_widgets
int nb_active
active row count
ALLEGRO_COLOR link_color_normal
link colour (normal)
float slider_handle_min_r
minimum handle circle radius
int scale_mode
scale mode: N_GUI_IMAGE_FIT, N_GUI_IMAGE_STRETCH, N_GUI_IMAGE_CENTER
float restore_h
saved height before maximise (for restore)
ALLEGRO_BITMAP * item_selected_bitmap
optional bitmap for per-item background, selected/highlighted (NULL = color theme)
ALLEGRO_BITMAP * bg_bitmap
optional bitmap for the radiolist background (NULL = color theme)
int truncate
how text too wide for the label is shortened: N_GUI_TRUNCATE_END (the default), N_GUI_TRUNCATE_START ...
float x
content-local x of every header and the layout origin
int show_value
1 to show the Value column (default 1)
ALLEGRO_BITMAP * box_bitmap
optional bitmap for the checkbox square, unchecked state (NULL = color theme)
float h_scroll
horizontal scroll offset in pixels
void * on_open_user_data
user data for on_open callback
float drag_press_y
mouse y at press time
int show_desc
1 to show the Description column (default 1)
float y
y origin of tab button row
float divider
divider thickness in pixels
float dropdown_arrow_reserve
horizontal space reserved for the arrow on the right
void * user_data
opaque pointer handed back to on_change
ALLEGRO_BITMAP * close_active_bitmap
optional bitmap for close button active state
float y
position y relative to parent window
int lbl_desc
label widget ID for "Description" header
int type
N_GUI_MOUSE_DOWN, _UP, _MOVE, _DRAG or _WHEEL.
const ALLEGRO_FONT * metrics_font
font cached_content_w was measured with (a text keeps its width only for as long as the font it was m...
int orientation
orientation: N_GUI_SLIDER_H or N_GUI_SLIDER_V
float global_scrollbar_border_thickness
global thumb border thickness
int state
state flags (N_GUI_WIN_*)
int visible[64]
per-physical-column visibility
int flags
feature flags (N_GUI_WIN_AUTO_SCROLLBAR, N_GUI_WIN_RESIZABLE, etc.)
int orientation
N_GUI_SPLIT_VERTICAL or N_GUI_SPLIT_HORIZONTAL.
void * user_data
user data for callback
int active
1 if active, 0 if removed
double max_val
maximum value
HASH_TABLE * widgets_by_id
hash table for fast widget lookup by id
float border_thickness
border thickness
float link_underline_thickness
link underline thickness
ALLEGRO_BITMAP * box_checked_bitmap
optional bitmap for the checkbox square, checked state (NULL = color theme)
int autofit_flags
bitmask of N_GUI_AUTOFIT_* flags (0 = no auto-fitting)
unsigned char consumed
1 once applied to a created window
float ratio
divider position as a fraction of the widget extent (0..1)
int drag_source_node
node being dragged, or -1
N_GUI_STYLE style
configurable style (sizes, colours, paddings)
ALLEGRO_FONT * font
font for the title bar
float col_resize_x0
cursor x at the start of a column-resize drag
int split_a
splitpane widget ID of the divider after the first text column, or -1
char * key_placeholder
owned hint shown in each key textarea, or NULL
void * expand_user_data
user data for on_expand
void * user_data
user data for callback
N_GUI_THEME btn_theme
theme for minimize and maximize buttons
ALLEGRO_COLOR text_active
text active
float ref_display_w
reference display width at the time normalized values were last captured
float restore_w
saved width before maximise (for restore)
int nb_nodes
number of nodes
size_t items_capacity
allocated capacity
int parent_window_id
parent window for tab buttons
double content_size
total content size
float autofit_origin_x
original insertion point x for N_GUI_AUTOFIT_CENTER (set by n_gui_window_set_autofit)
void * user_data
user data for callback
double step
step increment (0 is treated as 1).
float global_scroll_y
global vertical scroll offset (when GUI exceeds display)
size_t cap
bytes allocated (>= len; edits grow the buffer)
int scrollbar_drag_widget_id
id of the widget whose scrollbar is being dragged, or -1
ALLEGRO_BITMAP * maximize_hover_bitmap
optional bitmap for maximize button hover state
char caption[128]
what the title bar shows instead of the title when not empty, set by n_gui_window_set_caption(); neve...
float min_h
minimum height
float listbox_default_item_height
default item height for listbox
void * user_data
user data for callback
size_t nb_cols
number of columns
ALLEGRO_COLOR global_scrollbar_thumb_border_color
global scrollbar thumb border colour
float tb_btn_spacing
gap between titlebar buttons
ALLEGRO_COLOR border_active
border active
float scroll_x
horizontal scroll offset for single-line text (pixels)
float label_padding
horizontal padding each side
ALLEGRO_MOUSE_CURSOR * cursor_want_custom
... or a custom one, borrowed, which wins over the shape when set
float titlebar_h
title bar height
ALLEGRO_EVENT_QUEUE * event_queue
event queue the context registers native window event sources into (set via n_gui_set_event_queue).
float ratio
divider ratio (kind == SPLITPANE)
float gui_offset_y
vertical letterbox offset for virtual canvas
int hovered
which button is currently hovered (N_GUI_TB_BTN_*)
ALLEGRO_BITMAP * item_selected_bitmap
optional bitmap for per-item background, selected/highlighted (NULL = color theme)
N_GUI_PENDING_GEOM * pending_layout
layout entries for windows that did NOT exist when the saved layout was loaded (lazily-created panels...
void(* on_select)(int widget_id, int index, int selected, void *user_data)
callback on selection change (widget_id, item_index, selected, user_data)
float natural_h
stacked height of the members when expanded, recomputed by n_gui_sectionlist_relayout() from the live...
int scroll_offset
first visible line
float item_height
item height in pixels
void(* on_select)(int widget_id, int index, void *user_data)
callback on selection change (widget_id, selected_index, user_data)
int focused_widget_id
id of the widget that currently has focus, or -1
float h_scroll
horizontal scroll offset in pixels: how far the columns are scrolled to the left when their total wid...
int global_vscroll_drag
1 if global scrollbar vertical thumb is being dragged
int sel_dragging
1 if mouse is actively dragging to select text
char * selected
path of the selected node, or NULL
int nb_visible
number of visible rows
ALLEGRO_COLOR global_scrollbar_track_color
global scrollbar track colour
float item_height_pad
min padding added to font height for item height
int up_id
button widget ID for the move-up action (row actions only)
int section_hidden[16]
1 = the whole section, header and members, is left out of the stack
float display_h
display/viewport height
size_t len
text length in bytes
N_GUI_LISTITEM * items
dynamic array of items
void * user_data
user data for callback
float corner_ry
corner radius Y for rounded shapes
int sel_end
selection end byte offset (-1 = no selection)
float width[64]
per-physical-column width
int bg_scale_mode
scale mode for bg_bitmap: N_GUI_IMAGE_FIT, N_GUI_IMAGE_STRETCH, or N_GUI_IMAGE_CENTER
int modifiers
the modifier keys held when the event came, ALLEGRO_KEYMOD_SHIFT, _CTRL, _ALT and _ALTGR ORed,...
N_GUI_SB_TRACK sb_h
and the horizontal one
size_t text_alloc
allocated buffer size (char_limit + 1)
ALLEGRO_DISPLAY * pass_display
display the pass currently being processed or drawn belongs to: NULL for the host's main display (and...
ALLEGRO_COLOR bg_normal
background normal
ALLEGRO_BITMAP * handle_bitmap
optional bitmap for the draggable handle, normal state (NULL = color theme)
ALLEGRO_FONT * font
font used by this widget (NULL = context default)
float norm_w
normalized width (fraction of parent window w)
int resize_mode
context resize mode: N_GUI_RESIZE_VIRTUAL or N_GUI_RESIZE_ADAPTIVE
float virtual_w
virtual canvas width (0 = disabled / identity transform)
float radiolist_default_item_height
default item height for radiolist
void * user_data
user data for the callback
void(* on_minimize)(int window_id, void *user_data)
callback on minimize button click (NULL = default: toggle N_GUI_WIN_MINIMISED)
char label[128]
label displayed next to the checkbox
float slider_value_label_offset
gap between slider end and value label
void(* on_context)(int widget_id, int row, int x, int y, void *user_data)
callback on right-click over a data row, for a context menu (widget_id, row, x, y,...
size_t nb_items
number of items
int depth
depth in tree (0 = root)
float tb_btn_glyph_thickness
line thickness for titlebar button glyphs
ALLEGRO_COLOR bg_active
background active/pressed
char mask_char
mask character for password fields (0 = no masking, e.g.
ALLEGRO_BITMAP * minimize_bitmap
optional bitmap for minimize button normal state (NULL = color theme)
int split_b
splitpane widget ID of the divider after the second text column, or -1
int global_hscroll_drag
1 if global scrollbar horizontal thumb is being dragged
float w
saved width (display-scaled), 0 when absent
LIST * windows
ordered list of N_GUI_WINDOW* (back to front)
char text[128]
display text
int scroll_y
scroll offset for long text
char text[4096]
optional centered overlay text (empty string = none)
void(* on_scroll)(int widget_id, double scroll_pos, void *user_data)
callback on scroll
int x
bounding box x offset from draw origin
float gui_bounds_h
total bounding box height of all windows (computed internally)
double min_val
minimum value
float textarea_cursor_blink_period
cursor blink period in seconds (full cycle on+off)
int lbl_value
label widget ID for "Value" header
void(* on_toggle)(int widget_id, int checked, void *user_data)
callback on toggle
void(* on_expand)(int, void *)
fills a node the first time it opens, or NULL
ALLEGRO_COLOR bg_hover
background hover
size_t sel_start
selection anchor position (where shift-click/shift-arrow started).
int window_id
parent window
int cursor_shape
system mouse cursor currently applied to the display (an ALLEGRO_SYSTEM_MOUSE_CURSOR_* value),...
void * on_content_draw_data
user data passed to on_content_draw
void(* on_change)(int widget_id, const unsigned char *data, size_t len, void *user_data)
called after any edit, with the new byte count
float dropdown_arrow_thickness
arrow stroke thickness
float tb_btn_right_margin
right margin from window edge to rightmost button
void * user_data
user data for callback
ALLEGRO_COLOR link_color_hover
link colour (hover)
float radio_circle_min_r
minimum outer circle radius
ALLEGRO_BITMAP * bg_bitmap
optional bitmap for the listbox background (NULL = color theme)
float item_text_padding
text padding inside list/combo/dropmenu items
int next_widget_id
next widget id to assign
char * value_placeholder
owned hint shown in each value textarea, or NULL
float autofit_border
padding/border around content for auto-fit (pixels, applied on each side)
int suggest_count
how many of them
float gui_scale
computed uniform scale factor for virtual canvas
int anchor_row
anchor row for Shift-click range selection, or -1
int glyph
NGUI_GLYPH* icon drawn centred in the button's text colour instead of the label (N_GUI_GLYPH_NONE,...
int native_drag_anchored
1 when the four native_drag_* fields hold a usable grab, that is when al_get_mouse_cursor_position wo...
size_t cursor_pos
cursor position in text
float restore_y
saved y position before maximise (for restore)
int scroll_offset
first visible data row
void * user_data
user data for callback
int mode
mode: N_GUI_SLIDER_VALUE or N_GUI_SLIDER_PERCENT
int dirty
non-zero when the GUI's appearance may have changed since the last n_gui_draw.
size_t char_limit
maximum character limit (0 = N_GUI_TEXT_MAX)
int editable
1 when the bytes can be edited in place
void(* on_select)(int widget_id, int row, void *user_data)
callback on row selection (widget_id, row, user_data)
int toggle_mode
toggle mode: 0 = momentary (default), 1 = toggle (stays clicked/unclicked)
int is_open
is the menu currently open
float measured_w
the width it was measured at, so a resize re-measures and nothing else has to remember to
ALLEGRO_COLOR border_hover
border hover
N_GUI_CTX * ctx
GUI context.
void * on_minimize_user_data
user data for on_minimize callback
float scrollbar_thumb_min
minimum thumb dimension
int down_id
button widget ID for the move-down action (row actions only)
float x
pointer x from the widget's left edge; outside 0..w during a DRAG
int native_halted
1 while the native window's drawing is halted.
double wheel_step
how far one wheel notch moves it, in content units; 0 (the default) is a twentieth of the range.
int native_pos_y
last known native window y position (see native_pos_x)
float x
x origin of first tab button
ALLEGRO_BITMAP * thumb_hover_bitmap
optional bitmap for the thumb on hover (NULL = fallback to thumb_bitmap)
double double_click_time
how long after a press a second one still counts as a double click, in seconds.
int suggest_highlight
which one the keys and the pointer are on (-1 = none)
int value_id
textarea widget ID for the value
char label[128]
label displayed on the button
ALLEGRO_BITMAP * bg_bitmap
optional bitmap for the text area background (NULL = color theme)
int align
text alignment: N_GUI_ALIGN_LEFT, N_GUI_ALIGN_CENTER, N_GUI_ALIGN_RIGHT
int prev_over_win
whether the pointer was over a window on the previous motion event, so a motion that leaves the GUI s...
float native_w
last known native window width, 0 until the window is first detached.
size_t nb_rows
number of rows
void(* on_maximize)(int window_id, void *user_data)
callback on maximize button click (NULL = default: toggle N_GUI_WIN_MAXIMISED)
size_t text_len
current text length
char link[4096]
optional hyperlink URL (empty string = no link)
int orientation
orientation: N_GUI_SCROLLBAR_H or N_GUI_SCROLLBAR_V
float global_scrollbar_thumb_min
global minimum thumb dimension
double viewport_size
visible viewport size
int col_resize_col
physical column being resized by a header-border drag, or -1
unsigned char consumed
1 once applied
void(* on_link_click)(int widget_id, const char *link, void *user_data)
callback when link is clicked (widget_id, link_url, user_data)
ALLEGRO_FONT * default_font
default font.
float combobox_max_dropdown_width
maximum dropdown width for N_GUI_COMBOBOX_AUTO_WIDTH (0 = display width)
int selection_mode
selection mode: N_GUI_SELECT_NONE, N_GUI_SELECT_SINGLE, N_GUI_SELECT_MULTIPLE
float h
saved height (display-scaled), 0 when absent
size_t nb_items
number of items
int key_modifiers
required modifier key flags for the keybind (0 = no modifier requirement, matches any modifier state ...
ALLEGRO_COLOR * row_color
per-row background tint, sized rows_cap; NULL until a row color is set
float header_h
header button height
int widget_ids[96]
member widget ids
LIST * widgets
list of N_GUI_WIDGET* contained in this window
void * user_data
user data for callback
float y
position y on screen
ALLEGRO_BITMAP * bitmap_active
optional bitmap for active/pressed state
int tooltip_anchor_y
pointer y when the tooltip was last armed
double tooltip_armed_at
time the tooltip hover was (re)armed, from al_get_time()
char * placeholder
optional placeholder/hint text drawn dimmed while the field is empty (NULL = none); cleared from view...
int enabled
enabled flag (1 = enabled, 0 = disabled: drawn dimmed and ignores input)
float radio_circle_border_thickness
outer circle border thickness
float col_resize_w0
original width of the column at the start of a resize drag
int keycode
bound keyboard keycode (0 = none).
ALLEGRO_BITMAP * thumb_active_bitmap
optional bitmap for the thumb while dragging (NULL = fallback to thumb_bitmap)
float slider_track_size
track width (vertical) or height (horizontal)
ALLEGRO_DISPLAY * active_display
display that last received input, used to pick the display for clipboard and mouse-cursor calls.
float scroll_x
horizontal scroll offset for auto-scrollbar (pixels)
float slider_handle_border_thickness
handle border thickness
const char * n_gui_syntaxview_get_text(N_GUI_CTX *ctx, int widget_id)
get the text currently shown by a syntax view
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_combobox_set_bitmaps(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *bg, ALLEGRO_BITMAP *item_bg, ALLEGRO_BITMAP *item_selected)
Set optional bitmap overlays on a combobox widget.
int n_gui_load_theme_json(N_GUI_CTX *ctx, const char *filepath)
load a theme and style from a JSON file
#define N_GUI_MOUSE_DOWN
custom widget mouse event: a press inside it, button 1 or 2
int n_gui_suggest_add(N_GUI_SUGGEST_SINK *sink, const char *text)
add one completion to a suggestion sink
int n_gui_listbox_get_scroll_offset(N_GUI_CTX *ctx, int widget_id)
get the current scroll offset (in items)
void n_gui_dropmenu_clear(N_GUI_CTX *ctx, int widget_id)
Remove all entries from a dropdown menu.
int n_gui_widget_screen_rect(N_GUI_CTX *ctx, int widget_id, float *x, float *y, float *w, float *h)
Where a widget is on screen, rather than inside its window.
#define N_GUI_STATE_HOVER
mouse is hovering the widget
void n_gui_sectionlist_set_folded(N_GUI_SECTIONLIST *sl, int section_index, int folded)
set a section's folded state and relayout; does NOT fire on_toggle (for programmatic restore)
void n_gui_update_transform(N_GUI_CTX *ctx)
Recalculate scale and offset from virtual canvas to physical display.
#define N_GUI_DROPMENU_EXPAND_UP
dropdown panel opens upward (above the button) instead of downward.
int n_gui_add_hexview(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h)
Add a read-only hexadecimal byte viewer.
int n_gui_button_is_toggled(N_GUI_CTX *ctx, int widget_id)
Check if a toggle button is currently in the "on" state.
#define N_GUI_TYPE_MARKDOWNVIEW
widget type: read-only scrolling Markdown view
void n_gui_datagrid_sort(N_GUI_CTX *ctx, int widget_id, int col, int dir)
sort the rows by a column (dir 1 ascending, -1 descending)
float n_gui_detect_dpi_scale(N_GUI_CTX *ctx, ALLEGRO_DISPLAY *display)
Detect and apply DPI scale from an Allegro display.
float n_gui_splitpane_get_ratio(N_GUI_CTX *ctx, int widget_id)
get the current divider ratio of a split pane
void n_gui_toggle_window(N_GUI_CTX *ctx, int window_id)
Toggle window visibility (show if hidden, hide if shown).
#define N_GUI_GLYPH_COPY
two offset sheets: duplicate / copy
#define N_GUI_GLYPH_ARROW_UP
filled triangle pointing up
void n_gui_datagrid_set_on_columns_changed(N_GUI_CTX *ctx, int widget_id, void(*cb)(int, void *))
set the callback fired after the user drags a column border to resize it, so the host can persist the...
void n_gui_sectionlist_set_widget_offset(N_GUI_SECTIONLIST *sl, int section_index, int widget_id, float dy)
state a member's y offset from the section's content top, for a caller that computes its own layout a...
void n_gui_datagrid_set_selected(N_GUI_CTX *ctx, int widget_id, int row)
set the selected row index (fires the on_select callback).
N_GUI_MD_STYLE * n_gui_markdownview_style(N_GUI_CTX *ctx, int widget_id)
the view's style, to read or to change in place, or NULL if there is no such widget.
void n_gui_hexview_set_data(N_GUI_CTX *ctx, int widget_id, const unsigned char *data, size_t len)
set (copy) the bytes shown by a hex viewer
#define N_GUI_TREE_MAX
maximum number of nodes in a tree view
#define N_GUI_ZORDER_NORMAL
default z-order: window participates in normal raise/lower ordering
#define N_GUI_ALIGN_LEFT
left aligned text
void n_gui_tree_state_apply(N_GUI_TREE *tree, const N_GUI_TREE_STATE *state)
re-expand, re-select and re-scroll a rebuilt tree from a saved state.
void n_gui_raise_window(N_GUI_CTX *ctx, int window_id)
Bring a window to the front (top of draw order).
void n_gui_label_set_truncate(N_GUI_CTX *ctx, int widget_id, int mode)
set the text of a label widget
void n_gui_datagrid_clear_row_color(N_GUI_CTX *ctx, int widget_id, int row)
remove the background tint of data row row (it draws untinted again)
int n_gui_add_slider(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, double min_val, double max_val, double initial, int mode, void(*on_change)(int, double, void *), void *user_data)
Add a slider widget.
void n_gui_combobox_set_flags(N_GUI_CTX *ctx, int widget_id, int flags)
Set combobox feature flags.
void n_gui_window_apply_autofit(N_GUI_CTX *ctx, int window_id)
Trigger auto-fit recalculation for a window.
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,...
int n_gui_needs_redraw(N_GUI_CTX *ctx)
Return non-zero if the GUI must be redrawn this frame, i.e.
void n_gui_hexview_set_cursor(N_GUI_CTX *ctx, int widget_id, size_t offset)
move the edit cursor to a byte offset
int n_gui_datagrid_get_row_count(N_GUI_CTX *ctx, int widget_id)
get the number of rows in a data grid
#define N_GUI_SYNTAX_HTTP
syntax view: HTTP message highlighting (request/status line and headers)
void n_gui_textarea_set_text(N_GUI_CTX *ctx, int widget_id, const char *text)
set the text content of a textarea widget
void n_gui_kvtable_relayout(N_GUI_KVTABLE *table)
re-apply layout to all KV table widgets (positions, sizes, normalized coords).
int n_gui_save_layout_json(N_GUI_CTX *ctx, const char *filepath)
save the geometry + persistent state of every window to a JSON file
int n_gui_add_markdownview(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, const N_GUI_MD_FONTS *fonts)
add a read-only scrolling Markdown view.
int n_gui_window_detach(N_GUI_CTX *ctx, int window_id, int detach_flags)
Promote a pop-up window to a native OS window.
#define N_GUI_DETACH_SCALE_CONTENT
scale the window's widgets when the native window is resized by the user.
#define N_GUI_TB_BTN_NONE
no titlebar button
#define N_GUI_SLIDER_PERCENT
slider uses 0-100 percentage
#define N_GUI_DROP_BEFORE
drop position relative to a tree row (drag-and-drop)
int n_gui_kvtable_get_count(const N_GUI_KVTABLE *table)
get the number of active rows
int n_gui_dropmenu_is_open(N_GUI_CTX *ctx, int widget_id)
Is a dropdown menu's panel showing.
void n_gui_sectionlist_set_widget_hidden(N_GUI_SECTIONLIST *sl, int section_index, int widget_id, int hidden)
keep a member hidden whatever the fold state, and leave it out of the section's height.
const unsigned char * n_gui_hexview_get_data(N_GUI_CTX *ctx, int widget_id, size_t *len)
borrow the bytes a hex view holds
double n_gui_scrollbar_get_pos(N_GUI_CTX *ctx, int widget_id)
get the current scroll position of a scrollbar widget
void n_gui_tree_set_label(N_GUI_TREE *tree, int node_index, const char *new_label)
change the display label of a node
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
int n_gui_add_vslider(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, double min_val, double max_val, double initial, int mode, void(*on_change)(int, double, void *), void *user_data)
Add a vertical slider widget.
void n_gui_set_display(N_GUI_CTX *ctx, ALLEGRO_DISPLAY *display)
Set the display pointer for clipboard operations (copy/paste).
void n_gui_window_set_bitmaps(N_GUI_CTX *ctx, int window_id, ALLEGRO_BITMAP *bg, ALLEGRO_BITMAP *titlebar, int bg_scale_mode)
Set optional bitmap overlays on a window's body and titlebar.
void n_gui_set_widget_theme(N_GUI_CTX *ctx, int widget_id, N_GUI_THEME theme)
Override the theme of a specific widget.
#define N_GUI_SECTIONLIST_MAX
maximum number of foldable sections in a section list
const char * n_gui_datagrid_get_cell(N_GUI_CTX *ctx, int widget_id, int row, int col)
get a cell string by row and column, or NULL if out of range
#define N_GUI_MOUSE_WHEEL
custom widget mouse event: the wheel turned over it
int n_gui_wants_mouse(N_GUI_CTX *ctx)
Check if the mouse is currently over any open GUI window.
int n_gui_dropmenu_get_count(N_GUI_CTX *ctx, int widget_id)
Get number of entries in a dropdown menu.
int n_gui_radiolist_add_item(N_GUI_CTX *ctx, int widget_id, const char *text)
add an item to a radiolist widget
int n_gui_focus_takes_key(const N_GUI_CTX *ctx, int keycode)
Would the focused widget do something with this particular key.
#define N_GUI_WIN_VSCROLL_DRAG
window vertical auto-scrollbar is being dragged
void n_gui_set_widget_tooltip(N_GUI_CTX *ctx, int widget_id, const char *text)
Set (or clear) the tooltip text of any widget.
#define N_GUI_TYPE_DATAGRID
widget type: sortable column data grid
void n_gui_lower_window(N_GUI_CTX *ctx, int window_id)
Lower a window to the bottom of the draw order.
void n_gui_label_set_text(N_GUI_CTX *ctx, int widget_id, const char *text)
set label text content
int n_gui_window_native_is_hidden(N_GUI_CTX *ctx, int window_id)
Check whether a detached window is currently not drawable.
size_t n_gui_datagrid_get_column_count(N_GUI_CTX *ctx, int widget_id)
number of columns in a data grid (physical), or 0
int n_gui_add_listbox(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int selection_mode, void(*on_select)(int, int, int, void *), void *user_data)
Add a listbox widget.
#define N_GUI_SUGGEST_MAX
most completions a textarea's suggestion list keeps for one prefix.
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.
int n_gui_text_shorten(ALLEGRO_FONT *font, const char *text, float max_w, int mode, char *out, size_t out_len)
shorten text to fit max_w pixels in font, the way a label with truncate mode mode shows it: unchanged...
#define N_GUI_GLYPH_NONE
no glyph: the button draws its text label (default)
float n_gui_listbox_get_h_scroll(N_GUI_CTX *ctx, int widget_id)
get a listbox's horizontal scroll offset in pixels (0 = leftmost)
#define N_GUI_COMBOBOX_EXPAND_UP
dropdown panel opens upward (above the widget) instead of downward.
#define N_GUI_PERSIST_MAX_COLS
Maximum datagrid columns whose layout is persisted per widget.
float n_gui_datagrid_get_h_scroll(N_GUI_CTX *ctx, int widget_id)
#define N_GUI_COMBOBOX_AUTO_WIDTH
dropdown panel expands to fit the longest item text
#define N_GUI_TYPE_LABEL
widget type: static text label (with optional hyperlink)
#define N_GUI_WIN_RESIZE_SCALE
reposition AND resize proportionally, child widgets scale too
int n_gui_set_default_font(N_GUI_CTX *ctx, ALLEGRO_FONT *font)
Replace the context's default font, keeping every widget and its state.
void n_gui_datagrid_set_row_color(N_GUI_CTX *ctx, int widget_id, int row, ALLEGRO_COLOR color)
paint data row row with a background tint (a per-row highlight, e.g.
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_datagrid_set_scroll_offset(N_GUI_CTX *ctx, int widget_id, int offset)
set the first visible data row (clamped to the row count); the draw path re-clamps to the live viewpo...
size_t n_gui_datagrid_get_selected_rows(N_GUI_CTX *ctx, int widget_id, int *out, size_t max)
fill out with the indices of the selected rows (ascending), up to max, and return the total number of...
int n_gui_datagrid_get_scroll_offset(N_GUI_CTX *ctx, int widget_id)
first visible data row (the vertical scroll position), or 0.
#define N_GUI_TYPE_CHECKBOX
widget type: checkbox
int n_gui_slider_handle_pos(N_GUI_CTX *ctx, int widget_id, float *pos, float *radius)
Where a slider's handle is drawn and how big it is.
void n_gui_window_set_tb_button_bitmaps(N_GUI_CTX *ctx, int window_id, int btn_type, ALLEGRO_BITMAP *normal, ALLEGRO_BITMAP *hover, ALLEGRO_BITMAP *active)
Set optional bitmap overlays on a titlebar button.
void n_gui_focus_window(N_GUI_CTX *ctx, int window_id)
Give a window keyboard focus and bring it to the front.
#define N_GUI_KV_MAX
maximum number of rows in a KV table
#define N_GUI_TYPE_DROPMENU
widget type: dropdown menu with static and dynamic entries
float n_gui_syntaxview_get_h_scroll(N_GUI_CTX *ctx, int widget_id)
get the horizontal scroll offset of a syntax view
int n_gui_hovered_widget(const N_GUI_CTX *ctx)
Id of the widget currently under the mouse pointer, or -1.
int n_gui_process_event(N_GUI_CTX *ctx, ALLEGRO_EVENT event)
Process an allegro event through the GUI system.
int n_gui_window_get_flags(N_GUI_CTX *ctx, int window_id)
Get feature flags of a window.
void n_gui_minimize_window(N_GUI_CTX *ctx, int window_id)
Minimise a window (show title bar only).
#define N_GUI_DETACH_NONE
no option
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.
void n_gui_set_widget_enabled(N_GUI_CTX *ctx, int widget_id, int enabled)
Enable or disable a widget.
int n_gui_add_radiolist(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, void(*on_select)(int, int, void *), void *user_data)
Add a radio list widget (single selection with radio bullets).
#define N_GUI_SPLIT_HORIZONTAL
split pane: horizontal divider, regions are top and bottom
#define N_GUI_WIN_FIXED_POSITION
disable window dragging (default:enable)
void n_gui_tab_free(N_GUI_TAB_PANEL **panel)
free a tab panel (does not destroy the N_GUI widgets)
void n_gui_close_window(N_GUI_CTX *ctx, int window_id)
Close (hide) a window.
void n_gui_maximize_window(N_GUI_CTX *ctx, int window_id)
Toggle maximised state (full display or restore to previous size).
void n_gui_listbox_set_bitmaps(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *bg, ALLEGRO_BITMAP *item_bg, ALLEGRO_BITMAP *item_selected)
Set optional bitmap overlays on a listbox widget.
void n_gui_label_set_link(N_GUI_CTX *ctx, int widget_id, const char *link)
set the link URL of a label widget
void n_gui_datagrid_set_on_context(N_GUI_CTX *ctx, int widget_id, void(*on_context)(int, int, int, int, void *))
set the right-click context callback; fired (with the cursor x/y in GUI coordinates) when a data row ...
#define N_GUI_RESIZE_VIRTUAL
fixed virtual canvas with uniform scaling (default/existing behavior)
ALLEGRO_EVENT_QUEUE * n_gui_get_event_queue(N_GUI_CTX *ctx)
Get the event queue previously given to n_gui_set_event_queue.
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_button_set_keycode_focused(N_GUI_CTX *ctx, int widget_id, int keycode, int modifiers, const int *sources, int source_count)
Set a focused key binding on a button.
void n_gui_radiolist_clear(N_GUI_CTX *ctx, int widget_id)
remove all items from a radiolist widget
#define N_GUI_GLYPH_ARROW_RIGHT
filled triangle pointing right
int n_gui_combobox_get_count(N_GUI_CTX *ctx, int widget_id)
get the number of items in a combobox widget
#define N_GUI_TYPE_SPLITPANE
widget type: split pane with a draggable divider between two regions
void n_gui_kvtable_clear(N_GUI_KVTABLE *table)
remove every row at once.
void n_gui_markdownview_scroll_to(N_GUI_CTX *ctx, int widget_id, float y)
scroll to y pixels down the content, clamped to what there is
int(* N_GUI_CUSTOM_MOUSE)(int widget_id, const N_GUI_MOUSE_EVENT *ev, void *user_data)
Mouse callback for a custom widget, set with n_gui_custom_set_mouse().
void n_gui_slider_set_value_format(N_GUI_CTX *ctx, int widget_id, const char *fmt)
Override the built-in value readout's printf format string.
void n_gui_listbox_set_selected(N_GUI_CTX *ctx, int widget_id, int index, int selected)
set the selection state of a listbox item
#define N_GUI_SELECT_NONE
no selection allowed (display only)
int(* n_gui_tree_on_drop_t)(int src_node, int dst_node, int position, void *user_data)
drag-reorder drop callback.
#define N_GUI_TYPE_HEXVIEW
widget type: read-only hexadecimal byte viewer
int n_gui_add_window_auto(N_GUI_CTX *ctx, const char *title, float x, float y)
Add a window with automatic sizing (use n_gui_window_autosize after adding widgets).
int n_gui_tree_find_by_path(const N_GUI_TREE *tree, const char *path)
index of the first node with the given path, or -1.
void n_gui_syntaxview_set_selection(N_GUI_CTX *ctx, int widget_id, int start, int end)
set the selection range of a syntax view (byte offsets into the text)
#define N_GUI_GLYPH_CROSS
diagonal cross
void n_gui_syntaxview_set_h_scroll(N_GUI_CTX *ctx, int widget_id, float px)
set the horizontal scroll offset of a syntax view
#define N_GUI_GLOBAL_SCROLL_SLACK
how far, in pixels, the open windows may reach past the display before the global scrollbars appear: ...
int n_gui_dropmenu_set_open(N_GUI_CTX *ctx, int widget_id, int open)
Open or close a dropdown menu without a click on its button.
double n_gui_slider_get_value(N_GUI_CTX *ctx, int widget_id)
get the current value of a slider widget
#define N_GUI_TREE_PATH_MAX
maximum length of a node path (labels from the root, joined)
#define N_GUI_TREE_STATE_MAX
maximum number of expanded paths remembered by an N_GUI_TREE_STATE
int n_gui_listbox_add_item(N_GUI_CTX *ctx, int widget_id, const char *text)
add an item to a listbox widget
void n_gui_window_set_caption(N_GUI_CTX *ctx, int window_id, const char *caption)
Show a caption in a window's title bar in place of its title.
void n_gui_listbox_set_h_scroll(N_GUI_CTX *ctx, int widget_id, float px)
set a listbox's horizontal scroll offset in pixels
void n_gui_tree_set_expandable(N_GUI_TREE *tree, int node_index, int expandable)
mark a node as openable before it has children, so it shows an expander and the expand callback fills...
N_GUI_THEME n_gui_default_tb_btn_theme(void)
Build a default theme for titlebar minimize/maximize buttons.
void n_gui_set_virtual_size(N_GUI_CTX *ctx, float w, float h)
Set the virtual canvas size for resolution-independent scaling.
int n_gui_tooltip_pending(N_GUI_CTX *ctx)
Report the tooltip phase.
#define N_GUI_TRUNCATE_START
text too wide for its box is cut at the start, "...ong sentence": for anything whose end is what tell...
int n_gui_datagrid_is_row_selected(N_GUI_CTX *ctx, int widget_id, int row)
report whether a given data row is selected (1) or not (0)
float n_gui_get_dpi_scale(const N_GUI_CTX *ctx)
Get current DPI scale factor.
void n_gui_tree_clear(N_GUI_TREE *tree)
remove all nodes and clear the backing listbox; tree object remains valid
N_GUI_THEME n_gui_default_theme(void)
Build a sensible default colour theme.
#define N_GUI_WIN_RESIZE_NONE
no adaptation: absolute position and size unchanged
void n_gui_window_set_zorder(N_GUI_CTX *ctx, int window_id, int z_mode, int z_value)
Set window z-order mode and value.
int n_gui_radiolist_get_selected(N_GUI_CTX *ctx, int widget_id)
get the selected item index in a radiolist widget
void n_gui_tab_set_content_window(N_GUI_TAB_PANEL *panel, int tab_index, int window_id)
associate a content window with a tab
#define N_GUI_TYPE_SLIDER
widget type: slider
#define N_GUI_WIN_OPEN
window is visible
void n_gui_button_set_label(N_GUI_CTX *ctx, int widget_id, const char *label)
Replace the label text drawn on a button.
void n_gui_button_set_state_bitmaps(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *normal, ALLEGRO_BITMAP *hover, ALLEGRO_BITMAP *active)
Skin a button (or toggle button) with per-state bitmaps.
int n_gui_save_theme_json(N_GUI_CTX *ctx, const char *filepath)
save the current theme and style to a JSON file
#define N_GUI_SELECT_SINGLE
single item selection
#define N_GUI_TB_BTN_CLOSE
close titlebar button
int n_gui_combobox_add_item(N_GUI_CTX *ctx, int widget_id, const char *text)
add an item to a combo box
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.
float n_gui_sectionlist_content_height(const N_GUI_SECTIONLIST *sl)
total content height in pixels under the current fold state, for sizing/scrolling the host window
void n_gui_window_autosize(N_GUI_CTX *ctx, int window_id)
Recompute and apply minimum-fit size for a window based on its current widgets.
int n_gui_syntaxview_get_line_count(N_GUI_CTX *ctx, int widget_id)
get the number of text lines in a syntax view
#define N_GUI_SECTION_WIDGETS_MAX
maximum number of member widgets per section.
int n_gui_window_button_rect(N_GUI_CTX *ctx, int window_id, int btn_type, float *x, float *y, float *w, float *h)
Where one of a window's title bar buttons is, on screen.
void n_gui_window_set_minimize_callback(N_GUI_CTX *ctx, int window_id, void(*on_minimize)(int, void *), void *user_data)
Set the minimize button callback for a window.
int n_gui_kvtable_move_row(N_GUI_KVTABLE *table, int row_index, int direction)
Move a row one position up or down among the active rows.
int n_gui_add_splitpane(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int orientation, float ratio, void(*on_change)(int, float, void *), void *user_data)
Add a split pane widget: a draggable divider between two regions.
const char * n_gui_widget_get_persist_key(N_GUI_CTX *ctx, int widget_id)
Get a widget's persist key ("" when unset), or NULL when the widget is invalid.
int n_gui_datagrid_add_column(N_GUI_CTX *ctx, int widget_id, const char *title, float width)
append a column with a header title and pixel width; returns the column index or -1
void n_gui_set_focus(N_GUI_CTX *ctx, int widget_id)
Set keyboard focus to a specific widget.
#define N_GUI_MOUSE_DRAG
custom widget mouse event: the pointer moved with button 1 held after a press in it; reported outside...
void n_gui_tree_rebuild(N_GUI_TREE *tree)
rebuild the listbox to reflect current tree state
void n_gui_datagrid_set_h_scroll(N_GUI_CTX *ctx, int widget_id, float px)
set the horizontal scroll offset in pixels (clamped to >= 0; the draw path re-clamps to the live cont...
void n_gui_datagrid_set_multiselect(N_GUI_CTX *ctx, int widget_id, int enabled)
enable (1) or disable (0) multi-row selection.
void n_gui_textarea_set_selection(N_GUI_CTX *ctx, int widget_id, size_t start, size_t end)
set the text selection range (byte offsets into text content)
#define N_GUI_SELECT_MULTIPLE
multiple item selection
void n_gui_scrollbar_set_bitmaps(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *track, ALLEGRO_BITMAP *thumb, ALLEGRO_BITMAP *thumb_hover, ALLEGRO_BITMAP *thumb_active)
Set optional bitmap overlays on a scrollbar widget.
int n_gui_window_find_button(N_GUI_CTX *ctx, int window_id, const char *label)
Find the button in a window whose label is exactly this.
#define N_GUI_WIN_FRAMELESS
frameless window: no title bar drawn, drag via window body unless N_GUI_WIN_FIXED_POSITION is also se...
void n_gui_set_shape_mode(N_GUI_CTX *ctx, int shape_mode)
Set the global widget shape (round or square GUI).
int n_gui_add_combobox(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, void(*on_select)(int, int, void *), void *user_data)
Add a combo box widget (dropdown selector).
void n_gui_syntaxview_set_mode(N_GUI_CTX *ctx, int widget_id, int mode)
set the highlighting mode of a syntax view
void n_gui_button_set_toggled(N_GUI_CTX *ctx, int widget_id, int toggled)
Set the toggle state of a button.
void n_gui_custom_set_mouse(N_GUI_CTX *ctx, int widget_id, N_GUI_CUSTOM_MOUSE on_mouse, void *user_data)
give a custom widget mouse input
void n_gui_set_double_click_time(N_GUI_CTX *ctx, double seconds)
set how long after a press a second one still counts as a double click
void n_gui_progressbar_set_text(N_GUI_CTX *ctx, int widget_id, const char *text)
set the centered overlay text (NULL or "" clears it)
void n_gui_tab_set_active(N_GUI_TAB_PANEL *panel, int index)
set the active tab (toggles buttons, opens/closes content windows)
#define N_GUI_DETACH_RESIZABLE
the native window can be resized by the user through the OS window manager
#define N_GUI_SYNTAX_DIFF
syntax view: unified diff highlighting (added, removed and hunk header lines, as produced by n_diff_t...
int n_gui_window_is_detached(N_GUI_CTX *ctx, int window_id)
Check whether a window currently lives in a native OS window.
void n_gui_slider_set_step(N_GUI_CTX *ctx, int widget_id, double step)
set slider step increment.
int n_gui_add_toggle_button(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, int shape, int initial_state, void(*on_click)(int, void *), void *user_data)
Add a toggle button widget (stays clicked/unclicked on single click).
int n_gui_get_topmost_open_window(const N_GUI_CTX *ctx)
Get the id of the frontmost open, non-minimized window.
void n_gui_kvtable_remove_row(N_GUI_KVTABLE *table, int row_index)
remove a row by index (hides widgets, marks inactive)
int n_gui_add_label_link(N_GUI_CTX *ctx, int window_id, const char *text, const char *link, float x, float y, float w, float h, int align, void(*on_link_click)(int, const char *, void *), void *user_data)
Add a static text label with hyperlink.
void n_gui_textarea_set_mask_char(N_GUI_CTX *ctx, int widget_id, char mask)
Set a mask character for password-style input.
void n_gui_window_set_tb_close_theme(N_GUI_CTX *ctx, int window_id, N_GUI_THEME theme)
Set the theme for the titlebar close button on a specific window.
void n_gui_window_set_tb_btn_theme(N_GUI_CTX *ctx, int window_id, N_GUI_THEME theme)
Set the theme for titlebar minimize/maximize buttons on a specific window.
int n_gui_add_progressbar(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h)
add a horizontal progress bar (display only); returns the widget id or -1
int n_gui_tab_get_active(const N_GUI_TAB_PANEL *panel)
get the active tab index
size_t n_gui_hexview_get_length(N_GUI_CTX *ctx, int widget_id)
get the number of bytes currently held by a hex viewer
int n_gui_listbox_get_selected(N_GUI_CTX *ctx, int widget_id)
get the index of the first selected item in a listbox
float n_gui_datagrid_columns_width(N_GUI_CTX *ctx, int widget_id)
horizontal scroll offset in pixels (how far the columns are scrolled left when their total width exce...
#define N_GUI_AUTOFIT_EXPAND_LEFT
expand leftward instead of rightward when adjusting width
int n_gui_add_image(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, ALLEGRO_BITMAP *bitmap, int scale_mode)
Add an image display widget.
int n_gui_double_clicked_widget(const N_GUI_CTX *ctx)
id of the widget the primary press just processed double clicked
void n_gui_widget_set_persist_key(N_GUI_CTX *ctx, int widget_id, const char *key)
Give a widget a stable key so its user-adjustable state (a splitpane's divider ratio,...
void n_gui_set_double_click_radius(N_GUI_CTX *ctx, int pixels)
set how far the pointer may move between the two presses
int n_gui_button_get_glyph(N_GUI_CTX *ctx, int widget_id)
Get the glyph currently drawn on a button.
void n_gui_label_set_bitmap(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *bg)
Set optional background bitmap on a label widget.
void n_gui_draw(N_GUI_CTX *ctx)
draw all visible GUI windows and widgets
void n_gui_progressbar_set_value(N_GUI_CTX *ctx, int widget_id, float value)
set the progress fraction (clamped to 0.0 .
#define N_GUI_TYPE_SYNTAXVIEW
widget type: read-only syntax-highlighted text view
#define N_GUI_WIN_MINIMISED
window is minimised (title bar only)
#define N_GUI_SLIDER_H
horizontal slider (default)
void n_gui_markdownview_set_on_link(N_GUI_CTX *ctx, int widget_id, void(*on_link)(int widget_id, const char *url, void *user_data), void *user_data)
call on_link when a link in the view is clicked (NULL to stop).
int n_gui_tree_find_by_user_data(const N_GUI_TREE *tree, const void *ptr)
find the first node whose user_data pointer equals ptr, or -1.
void n_gui_scrollbar_set_wheel_step(N_GUI_CTX *ctx, int widget_id, double step)
set how far one wheel notch moves a scrollbar
void n_gui_hexview_set_editable(N_GUI_CTX *ctx, int widget_id, int editable)
make a hex view editable, or read-only again
void n_gui_tree_set_selection(N_GUI_TREE *tree, int node_index)
programmatically select a node; ancestors are expanded so the node is visible, and the listbox scroll...
void n_gui_markdownview_set_text(N_GUI_CTX *ctx, int widget_id, const char *text)
set the Markdown source (copied; NULL clears it).
#define N_GUI_AUTOFIT_CENTER
center the window on its insertion point after auto-fit (overrides EXPAND_LEFT/EXPAND_UP for centerin...
int n_gui_tab_add(N_GUI_TAB_PANEL *panel, const char *label)
add a tab to the panel, returns tab index
void n_gui_tree_set_on_drop(N_GUI_TREE *tree, n_gui_tree_on_drop_t on_drop, void *user_data)
install (or clear, with NULL) a drag-reorder drop callback.
void n_gui_slider_set_bitmaps(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *track, ALLEGRO_BITMAP *fill, ALLEGRO_BITMAP *handle, ALLEGRO_BITMAP *handle_hover, ALLEGRO_BITMAP *handle_active)
Set optional bitmap overlays on a slider widget.
#define N_GUI_SYNTAX_XML
syntax view: XML/HTML highlighting (tags, attributes, quoted values, comments)
int n_gui_window_get_zorder(N_GUI_CTX *ctx, int window_id)
Get window z-order mode.
void n_gui_tree_free(N_GUI_TREE **tree)
free a tree view (does not destroy the N_GUI listbox)
N_GUI_SECTIONLIST * n_gui_sectionlist_create(N_GUI_CTX *ctx, int window_id, float x, float y0, float width, float header_h, float gap, void(*on_toggle)(int, int, void *), void *user_data)
create an empty section list anchored at (x,y0) in window_id; sections stack downward from y0
void n_gui_sectionlist_set_order(N_GUI_SECTIONLIST *sl, const int *order, int count)
Stack the sections in another order.
void n_gui_datagrid_move_column(N_GUI_CTX *ctx, int widget_id, int from, int to)
move the column at display position from to display position to, shifting the columns in between (reo...
#define N_GUI_TYPE_IMAGE
widget type: image display
int n_gui_window_get_resize_policy(N_GUI_CTX *ctx, int window_id)
Get per-window resize policy.
void n_gui_checkbox_set_checked(N_GUI_CTX *ctx, int widget_id, int checked)
set the checked state of a checkbox widget
int n_gui_dropmenu_add_dynamic_entry(N_GUI_CTX *ctx, int widget_id, const char *text, int tag, void(*on_click)(int, int, int, void *), void *user_data)
Add a dynamic entry (rebuilt each time menu opens).
void n_gui_apply_adaptive_resize(N_GUI_CTX *ctx, float new_w, float new_h)
Apply adaptive resize: reposition/resize all windows according to their policies for the new display ...
#define N_GUI_WIN_HSCROLL_HOVER
pointer is over the window's horizontal auto-scrollbar
int n_gui_tree_get_selection(N_GUI_TREE *tree)
get the index of the currently selected node, or -1 when nothing is selected or the selection points ...
void n_gui_hexview_set_on_change(N_GUI_CTX *ctx, int widget_id, void(*on_change)(int, const unsigned char *, size_t, void *), void *user_data)
set the callback fired after each edit
int n_gui_tree_node_path(const N_GUI_TREE *tree, int node_index, char *buf, size_t bufsz)
Write the path of a node into a buffer.
int n_gui_is_widget_enabled(N_GUI_CTX *ctx, int widget_id)
Check if a widget is enabled.
void n_gui_button_set_keycode(N_GUI_CTX *ctx, int widget_id, int keycode, int modifiers)
Bind a keyboard key with optional modifier requirements to a button.
#define N_GUI_SYNTAX_JSON
syntax view: JSON highlighting (keys, strings, numbers, punctuation)
float n_gui_listbox_content_width(N_GUI_CTX *ctx, int widget_id)
width the widest item of a listbox needs to be drawn in full
double n_gui_slider_get_key_step(N_GUI_CTX *ctx, int widget_id)
get the arrow key and wheel increment a slider actually uses
N_GUI_THEME n_gui_default_tb_close_theme(void)
Build a default theme for the titlebar close button.
char * n_gui_syntaxview_get_selected_text(N_GUI_CTX *ctx, int widget_id)
get a copy of the currently selected text in a syntax view
int n_gui_window_is_open(N_GUI_CTX *ctx, int window_id)
Check if a window is currently visible.
void n_gui_set_dpi_scale(N_GUI_CTX *ctx, float scale)
Set DPI scale factor manually (default 1.0).
#define N_GUI_TYPE_RADIOLIST
widget type: radio list (single select radio buttons)
#define N_GUI_SLIDER_V
vertical slider
int n_gui_get_resize_mode(N_GUI_CTX *ctx)
Get current resize mode.
void n_gui_slider_set_key_step(N_GUI_CTX *ctx, int widget_id, double step)
set how far one arrow key press or wheel notch moves a slider
float n_gui_markdownview_get_scroll(N_GUI_CTX *ctx, int widget_id)
how far down the content the view is, in pixels
#define N_GUI_STATE_SCROLLBAR_DRAG
widget scrollbar is being dragged
N_GUI_WIDGET * n_gui_get_widget(N_GUI_CTX *ctx, int widget_id)
Get a widget pointer by id.
int n_gui_dropmenu_add_entry(N_GUI_CTX *ctx, int widget_id, const char *text, int tag, void(*on_click)(int, int, int, void *), void *user_data)
Add a static entry to a dropdown menu.
int n_gui_get_focus(const N_GUI_CTX *ctx)
Which widget has the keyboard, or -1 when none has.
int n_gui_datagrid_get_row_color(N_GUI_CTX *ctx, int widget_id, int row, ALLEGRO_COLOR *out)
report whether data row row carries a background tint (1) or not (0), and copy the tint into out when...
#define N_GUI_ZORDER_ALWAYS_BEHIND
always drawn behind normal windows, cannot be raised above them
#define N_GUI_IMAGE_STRETCH
stretch to fill bounds
void n_gui_window_set_wheel_scrollbar(N_GUI_CTX *ctx, int window_id, int scrollbar_id)
Make the wheel anywhere over a window move one of its scrollbars.
N_GUI_WINDOW * n_gui_get_window(N_GUI_CTX *ctx, int window_id)
Get a window pointer by id.
#define N_GUI_ZORDER_ALWAYS_ON_TOP
always drawn on top of normal windows, cannot be lowered behind them
int n_gui_add_syntaxview(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int mode)
Add a read-only syntax-highlighted text view.
void n_gui_datagrid_clear_selection(N_GUI_CTX *ctx, int widget_id)
clear the entire selection (no row selected)
void n_gui_dropmenu_set_bitmaps(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *panel, ALLEGRO_BITMAP *item_hover)
Set optional bitmap overlays on a dropmenu widget.
int n_gui_slider_get_default(N_GUI_CTX *ctx, int widget_id, double *value)
read a slider's default
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.
void n_gui_slider_set_value_visible(N_GUI_CTX *ctx, int widget_id, int visible)
Toggle the built-in value label.
int n_gui_window_attach(N_GUI_CTX *ctx, int window_id)
Return a detached window to being an in-display pop-up.
void n_gui_tree_state_free(N_GUI_TREE_STATE *state)
release the strings owned by a saved state (safe on a zeroed struct)
#define N_GUI_GLYPH_ARROW_DOWN
filled triangle pointing down
void n_gui_datagrid_select_row(N_GUI_CTX *ctx, int widget_id, int row, int selected)
select (1) or deselect (0) a single row in a multi-select grid programmatically (e....
void n_gui_draw_detached(N_GUI_CTX *ctx)
Render and flip every detached window, and release the ones whose native window was closed.
N_GUI_CTX * n_gui_new_ctx(ALLEGRO_FONT *default_font)
Create a new GUI context.
#define N_GUI_MOUSE_MOVE
custom widget mouse event: the pointer moved over it with no button held
void n_gui_datagrid_clear_rows(N_GUI_CTX *ctx, int widget_id)
remove all rows from a data grid (columns are kept)
void n_gui_slider_set_range(N_GUI_CTX *ctx, int widget_id, double min_val, double max_val)
set slider min/max range, clamping the current value if needed
const char * n_gui_listbox_get_item_text(N_GUI_CTX *ctx, int widget_id, int index)
get the text of a listbox item
void n_gui_radiolist_set_bitmaps(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *bg, ALLEGRO_BITMAP *item_bg, ALLEGRO_BITMAP *item_selected)
Set optional bitmap overlays on a radiolist widget.
void n_gui_kvtable_set_row_actions(N_GUI_KVTABLE *table, int enabled)
Show or hide the per-row move-up / move-down / duplicate buttons.
void n_gui_button_set_glyph(N_GUI_CTX *ctx, int widget_id, int glyph)
Draw a glyph on a button instead of its text label.
N_GUI_TREE * n_gui_tree_create(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, void(*on_select)(int, void *), void *user_data)
create a tree view in an existing window
#define N_GUI_WIN_MAXIMISED
window is maximised (full display size)
int n_gui_add_button_bitmap(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, ALLEGRO_BITMAP *normal, ALLEGRO_BITMAP *hover, ALLEGRO_BITMAP *active, void(*on_click)(int, void *), void *user_data)
Add a bitmap-based button.
#define N_GUI_IMAGE_CENTER
draw at original size, centered
int n_gui_kvtable_duplicate_row(N_GUI_KVTABLE *table, int row_index)
Insert a copy of a row directly after it.
void n_gui_window_set_close_callback(N_GUI_CTX *ctx, int window_id, void(*on_close)(int, void *), void *user_data)
Set the close button callback for a window.
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_button_set_toggle_mode(N_GUI_CTX *ctx, int widget_id, int toggle_mode)
Enable or disable toggle mode on a button.
int n_gui_datagrid_display_to_physical(N_GUI_CTX *ctx, int widget_id, int display_pos)
physical column shown at display position display_pos, or -1 if out of range
#define N_GUI_ALIGN_CENTER
center aligned text
#define N_GUI_DETACH_OWN_CHROME
keep N_GUI's own window chrome instead of the window manager's: the native window is created frameles...
float n_gui_datagrid_get_column_width(N_GUI_CTX *ctx, int widget_id, int col)
current pixel width of physical column col, or 0 if out of range
void n_gui_tree_toggle_expand(N_GUI_TREE *tree, int node_index)
toggle expand/collapse of a node.
#define N_GUI_TRUNCATE_END
text too wide for its box is cut at the end, "Long senten...": the default, right for a sentence
#define N_GUI_TYPE_SCROLLBAR
widget type: scrollbar
void n_gui_textarea_scroll_to_offset(N_GUI_CTX *ctx, int widget_id, size_t byte_offset)
scroll a multiline textarea so that the given byte offset is vertically centered
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.
#define N_GUI_GLYPH_PLUS
plus sign
#define N_GUI_TYPE_PROGRESSBAR
widget type: horizontal progress bar (display only)
const char * n_gui_datagrid_get_column_title(N_GUI_CTX *ctx, int widget_id, int col)
header title of physical column col, or "" if out of range
#define N_GUI_TB_BTN_MAXIMIZE
maximize/restore titlebar button
void(* N_GUI_CUSTOM_DRAW)(N_GUI_WIDGET *widget, float x, float y, ALLEGRO_FONT *font, void *user_data)
Owner-draw callback for a custom widget (N_GUI_TYPE_CUSTOM).
#define N_GUI_TB_BTN_MINIMIZE
minimize titlebar button
#define N_GUI_SPLIT_VERTICAL
split pane: vertical divider, regions are left and right
void n_gui_sectionlist_set_geometry(N_GUI_SECTIONLIST *sl, float x, float y0, float width, float header_h, float gap)
restate where the list stacks from, how wide its headers are and the two heights it stacks with,...
void n_gui_textarea_set_bitmap(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *bg)
Set optional background bitmap on a textarea widget.
void n_gui_listbox_clear(N_GUI_CTX *ctx, int widget_id)
remove all items from a listbox widget
#define N_GUI_TYPE_BUTTON
widget type: button
#define N_GUI_TYPE_COMBOBOX
widget type: combo box (dropdown)
#define N_GUI_MOUSE_UP
custom widget mouse event: the release of a button 1 press that began in it, wherever the pointer is ...
float n_gui_dropmenu_panel_width(N_GUI_CTX *ctx, int widget_id)
Width the open drop-down panel needs to show its entries.
#define N_GUI_WIN_VSCROLL_HOVER
pointer is over the window's vertical auto-scrollbar
#define N_GUI_TYPE_CUSTOM
widget type: owner-draw custom widget (rendering delegated to a callback)
int n_gui_add_scrollbar(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int orientation, int shape, double content_size, double viewport_size, void(*on_scroll)(int, double, void *), void *user_data)
Add a scrollbar widget.
N_GUI_TEXT_DIMS n_gui_get_text_dims(ALLEGRO_FONT *font, const char *text)
get the bounding box dimensions of text rendered with the given font.
void n_gui_textarea_set_suggest(N_GUI_CTX *ctx, int widget_id, N_GUI_SUGGEST_FN fn, const char *separators, void *user_data)
offer completions in a textarea
#define N_GUI_WIN_BTN_MINIMIZE
enable minimize button on the title bar
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
int n_gui_window_is_minimised(N_GUI_CTX *ctx, int window_id)
Check if a window is currently minimised.
void n_gui_restore_window(N_GUI_CTX *ctx, int window_id)
Restore a minimised window to its full size.
#define N_GUI_ZORDER_FIXED
fixed z-value: window is sorted within a dedicated group between ALWAYS_BEHIND and NORMAL windows.
void n_gui_checkbox_set_label(N_GUI_CTX *ctx, int widget_id, const char *label)
Replace the text drawn beside a checkbox.
const char * n_gui_textarea_get_text(N_GUI_CTX *ctx, int widget_id)
get the text content of a textarea widget
const char * n_gui_markdownview_get_text(N_GUI_CTX *ctx, int widget_id)
the Markdown source, owned by the widget, or NULL
void n_gui_slider_set_default(N_GUI_CTX *ctx, int widget_id, double value)
give a slider the value a double click on it puts back
int n_gui_splitpane_at(N_GUI_CTX *ctx, float x, float y)
report the split pane whose divider band is under a point, or -1.
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
int n_gui_get_shape_mode(N_GUI_CTX *ctx)
Get the global widget shape.
#define N_GUI_WIN_HSCROLL_DRAG
window horizontal auto-scrollbar is being dragged
void n_gui_checkbox_set_bitmaps(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *box, ALLEGRO_BITMAP *box_checked, ALLEGRO_BITMAP *box_hover)
Set optional bitmap overlays on a checkbox widget.
int n_gui_sectionlist_add_widget(N_GUI_SECTIONLIST *sl, int section_index, int widget_id)
register an existing widget as a member of a section (captures its current y as the fold offset).
#define N_GUI_TREE_PATH_SEP
separator joining the labels of a node path.
void n_gui_listbox_set_scroll_offset(N_GUI_CTX *ctx, int widget_id, int offset)
set the scroll offset (in items), clamps to valid range
float n_gui_progressbar_get_value(N_GUI_CTX *ctx, int widget_id)
get the current progress fraction (0.0 on an invalid widget)
int n_gui_sectionlist_get_count(const N_GUI_SECTIONLIST *sl)
number of sections in the list
#define N_GUI_TEXT_MAX
maximum length for textarea content
#define N_GUI_STATE_IDLE
widget is idle / normal state
void n_gui_textarea_scroll_to_bottom(N_GUI_CTX *ctx, int widget_id)
scroll a multiline textarea to the bottom
size_t n_gui_textarea_get_text_length(N_GUI_CTX *ctx, int widget_id)
return the current text length in bytes
#define N_GUI_GLYPH_COUNT
number of defined glyphs, for range checks
void n_gui_open_window(N_GUI_CTX *ctx, int window_id)
Open (show) a window.
int n_gui_window_get_zvalue(N_GUI_CTX *ctx, int window_id)
Get window z-value (for N_GUI_ZORDER_FIXED mode).
ALLEGRO_DISPLAY * n_gui_window_get_display(N_GUI_CTX *ctx, int window_id)
Get the native display backing a window, or NULL when it is a pop-up.
int n_gui_textarea_has_selection(N_GUI_CTX *ctx, int widget_id)
is any text selected in a text area
#define N_GUI_WIN_BTN_MAXIMIZE
enable maximize/restore button on the title bar
int n_gui_get_key_modifiers(const N_GUI_CTX *ctx)
the modifier keys held down now, as the GUI has seen them
int n_gui_sectionlist_add_section(N_GUI_SECTIONLIST *sl, const char *title, float header_y, int folded)
add a section with a header button at header_y (members added next are captured relative to it); retu...
void n_gui_dropmenu_set_entry_text(N_GUI_CTX *ctx, int widget_id, int index, const char *text)
Update text of an existing entry.
void n_gui_window_set_content_draw_callback(N_GUI_CTX *ctx, int window_id, void(*on_content_draw)(int, void *), void *user_data)
Set the content-draw callback for a window.
int n_gui_tree_add_node(N_GUI_TREE *tree, const char *label, int parent_index, void *user_data)
add a node to the tree
#define N_GUI_WIN_BTN_CLOSE
enable close button on the title bar
int n_gui_listbox_get_count(N_GUI_CTX *ctx, int widget_id)
get the number of items in a listbox widget
int n_gui_sectionlist_is_section_hidden(const N_GUI_SECTIONLIST *sl, int section_index)
Is a section left out of the stack.
int n_gui_window_set_native_icons(N_GUI_CTX *ctx, int window_id, ALLEGRO_BITMAP **icons, int num_icons)
Give a detached window's OS window a taskbar / title bar icon.
void n_gui_dropmenu_set_label(N_GUI_CTX *ctx, int widget_id, const char *label)
Replace the button label shown on a dropmenu.
void n_gui_custom_set_destroy(N_GUI_CTX *ctx, int widget_id, void(*destroy)(void *user_data))
hand a custom widget's paint user pointer to the widget
int n_gui_sectionlist_get_order(const N_GUI_SECTIONLIST *sl, int position)
The section stacked at a position.
void n_gui_tree_draw_overlay(N_GUI_TREE *tree)
per-frame overlay drawing: draws the active drop-indicator on top of the listbox.
const char * n_gui_checkbox_get_label(N_GUI_CTX *ctx, int widget_id)
What a checkbox says.
#define N_GUI_TRUNCATE_PATH
a path too wide for its box loses whole leading components, ".../photos/IMG_0001.CR3",...
float n_gui_markdownview_content_height(N_GUI_CTX *ctx, int widget_id)
the height of the whole document at the width it was last drawn at, or 0 before the first draw
void n_gui_close_menus(N_GUI_CTX *ctx)
Put away any open combo box list or drop menu panel.
const char * n_gui_combobox_get_item_text(N_GUI_CTX *ctx, int widget_id, int index)
get the text of the combobox item at index ("" if out of range / not a combobox)
int n_gui_count_detached(N_GUI_CTX *ctx)
Count the windows currently detached into native OS windows.
#define N_GUI_WIN_NO_HSCROLL
with N_GUI_WIN_AUTO_SCROLLBAR, never show the horizontal scrollbar (vertical-only scrolling): content...
#define N_GUI_ZORDER_POPUP
popup/modal dialogs: drawn above EVERYTHING including ALWAYS_ON_TOP windows.
int n_gui_textarea_suggest_is_open(N_GUI_CTX *ctx, int widget_id)
is a textarea's completion panel up
void n_gui_dropmenu_set_flags(N_GUI_CTX *ctx, int widget_id, int flags)
Set dropmenu feature flags (bitmask of N_GUI_DROPMENU_* values).
int n_gui_get_cursor(N_GUI_CTX *ctx, ALLEGRO_MOUSE_CURSOR **custom)
The cursor the GUI last applied to the display.
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.
void n_gui_splitpane_set_ratio(N_GUI_CTX *ctx, int widget_id, float ratio)
set the divider ratio of a split pane (clamped to its min/max)
int n_gui_checkbox_is_checked(N_GUI_CTX *ctx, int widget_id)
check if a checkbox widget is checked
int n_gui_label_get_truncate(N_GUI_CTX *ctx, int widget_id)
a label's truncate mode
#define N_GUI_WIN_RESIZE_MOVE
reposition proportionally, keep pixel size
void n_gui_splitpane_set_limits(N_GUI_CTX *ctx, int widget_id, float min_ratio, float max_ratio)
set the minimum and maximum allowed divider ratio of a split pane
#define N_GUI_STATE_ACTIVE
widget is being pressed / dragged
void n_gui_set_default_theme(N_GUI_CTX *ctx, N_GUI_THEME theme)
Set the default theme on a context and sync scrollbar style colors.
int n_gui_combobox_get_selected(N_GUI_CTX *ctx, int widget_id)
get the selected item index in a combobox widget
void n_gui_tree_remove_node(N_GUI_TREE *tree, int node_index)
remove a node and its entire subtree; remaining node indices are compacted (callers holding indices a...
void n_gui_image_set_bitmap(N_GUI_CTX *ctx, int widget_id, ALLEGRO_BITMAP *bitmap)
set the bitmap of an image widget
const char * n_gui_button_get_label(N_GUI_CTX *ctx, int widget_id)
What a button says.
int n_gui_tree_state_save(const N_GUI_TREE *tree, N_GUI_TREE_STATE *out)
capture which nodes are expanded, which one is selected, and where the view is scrolled,...
int n_gui_load_layout_json(N_GUI_CTX *ctx, const char *filepath)
load a JSON window layout file and apply it to matching windows
int n_gui_window_is_maximised(N_GUI_CTX *ctx, int window_id)
Check if a window is currently maximised.
int n_gui_datagrid_add_row(N_GUI_CTX *ctx, int widget_id, const char **values)
append a row of cell strings (values must have one entry per column); returns the row index or -1
void n_gui_syntaxview_set_text(N_GUI_CTX *ctx, int widget_id, const char *text)
set (copy) the text shown by a syntax view
void n_gui_slider_set_value(N_GUI_CTX *ctx, int widget_id, double value)
set the value of a slider widget
#define N_GUI_AUTOFIT_EXPAND_UP
expand upward instead of downward when adjusting height
#define N_GUI_SHAPE_BITMAP
bitmap-based rendering
#define N_GUI_SHAPE_ROUNDED
rounded rectangle shape
#define N_GUI_ALIGN_RIGHT
right aligned text
int n_gui_datagrid_get_sort(N_GUI_CTX *ctx, int widget_id, int *col, int *dir)
read back the sort a datagrid is currently showing.
#define N_GUI_GLYPH_MINUS
minus sign
void n_gui_tree_set_expand_callback(N_GUI_TREE *tree, void(*on_expand)(int node_index, void *user_data), void *user_data)
set the callback that fills a node the first time it is opened, for a tree too large to build before ...
int n_gui_sectionlist_is_folded(const N_GUI_SECTIONLIST *sl, int section_index)
query a section's folded state (1 = folded, 0 = expanded)
void n_gui_datagrid_set_column_width(N_GUI_CTX *ctx, int widget_id, int col, float width)
set the pixel width of physical column col (clamped to a small minimum)
void n_gui_syntaxview_scroll_to_offset(N_GUI_CTX *ctx, int widget_id, int byte_offset)
scroll a syntax view so the line holding a byte offset is vertically centered, and horizontally so th...
#define N_GUI_AUTOFIT_H
auto-adjust window height to content
void n_gui_datagrid_set_column_visible(N_GUI_CTX *ctx, int widget_id, int col, int visible)
show (1) or hide (0) physical column col; hidden columns keep their cells but are skipped in the head...
void n_gui_sectionlist_set_first_inset(N_GUI_SECTIONLIST *sl, float inset)
set a left inset applied to the FIRST section's header only, so a caller can place a button before it...
void n_gui_sectionlist_set_section_hidden(N_GUI_SECTIONLIST *sl, int section_index, int hidden)
Leave a whole section out of the stack, header and members, or put it back.
void n_gui_radiolist_set_selected(N_GUI_CTX *ctx, int widget_id, int index)
set the selected item in a radiolist widget
void n_gui_window_set_flags(N_GUI_CTX *ctx, int window_id, int flags)
Set feature flags on a window.
float n_gui_syntaxview_content_width(N_GUI_CTX *ctx, int widget_id)
pixel width the widest line of a syntax view needs, padding included
void(* N_GUI_SUGGEST_FN)(const char *prefix, N_GUI_SUGGEST_SINK *sink, void *user_data)
asked for the completions of what has been typed so far
#define N_GUI_KEY_MOD_MASK
mask of supported modifier flags for button keybind matching
int n_gui_combobox_remove_item(N_GUI_CTX *ctx, int widget_id, int index)
remove an item from a combobox widget
#define N_GUI_ALIGN_JUSTIFIED
justified text (spread words to fill width)
void n_gui_set_widget_visible(N_GUI_CTX *ctx, int widget_id, int visible)
Show or hide a widget.
void n_gui_syntaxview_select_all(N_GUI_CTX *ctx, int widget_id)
select the entire text of a syntax view
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_mark_dirty(N_GUI_CTX *ctx)
Mark the GUI as needing a redraw.
#define N_GUI_ID_MAX
maximum length for widget id/name strings
N_GUI_STYLE n_gui_default_style(void)
Build sensible default style (all configurable sizes, colours, paddings).
#define N_GUI_SUGGEST_VISIBLE
most completions a suggestion panel shows at once.
#define N_GUI_TAB_MAX
maximum number of tabs in a single tab panel
void n_gui_datagrid_clear_row_colors(N_GUI_CTX *ctx, int widget_id)
remove every row background tint (the rows and cells are kept)
#define N_GUI_AUTOFIT_W
auto-adjust window width to content
void n_gui_window_set_maximize_callback(N_GUI_CTX *ctx, int window_id, void(*on_maximize)(int, void *), void *user_data)
Set the maximize button callback for a 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.
void n_gui_scrollbar_set_sizes(N_GUI_CTX *ctx, int widget_id, double content_size, double viewport_size)
set the content and viewport sizes of a scrollbar widget
#define N_GUI_WIN_AUTO_SCROLLBAR
enable automatic scrollbars when content exceeds window size
#define N_GUI_WIN_RESIZING
window is being resized
int n_gui_window_from_display(N_GUI_CTX *ctx, ALLEGRO_DISPLAY *display)
Find the window detached into a given display.
void n_gui_set_cursor(N_GUI_CTX *ctx, int system_shape, ALLEGRO_MOUSE_CURSOR *custom)
Say which mouse cursor the application wants.
void n_gui_markdownview_set_fonts(N_GUI_CTX *ctx, int widget_id, const N_GUI_MD_FONTS *fonts)
replace the faces; the new ones are borrowed on the same terms
#define N_GUI_RESIZE_ADAPTIVE
virtual size tracks display; windows adapt per their resize_policy
int n_gui_menu_is_open(const N_GUI_CTX *ctx)
Is a combo box's list or a drop menu's panel currently open.
float n_gui_splitpane_band(N_GUI_CTX *ctx, int widget_id)
How far either side of a split pane's divider a press still counts as the divider's.
void n_gui_tree_expand(N_GUI_TREE *tree, int node_index)
open a node, filling it first through the expand callback if it has not been; a node already open sta...
void n_gui_textarea_set_placeholder(N_GUI_CTX *ctx, int widget_id, const char *text)
Set placeholder/hint text shown dimmed while a textarea is empty.
int n_gui_add_textarea(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, int multiline, size_t char_limit, void(*on_change)(int, const char *, void *), void *user_data)
Add a text area widget.
void n_gui_sectionlist_free(N_GUI_SECTIONLIST **sl)
free the section list (does not destroy the N_GUI widgets or window)
void n_gui_textarea_suggest_close(N_GUI_CTX *ctx, int widget_id)
put a textarea's completion panel away
#define N_GUI_TYPE_LISTBOX
widget type: listbox (selectable list)
float n_gui_slider_value_width(N_GUI_CTX *ctx, int widget_id)
width in pixels a slider's built-in readout needs beside it, the gap between track and text included.
int n_gui_datagrid_get_selected(N_GUI_CTX *ctx, int widget_id)
get the selected row index, or -1 if none
int n_gui_listbox_is_selected(N_GUI_CTX *ctx, int widget_id, int index)
check if a listbox item is selected
void n_gui_window_update_normalized(N_GUI_CTX *ctx, int window_id)
Recapture normalized coordinates for a window from its current absolute position/size.
#define N_GUI_SYNTAX_YAML
syntax view: YAML highlighting (keys, quoted values, list markers, comments)
int n_gui_add_checkbox(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, int initial_checked, void(*on_toggle)(int, int, void *), void *user_data)
Add a checkbox widget.
void n_gui_combobox_clear(N_GUI_CTX *ctx, int widget_id)
remove all items from a combobox widget
void n_gui_sectionlist_relayout(N_GUI_SECTIONLIST *sl)
re-stack all sections from y0 by current fold state: hide folded members, show and reposition expande...
#define N_GUI_SYNTAX_JS
syntax view: JavaScript highlighting (keywords, strings, numbers, comments)
int n_gui_was_double_click(const N_GUI_CTX *ctx, int widget_id)
whether the press just processed double clicked this widget
int n_gui_datagrid_get_column_visible(N_GUI_CTX *ctx, int widget_id, int col)
whether physical column col is visible (1) or hidden (0); 0 if out of range
#define N_GUI_SHAPE_RECT
rectangle shape (default)
void n_gui_combobox_set_selected(N_GUI_CTX *ctx, int widget_id, int index)
set the selected item in a combobox widget
int n_gui_listbox_remove_item(N_GUI_CTX *ctx, int widget_id, int index)
remove an item from a listbox widget
#define N_GUI_SCROLLBAR_V
vertical scrollbar
N_GUI_THEME n_gui_make_theme(ALLEGRO_COLOR bg, ALLEGRO_COLOR bg_hover, ALLEGRO_COLOR bg_active, ALLEGRO_COLOR border, ALLEGRO_COLOR border_hover, ALLEGRO_COLOR border_active, ALLEGRO_COLOR text, ALLEGRO_COLOR text_hover, ALLEGRO_COLOR text_active, float border_thickness, float corner_rx, float corner_ry)
Create a custom theme with explicit colours.
int n_gui_add_dropmenu(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, void(*on_open)(int, void *), void *on_open_user_data)
Add a dropdown menu widget.
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_datagrid(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, void(*on_select)(int, int, void *), void *user_data)
Add a sortable data grid widget.
void n_gui_screen_to_virtual(const N_GUI_CTX *ctx, float sx, float sy, float *vx, float *vy)
Convert physical screen coordinates to virtual canvas coordinates.
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.
size_t n_gui_hexview_get_cursor(N_GUI_CTX *ctx, int widget_id)
the byte offset the edit cursor sits on
void n_gui_set_event_queue(N_GUI_CTX *ctx, ALLEGRO_EVENT_QUEUE *queue)
Set the event queue used to register native window event sources.
int n_gui_add_custom(N_GUI_CTX *ctx, int window_id, float x, float y, float w, float h, N_GUI_CUSTOM_DRAW draw, void *user_data)
add an owner-draw custom widget; returns the widget id or -1
#define N_GUI_KEY_SOURCES_MAX
maximum number of source widgets for a focused key binding
const char * n_gui_label_get_text(N_GUI_CTX *ctx, int widget_id)
What a label says now.
#define N_GUI_WIN_RESIZABLE
enable user-resizable window with a drag handle at bottom-right
#define N_GUI_STATE_FOCUSED
widget has keyboard focus
void n_gui_tree_tick(N_GUI_TREE *tree)
per-frame poll: reads ctx->mouse_* to track drag state and fires the on_drop callback on release.
#define N_GUI_WIN_DRAGGING
window is being dragged
void n_gui_reset_all_widget_themes(N_GUI_CTX *ctx)
Reset all widget and window themes to ctx->default_theme.
#define N_GUI_TYPE_TEXTAREA
widget type: text area
#define N_GUI_GLYPH_ARROW_LEFT
filled triangle pointing left
void n_gui_window_set_autofit(N_GUI_CTX *ctx, int window_id, int autofit_flags, float border)
Configure auto-fit behavior for a dialog window.
int n_gui_widget_is_visible(N_GUI_CTX *ctx, int widget_id)
Is a widget currently shown.
void n_gui_scrollbar_set_pos(N_GUI_CTX *ctx, int widget_id, double pos)
set the scroll position of a scrollbar widget
void n_gui_dropmenu_clear_dynamic(N_GUI_CTX *ctx, int widget_id)
Remove all dynamic entries (keep static ones).
The top-level GUI context that holds all windows.
Owner-draw custom widget data: a paint callback, an optional mouse callback, and their user pointers.
one data grid column definition
data grid specific data: a sortable column table
dropdown menu specific data
A single entry in a dropdown menu (static or dynamic).
hex viewer specific data: a read-only byte dump
image widget specific data
a single row in the KV table
key-value table built from textareas, checkboxes, and buttons.
static text label specific data
a single item in a list/radio/combo widget
markdownview specific data.
A mouse event handed to a custom widget, in the widget's own coordinates.
A saved window position retained for a window not yet created at load time (see N_GUI_CTX::pending_la...
Saved user-adjustable state for a keyed widget that did not exist when the layout was loaded (a lazil...
Progress-bar widget data (display only).
Where a scrollbar a widget draws inside itself was last painted, and whether the pointer is on it.
a single foldable section: a clickable header plus the member widgets it shows/hides
a vertical accordion of foldable sections inside one window; folding hides a section's widgets and re...
split pane specific data: a draggable divider between two regions
Global style holding every configurable layout constant.
syntax view specific data: read-only highlighted text
tab panel built from toggle buttons with content window management
Titlebar button state for a window (minimize, maximize, close).
bounding box dimensions returned by n_gui_get_text_dims()
Color theme for a widget.
tree view built from an N_GUI listbox
a single node in the tree view
A tree's view state, captured by path so it survives a rebuild that replaces every node (a reloaded m...
A pseudo window that contains widgets.
int ht_get_ptr(HASH_TABLE *table, const char *key, void **val)
get pointer at 'key' from 'table'
int destroy_ht(HASH_TABLE **table)
empty a table and destroy it
HASH_TABLE * new_ht(size_t size)
Create a hash table with the given size.
int ht_put_ptr(HASH_TABLE *table, const char *key, void *ptr, void(*destructor)(void *ptr), void *(*duplicator)(void *ptr))
put an arbitrary pointer value with given key in the targeted hash table
LIST_NODE * end
pointer to the end of the list
void * ptr
void pointer to store
struct LIST_NODE * prev
pointer to the previous node
LIST_NODE * start
pointer to the start of the list
size_t nb_items
number of item currently in the list
void(* destroy_func)(void *ptr)
pointer to destructor function if any, else NULL
#define UNLIMITED_LIST_ITEMS
flag to pass to new_generic_list for an unlimited number of item in the list.
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper, safe for node removal during iteration.
int list_unshift(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer at the start of the list.
int list_destroy(LIST **list)
Empty and Free a list container.
void * remove_list_node_f(LIST *list, LIST_NODE *node)
Internal function called each time we need to get a node out of a list.
LIST * new_generic_list(size_t max_items)
Initialiaze a generic list container to max_items pointers.
Structure of a generic list node.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_DEBUG
debug-level messages
#define LOG_ERR
error conditions
#define LOG_NOTICE
normal but significant condition
#define LOG_WARNING
warning conditions
int n_clipboard_set(int which, const char *text)
Own which selection and serve text to any app that requests it.
int n_clipboard_available(void)
Whether a real clipboard backend (X11 or Win32) is active on this platform.
char * n_clipboard_get(int which)
Fetch the current text of which selection from its owner.
void n_clipboard_destroy(void)
Stop the backend thread and release the display connection.
System clipboard: full X11 selection support on Linux, Win32 clipboard on Windows/MinGW.
#define N_CLIPBOARD_PRIMARY
the X11 PRIMARY selection (mouse select-to-copy / middle-click paste); a no-op on Windows,...
#define N_CLIPBOARD_CLIPBOARD
the Ctrl+C / Ctrl+V clipboard selection
static void _draw_justified_selection(ALLEGRO_FONT *font, float x, float y, float max_w, float max_h, const char *text, int sel_start, int sel_end, ALLEGRO_COLOR sel_color)
helper: draw selection highlight rectangles over justified/wrapped text.
static int _n_gui_tree_hit_row(N_GUI_TREE *tree, float mx, float my, int *out_node_idx, int *out_drop_pos)
Hit-test the mouse against the listbox's visible rows and fill the out params.
static size_t _textarea_pos_from_mouse(const N_GUI_TEXTAREA_DATA *td, ALLEGRO_FONT *font, float mx, float my, float ax, float ay, float widget_w, float widget_h, float pad, float scrollbar_size)
helper: find the byte position in a textarea closest to the given mouse coordinates (mx,...
static void _slider_update_from_mouse(N_GUI_WIDGET *wgt, float mx, float my, float win_x, float win_content_y, const N_GUI_STYLE *style)
handle slider drag (horizontal or vertical)
static void _draw_textarea_suggest(N_GUI_CTX *ctx)
draw the open completion panel (called after all windows, with the other floating overlays)
static int _opt_rounded(const N_GUI_STYLE *style)
the widget types that have no shape of their own (textarea, checkbox, a frameless window's body,...
static float _text_w(ALLEGRO_FONT *font, const char *text)
helper: get the advance width of text.
static int _suggest_panel_rect(N_GUI_CTX *ctx, N_GUI_WIDGET *wgt, float *out_x, float *out_y, float *out_w, float *out_h, float *out_ih, int *out_vis)
the geometry of an open completion panel, so the draw and the pointer agree about where its rows are.
static int _n_gui_kv_active_order(const N_GUI_KVTABLE *table, int *out)
static ALLEGRO_COLOR _syntax_diff_add(void)
unified diff line colours.
static void _n_gui_sectionlist_header_clicked(int widget_id, void *user_data)
static void _register_widget(N_GUI_CTX *ctx, N_GUI_WIDGET *w)
helper: register a widget in the hash table
ALLEGRO_COLOR outline
outline drawn round the thumb in every state, on top of which the state outline still applies.
static float _json_get_float(cJSON *parent, const char *name, float fallback)
helper: read a float from JSON, return fallback if missing
static int _splitpane_hit(N_GUI_CTX *ctx, float px, float py)
report the split pane whose divider band is under a point, or -1.
static N_GUI_WINDOW * _find_focused_window(N_GUI_CTX *ctx)
helper: find the window containing a focused widget
static void _syntaxview_clamp_h(N_GUI_SYNTAXVIEW_DATA *yd, float content_w, float pane_w)
forward declaration: clamp a syntaxview's horizontal scroll to its content.
static ALLEGRO_COLOR _bg_for_state(const N_GUI_THEME *t, int state)
helper: pick colour based on widget state
const n_wrap_item * items
static void _n_gui_apply_display_size(N_GUI_CTX *ctx, float w, float h)
Draw all visible windows and their widgets.
static void _n_gui_tree_listbox_selected(int widget_id, int index, int selected, void *user_data)
#define _N_GUI_TREE_DRAG_THRESHOLD_PX
pixels of mouse movement before a press becomes a drag
static void _draw_text_truncated(ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, float max_w, const char *text)
helper: draw text truncated to a maximum pixel width.
static int _label_line_count(const char *text)
forward declarations: the lines of a label whose text has line breaks, used by n_gui_label_fits().
static int _suggest_handle_key(N_GUI_CTX *ctx, N_GUI_WIDGET *wgt, ALLEGRO_EVENT *ev)
the keys a completion panel takes before the textarea sees them.
float x_min
left edge of the visible area
static float _label_wrap_w(const N_GUI_WIDGET *wgt, const N_GUI_STYLE *style)
forward declaration: the width a justified label wraps its text to.
static int _native_monitor_info(ALLEGRO_DISPLAY *display, ALLEGRO_MONITOR_INFO *info)
helper: the monitor rectangle a native window sits on.
static int _splitpane_on_divider(const N_GUI_WIDGET *wgt, float px, float py, float ax, float ay)
forward declaration: test whether a point falls on a split pane's draggable divider band.
#define N_GUI_MEAS_KEY_MAX
#define _N_GUI_HELD_LSHIFT
static float _tb_buttons_area_width(const N_GUI_WINDOW *win, const N_GUI_STYLE *style)
compute the total width consumed by enabled titlebar buttons (0 if none/frameless)
static int _scrollbar_wheel(N_GUI_WIDGET *wgt, int dz)
helper: turn the wheel over a scrollbar: its wheel step per notch, a twentieth of its range when it h...
static int _custom_mouse(const N_GUI_CTX *ctx, N_GUI_WIDGET *wgt, int type, int button, float local_x, float local_y, int dz)
helper: hand a mouse event to a custom widget that takes them.
static void _draw_label_lines(ALLEGRO_FONT *font, ALLEGRO_COLOR tc, float ax, float ay, float effective_w, float h, float pad, const N_GUI_LABEL_DATA *lb, ALLEGRO_COLOR sel_color)
helper: draw a LEFT, CENTER or RIGHT label whose text has line breaks, one line under another,...
static void _draw_textarea(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, N_GUI_STYLE *style)
draw a textarea widget
static ALLEGRO_DISPLAY * _event_display(const ALLEGRO_EVENT *event)
helper: the display an event originates from, or NULL when the event carries no display (timer,...
static void _normalize_crlf(char *s)
helper: strip CR from a string in-place, normalizing CRLF to LF.
static int _hexview_insert(N_GUI_HEXVIEW_DATA *hd)
insert one zero byte before the cursor of an editable hex view.
static void _draw_progressbar(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, N_GUI_STYLE *style)
static void _listbox_hmetrics(const N_GUI_WIDGET *wgt, const N_GUI_LISTBOX_DATA *ld, ALLEGRO_FONT *font, const N_GUI_STYLE *style, float *content_w, float *pane_w, int *need_hsb, int *visible)
Listbox horizontal-scroll metrics, computed identically by the draw path and the mouse handlers so th...
static int _is_focusable_type(int type)
helper: check if a widget type takes keys once it has focus.
ALLEGRO_COLOR track
track fill
static int _wrap_words(const float *word_widths, const int *nl_before, int nwords, float space_w, float max_w, int *line_first, unsigned char *para_end, int max_lines)
helper: pack word widths into justified lines.
static void _draw_rows_scrollbar(float ax, float ay, float w, float h, int nb_rows, int visible, int scroll_offset, N_GUI_SB_TRACK *track, const N_GUI_STYLE *style, const N_GUI_THEME *theme)
draw a row-indexed vertical scrollbar (shared by hexview, syntaxview, datagrid, listbox and radiolist...
static void _listbox_clamp_h(N_GUI_LISTBOX_DATA *ld, float content_w, float pane_w)
clamp a listbox's horizontal scroll to the room its content actually needs
static void _draw_widget_vscrollbar(float area_x, float area_y, float area_w, float view_h, float content_h, float scroll_y, N_GUI_SB_TRACK *track, const N_GUI_STYLE *style, const N_GUI_THEME *theme)
helper: draw a mini vertical scrollbar inside a widget, at the right edge of the area [area_x .
static void _draw_slider(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, N_GUI_STYLE *style)
static void _draw_image(N_GUI_WIDGET *wgt, float ox, float oy)
draw an image widget
static int _splitpane_cursor_hover(N_GUI_CTX *ctx, float px, float py)
report the split-pane divider under a point, for the mouse cursor shape: 0 = none,...
static int _zorder_group(const N_GUI_WINDOW *w)
static void _n_gui_kv_content_free(N_GUI_KV_CONTENT *c)
static void _draw_themed_rect(N_GUI_THEME *t, int state, float x, float y, float w, float h, int rounded)
draw a themed rectangle or rounded rectangle.
static float _label_effective_w(const N_GUI_LABEL_DATA *lb, ALLEGRO_FONT *font, float wgt_w, float win_w, float wgt_x, float label_padding)
helper: the width a LEFT, CENTER or RIGHT label lays its text out in.
static float _combobox_dropdown_width(N_GUI_CTX *ctx, const N_GUI_COMBOBOX_DATA *cd, ALLEGRO_FONT *font, float widget_w, float ax, float pad)
helper: the effective width of an open combobox dropdown panel.
static void _draw_dropmenu(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, const N_GUI_STYLE *style)
draw a dropdown menu button (closed state)
static float _label_content_height(const char *text, ALLEGRO_FONT *font, float max_w)
forward declaration: height the wrapped text of a justified label needs at a given width.
static int _syntax_js_regex_possible(char c)
whether a '/' may start a regex literal after last significant char c (start of line,...
static int _combobox_index_after_remove(int index, int removed)
shift an index that pointed into a list one item shorter now
static float _slider_handle_r(const N_GUI_WIDGET *wgt, const N_GUI_STYLE *style)
Radius of a slider's handle, from the widget's short side.
static int _hexview_reserve(N_GUI_HEXVIEW_DATA *hd, size_t need)
grow an editable hex view's buffer so it can hold at least need bytes.
static N_GUI_WINDOW * _find_widget_window(N_GUI_CTX *ctx, int wgt_id, float *ox, float *oy)
helper: find the parent window of a widget by id, returning the window's content origin (accounting f...
int clen
bytes consumed by this character (1 for a newline)
static void _tb_button_action(N_GUI_CTX *ctx, N_GUI_WINDOW *win, int btn_type)
Dispatch a titlebar button action, invoke the user callback if set, otherwise fall back to the built-...
static ALLEGRO_BITMAP * _select_state_bitmap(int state, ALLEGRO_BITMAP *normal_bmp, ALLEGRO_BITMAP *hover_bmp, ALLEGRO_BITMAP *active_bmp)
helper: select per-state bitmap with fallback chain.
static float _markdownview_text_w(const N_GUI_WIDGET *wgt, const N_GUI_MARKDOWNVIEW_DATA *md, const N_GUI_STYLE *style, int with_bar)
The width the document is laid out at: the widget less its padding, and less the bar when there is on...
static int _datagrid_resize_hover(N_GUI_CTX *ctx, float px, float py)
Whether the pointer at (px,py) rests on a datagrid column-resize border: the header row of a visible ...
static void _datagrid_header_hit(const N_GUI_DATAGRID_DATA *gd, float ax, float x, int *border_col, int *cell_col)
helper: what a datagrid header row is offering at x.
float cx
pen x, advanced by the width of each run
static void _slider_travel(const N_GUI_WIDGET *wgt, const N_GUI_STYLE *style, float *start, float *length)
The strip a slider's handle centre travels along, inset by its radius at each end.
static void _win_auto_sb_rects(N_GUI_WINDOW *win, ALLEGRO_FONT *font, float size, float v[4], float h[4])
helper: where a window's automatic scrollbars are, in display coordinates.
static void _native_drag_begin(N_GUI_WINDOW *win)
helper: anchor an own-chrome window's title bar drag on the desktop cursor.
static float _label_text_origin_x(const N_GUI_LABEL_DATA *lb, ALLEGRO_FONT *font, float ax, float wgt_w, float win_w, float wgt_x, float label_padding)
helper: compute the screen-space x origin where label text starts, accounting for alignment.
static int _n_gui_sectionlist_slot(const N_GUI_SECTIONLIST *sl, int section_index, int widget_id)
static int _syntaxview_offset_from_mouse(const N_GUI_SYNTAXVIEW_DATA *yd, ALLEGRO_FONT *font, float mx, float my, float ax, float ay, float pad)
Map a mouse position over a syntax view to a byte offset into its text.
static void _draw_scrollbar_thumb(float x, float y, float w, float h, int state, const _N_GUI_SB_SKIN *skin, const N_GUI_THEME *theme)
Draw the thumb of a scrollbar, in the state its owner is in.
static void _set_clipping_rect_transformed(int wx, int wy, int ww, int wh)
helper: set clipping rectangle in world space, transforming to screen space.
static void _n_gui_kv_up_clicked(int widget_id, void *user_data)
static void _n_gui_kv_apply_layout(N_GUI_KVTABLE *table)
static void _n_gui_kv_dup_clicked(int widget_id, void *user_data)
static void _datagrid_ensure_sel(N_GUI_DATAGRID_DATA *gd)
helper: ensure the per-row selection array exists, sized to rows_cap
static void _draw_dropmenu_panel(N_GUI_CTX *ctx)
draw the dropdown menu panel overlay (called after all windows)
static int _hexview_digit(int keycode, int unichar)
the value of a hex digit key (0-15), or -1 when the key is not one.
static int _win_on_pass(const N_GUI_CTX *ctx, const N_GUI_WINDOW *win)
helper: whether a window takes part in the pass currently being processed or drawn.
static void _syntax_draw_line(ALLEGRO_FONT *font, N_GUI_THEME *th, float x, float y, const char *s, int n, int mode, int line_idx, int in_headers, float x_min, float x_max)
draw one text line with mode-specific highlighting starting at (x,y), inside the horizontal window [x...
static N_GUI_MARKDOWNVIEW_DATA * _markdownview_of(N_GUI_CTX *ctx, int widget_id)
The view's data, or NULL when that widget is not one.
static void _draw_widget(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, float win_w, N_GUI_STYLE *style)
float track_inset
see track_round
static int _native_own_chrome(const N_GUI_WINDOW *win)
helper: whether a window is detached AND keeps drawing its own chrome (N_GUI_DETACH_OWN_CHROME).
static ALLEGRO_DISPLAY * _ctx_io_display(const N_GUI_CTX *ctx)
helper: the display to use for clipboard and mouse-cursor calls.
static void _window_update_content_size(N_GUI_WINDOW *win, ALLEGRO_FONT *default_font)
helper: recompute content extents for a window (for scrollbar support)
static void _draw_glyph(int glyph, float cx, float cy, float s, ALLEGRO_COLOR fg, ALLEGRO_COLOR bg, float thick)
draw a button widget
static _N_GUI_TA_STEP _textarea_step(const char *text, size_t len, size_t i, ALLEGRO_FONT *font, float cx, float wrap_limit, float line_x0)
helper: decode, measure and wrap-test one character of textarea text.
static void _n_gui_window_capture_normalized(const N_GUI_CTX *ctx, N_GUI_WINDOW *win)
capture normalized coords for a window and its widgets from current absolutes
static void _draw_textarea_placeholder(const N_GUI_TEXTAREA_DATA *td, const N_GUI_WIDGET *wgt, ALLEGRO_FONT *font, float tx, float ty)
draw a textarea's placeholder/hint at (tx,ty), dimmed, while the field is empty; a no-op once any tex...
static void _draw_scrollbar_body(float bar_x, float bar_y, float bar_w, float bar_h, float thumb_off, float thumb_len, int vertical, int state, N_GUI_SB_TRACK *track, const _N_GUI_SB_SKIN *skin, const N_GUI_THEME *theme)
Draw one whole scrollbar: track, divider and thumb.
static int _widget_took_press(const N_GUI_WIDGET *wgt)
helper: did the press just handled by wgt belong to it?
int done
1 once the pen passed x_max, so the tokenizer stops walking the line
static int _label_lines_char_at(const N_GUI_LABEL_DATA *lb, ALLEGRO_FONT *font, float ax, float ay, float effective_w, float h, float pad, float mx, float my)
helper: the byte offset in a multi-line label closest to a click.
static int _shape_rounded(const N_GUI_STYLE *style, int widget_shape)
resolve whether a shape-aware widget draws rounded: the global shape_mode override (style->shape_mode...
static float _min_thickness(float requested)
helper: compute minimum line thickness so it stays >= 1 physical pixel.
static float _scrollbar_calc_scroll(float mouse, float track_start, float track_length, float viewport, float content, float thumb_min)
helper: compute scroll position from mouse coordinate using thumb-aware math.
static float _tb_btn_resolved_size(const N_GUI_WINDOW *win, const N_GUI_STYLE *style)
return the effective titlebar button size (0 = auto from titlebar_h)
static void _n_gui_kv_split_b_changed(int widget_id, float ratio, void *user_data)
static int _syntax_js_regex_kw(const char *s, int n)
whether the n bytes at s are a keyword after which an expression (and therefore a regex literal) can ...
static void _textarea_clear_selection(N_GUI_TEXTAREA_DATA *td)
clear the selection (set both anchors to cursor_pos)
static void _release_native_window(N_GUI_CTX *ctx, N_GUI_WINDOW *win)
forward declaration: unregister and destroy a window's native display, leaving the window's geometry ...
static int _text_line_count(const char *s)
helper: destroy a single widget (called by list destructor)
static void _draw_scrollbar(N_GUI_WIDGET *wgt, float ox, float oy, const N_GUI_STYLE *style)
draw a scrollbar widget.
static void _textarea_sel_range(const N_GUI_TEXTAREA_DATA *td, size_t *lo, size_t *hi)
get the ordered selection range (lo, hi)
ALLEGRO_FONT * font
font every run of the line is drawn with
static int _button_neighbour(N_GUI_CTX *ctx, const N_GUI_WIDGET *from, int forward)
The button before or after one, in its window, in reading order.
static int _is_tab_focusable_type(int type)
helper: check if a widget type is reached by Tab and Shift+Tab: every widget that takes keys,...
float thumb_padding
inset of the thumb across the bar
static void _draw_scrollbar_track(float bar_x, float bar_y, float bar_w, float bar_h, int vertical, int state, const _N_GUI_SB_SKIN *skin, const N_GUI_THEME *theme)
Draw the track of a scrollbar: the one look every bar shares.
static FILE * _gui_fopen_write(const char *path, const char *mode)
#define N_GUI_COLRESIZE_GRAB
grab zone, in pixels either side of a column's right border
#define _N_GUI_HELD_RCTRL
static char * _ngui_clip_get(ALLEGRO_DISPLAY *display, int which)
static void _sort_windows_by_zorder(N_GUI_CTX *ctx)
Sort windows list by z-order: ALWAYS_BEHIND first, then FIXED (by z_value), then NORMAL,...
float cw
its pixel width (0 for a newline)
static void _draw_custom(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font)
draw a single widget.
ALLEGRO_COLOR thumb
thumb fill at rest, before any state lift
static ALLEGRO_COLOR _color_with_alpha(ALLEGRO_COLOR c, float a)
Helper: return a copy of c with the given alpha (0..1).
static void _n_gui_kv_down_clicked(int widget_id, void *user_data)
static int _key_navigates(int keycode)
is this one of the keys that move through a widget rather than type into it: the arrows,...
static void _draw_cols_scrollbar(float ax, float bar_y, float track_w, float content_w, float h_scroll, N_GUI_SB_TRACK *track, const N_GUI_STYLE *style, const N_GUI_THEME *theme)
draw a horizontal scrollbar along the bottom edge of a widget: track_w is the width of the scrollable...
static double _slider_key_step(const N_GUI_SLIDER_DATA *sd)
how far one arrow key press or one wheel notch moves a slider
static int _justified_char_at_pos(const char *text, ALLEGRO_FONT *font, float max_w, float text_x, float text_y, float scroll_y, float click_mx, float click_my)
helper: find the byte offset in justified text closest to a click position.
static float _textarea_content_height(const N_GUI_TEXTAREA_DATA *td, ALLEGRO_FONT *font, float widget_w, float pad)
helper: compute the total content height of multiline textarea text (with line-wrap),...
static int _n_gui_tree_open(N_GUI_TREE *tree, int node_index)
helper: open a node, calling the expand callback first when it has not filled this node yet.
static N_GUI_MEAS_ENTRY * _ngui_meas_slot(ALLEGRO_FONT *font, const char *text, size_t len)
find (or claim) the cache slot for (font, text[len]).
static int _tooltip_widget_at(N_GUI_CTX *ctx, float px, float py)
helper: top-most visible tooltip-bearing widget under a gui-space point (-1 = none).
float corner_r
thumb corner radius; zero draws square corners
static int _textarea_handle_key(N_GUI_WIDGET *wgt, ALLEGRO_EVENT *ev, ALLEGRO_FONT *font, float pad, float sb_size, N_GUI_CTX *ctx)
static ALLEGRO_COLOR _scrollbar_thumb_for_state(ALLEGRO_COLOR at_rest, const N_GUI_THEME *t, int state)
helper: the fill of a scrollbar thumb, for the state of the bar.
float y
pen y, constant for the whole line
static int _cell_is_num(const char *s)
true when every character of a non-empty string is a decimal digit
float x_max
right edge of the visible area
static void _ngui_publish_primary_selection(N_GUI_CTX *ctx)
publish the active text selection (syntax view, label, or focused textarea) to the X11 PRIMARY select...
static void _suggest_accept(N_GUI_CTX *ctx, N_GUI_WIDGET *wgt)
put the highlighted completion in place of the word under the cursor
static void _n_gui_kv_content_grab(N_GUI_KVTABLE *table, int idx, N_GUI_KV_CONTENT *out)
static void _draw_combobox(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, const N_GUI_STYLE *style)
draw a combobox widget (closed state)
static char * _n_gui_kv_dup_text(N_GUI_CTX *ctx, int widget_id)
static int _items_grow(N_GUI_LISTITEM **items, const size_t *nb, size_t *cap)
helper: ensure items array has room for one more, returns 1 on success
static void _n_gui_kv_refresh_actions(N_GUI_KVTABLE *table)
#define N_GUI_WRAP_MAX_WORDS
the most words any justified layout will consider
static void _draw_syntaxview(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, N_GUI_STYLE *style)
static int _scrollbar_calc_scroll_int(float mouse, float track_start, float track_length, int visible_items, int total_items, float thumb_min)
helper: integer variant of _scrollbar_calc_scroll for item-based widgets.
static ALLEGRO_COLOR _syntax_diff_hunk(void)
see _syntax_diff_add: colour of a hunk header line
static ALLEGRO_COLOR _syntax_diff_del(void)
see _syntax_diff_add: colour of a removed line
static void _draw_hexview(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, N_GUI_STYLE *style)
draw a read-only hex viewer: offset, hex bytes, and an ASCII gutter
static void _draw_tooltip(N_GUI_CTX *ctx)
helper: draw the hover-tooltip bubble for the currently armed tooltip widget, but ONLY in the render ...
#define _N_GUI_HELD_ALTGR
static void _datagrid_apply_columns(N_GUI_CTX *ctx, int widget_id, int ncols, const int *order, const int *visible, const float *width)
static void _destroy_widget(void *ptr)
static _N_GUI_SB_SKIN _sb_skin_global(const N_GUI_STYLE *style)
helper: the skin of one of the display's own bars, which scroll the whole virtual canvas rather than ...
static size_t _datagrid_phys(const N_GUI_DATAGRID_DATA *gd, size_t dp)
physical column index shown at display position dp (identity when no order).
static void _draw_datagrid(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, N_GUI_STYLE *style)
static void _syntaxview_hmetrics(const N_GUI_WIDGET *wgt, N_GUI_SYNTAXVIEW_DATA *yd, ALLEGRO_FONT *font, const N_GUI_STYLE *style, float *content_w, float *pane_w, int *need_hsb, int *visible)
forward declaration: syntaxview horizontal-scroll metrics, shared by the draw path and every mouse ha...
static int _point_in_rect(float px, float py, float rx, float ry, float rw, float rh)
helper: test if point is inside a rectangle
static ALLEGRO_COLOR _text_for_state(const N_GUI_THEME *t, int state)
static int _cell_cmp(const char *a, const char *b)
compare two cell strings: numerically when both are integers, else case-insensitive
static int _label_line_at(const char *text, int index, char *out, size_t out_len)
helper: line index of text, copied into out without its break.
static void _markdownview_follow_theme(N_GUI_WIDGET *wgt, N_GUI_MARKDOWNVIEW_DATA *md)
Re-derive the view's colours from the widget's theme, while the caller has not taken the style over.
#define N_GUI_ANIM_TAIL_SEC
static double _clamp(double v, double lo, double hi)
helper: clamp a double between lo and hi
static int _n_gui_tree_listbox_bounds(N_GUI_TREE *tree, float *out_x, float *out_y, float *out_w, float *out_h, float *out_item_area_w, float *out_inset, float *out_item_h, int *out_scroll_off)
Return the listbox's absolute (screen-space) bounds and geometry via out params.
static ALLEGRO_COLOR _scrollbar_edge_for_state(const N_GUI_THEME *t, int state)
helper: the colour of the outline round a scrollbar's thumb, for the state of the bar.
static size_t _utf8_step(unsigned char lead)
helper: the length in bytes of the UTF-8 sequence led by lead, 1 for a byte that does not lead one.
static void _textarea_delete_selection(N_GUI_WIDGET *wgt)
delete the currently selected text, move cursor to selection start
static int _json_get_int(cJSON *parent, const char *name, int fallback)
helper: read an int from JSON, return fallback if missing
static int _hexview_handle_key(N_GUI_WIDGET *wgt, const ALLEGRO_EVENT *ev, int visible_rows)
handle one key for a focused editable hex view.
int wrapped
it does not fit: start a new line before placing it
#define N_GUI_WRAP_MAX_ITEMS
most layout items one wrap takes: every word, the break between each two, and room for the hard break...
static void _word_text(const char *text, int start, int len, char *out)
helper: copy one word out of text into out (bounded by N_GUI_TEXT_MAX, which is also the widget text ...
static N_GUI_WIDGET * _new_widget(N_GUI_CTX *ctx, int type, float x, float y, float w, float h)
helper: allocate and initialise a base widget
static int _tb_button_rect(const N_GUI_WINDOW *win, const N_GUI_STYLE *style, int btn_type, float *out_x, float *out_y, float *out_w, float *out_h)
compute the absolute rect for a titlebar button.
static void _draw_tb_buttons(N_GUI_WINDOW *win, const N_GUI_STYLE *style)
draw the titlebar buttons for a window
static double _slider_snap_value(double val, double min_val, double max_val, double step)
helper: snap a slider value to the nearest valid step from min_val.
static int _reading_order(const N_GUI_WIDGET *a, const N_GUI_WIDGET *b)
Which of two widgets comes first in reading order.
static void _draw_radiolist(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, const N_GUI_STYLE *style)
draw a radiolist widget
static void _list_panel_highlight_step(int *highlight, int *scroll, int nb, int max_visible, int delta, int fallback)
helper: move an open list panel's highlight cursor (combobox / dropmenu) by delta items and scroll th...
char ch[5]
the decoded character, NUL-terminated, for a caller that draws it
static void _suggest_word(const N_GUI_TEXTAREA_DATA *td, size_t *start, size_t *end)
the word the cursor is in.
static void _draw_bitmap_scaled(ALLEGRO_BITMAP *bmp, float dx, float dy, float dw, float dh, int mode)
helper: draw a bitmap into a rectangle, respecting the given scale mode.
static void _draw_checkbox(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, N_GUI_STYLE *style)
draw a checkbox widget
static void _draw_label_overflow(ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, float max_w, const N_GUI_LABEL_DATA *lb, const char *text)
helper: draw a label's text, or one line of it, that is too wide for it, shortened the way its trunca...
static void _draw_combobox_dropdown(N_GUI_CTX *ctx)
static void _n_gui_kv_add_clicked(int widget_id, void *user_data)
static void _button_key_press(N_GUI_CTX *ctx, N_GUI_WIDGET *wgt)
Press a button from the keyboard, as a click would.
N_GUI_TEXTAREA_DATA * td
the field being completed
static void _n_gui_tab_button_clicked(int widget_id, void *user_data)
float outline_thickness
thickness of that outline; zero for none
static N_GUI_DATAGRID_DATA * _datagrid_data(N_GUI_CTX *ctx, int widget_id)
fetch a data grid's column table for an API call, or NULL on a bad id.
int track_round
draw the track as a pill, inset by track_inset at both ends and with no divider: what a frameless win...
static void _syntaxview_ensure_width(N_GUI_SYNTAXVIEW_DATA *yd, ALLEGRO_FONT *font, const N_GUI_STYLE *style)
forward declaration: (re)build a syntaxview's cached content width when stale.
static int _held_bit(int keycode)
the held-key bit of a key code, 0 for a key that is not a modifier
static int _textarea_has_selection(const N_GUI_TEXTAREA_DATA *td)
forward declaration: whether a text area has a non empty selection.
static bool _tooltip_line_cb(int line_num, const char *line, int size, void *extra)
helper: al_do_multiline_text callback that just counts the wrapped lines.
static void _list_panel_wheel(int *highlight, int *scroll, int nb, int max_visible, int notches, int row)
helper: the mouse wheel over an open list panel (combobox / dropmenu).
static int _hexview_erase(N_GUI_HEXVIEW_DATA *hd, size_t at)
remove the byte at at from an editable hex view.
static ALLEGRO_COLOR _border_for_state(const N_GUI_THEME *t, int state)
static N_GUI_MEAS_ENTRY _ngui_meas_cache[1024u]
static float _syntax_prefix_w(ALLEGRO_FONT *font, const char *s, int n)
forward declaration: pixel width of the first n bytes of a line.
static float _syntax_prefix_w_lim(ALLEGRO_FONT *font, const char *s, int n, float limit)
pixel width of the first n bytes of s in font, of any length: the measurement needs a NUL-terminated ...
#define _N_GUI_WIN_STATE_PERSIST_MASK
static void _ngui_clip_set(ALLEGRO_DISPLAY *display, int which, const char *text)
char * key
owned copy of the key text
static void _draw_focus_outline(const N_GUI_WIDGET *wgt, float ox, float oy)
draw the keyboard focus outline over a widget that has the focus: a line just inside its edge,...
static int _button_takes_key(int keycode)
helper: is a key one a focused button does something with: Enter and Space press it,...
static int _sb_track_hit(const N_GUI_SB_TRACK *track, float mx, float my)
helper: is the pointer inside a bar's last painted rectangle.
static LIST_NODE * _find_window_node(N_GUI_CTX *ctx, int window_id)
helper: find a window node in the context list by id
static _N_GUI_THUMB _scrollbar_thumb(float track_len, float visible, float content, float offset, float min_len)
helper: where a scrollbar thumb sits and how long it is.
static void _draw_text_justified(ALLEGRO_FONT *font, ALLEGRO_COLOR color, float x, float y, float max_w, float max_h, const char *text)
helper: draw justified text within a given width, with multi-line word wrapping.
static void _n_gui_tree_emit(N_GUI_TREE *tree, int parent)
helper: add the children of one node to the listbox, in order, then each expanded child's own childre...
char * value
owned copy of the value text
static int _dropmenu_entries_grow(N_GUI_DROPMENU_ENTRY **entries, const size_t *nb, size_t *cap)
helper: ensure dropmenu entries array has room for one more
static void _draw_listbox(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, N_GUI_STYLE *style)
draw a listbox widget
static float _dropdown_panel_y(const N_GUI_CTX *ctx, float widget_top, float widget_bottom, float panel_h, int expand_up)
draw the combobox dropdown overlay (called after all windows)
static void _draw_splitpane(N_GUI_WIDGET *wgt, float ox, float oy)
draw a split pane: only the divider bar is painted (the app fills the two regions with its own widget...
static void _suggest_refresh(N_GUI_CTX *ctx, N_GUI_WIDGET *wgt, int force)
ask the provider about the word under the cursor, and open or close the panel by what it answers.
static void _textarea_paste_clip(N_GUI_WIDGET *wgt, N_GUI_TEXTAREA_DATA *td, const char *clip)
insert clipboard text at the cursor, replacing any selection.
static int _shorten_start(ALLEGRO_FONT *font, const char *text, float max_w, char *out, size_t out_len)
helper: "..." followed by the shortest tail of text, cut between UTF-8 sequences, that fits max_w.
static int _textarea_copy_to_clipboard(const N_GUI_TEXTAREA_DATA *td, ALLEGRO_DISPLAY *display)
copy selected text to clipboard.
static void _draw_button(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, const N_GUI_STYLE *style)
static int _pointer_over_window(const N_GUI_CTX *ctx, float px, float py)
helper: is the pointer over any open window that takes part in the current pass?
static void _global_scroll_needs(const N_GUI_CTX *ctx, float eff_w, float eff_h, int *need_v, int *need_h)
helper: which global scrollbars the open windows need in a view of eff_w by eff_h,...
static int _datagrid_ensure_colors(N_GUI_DATAGRID_DATA *gd)
helper: ensure the per-row tint arrays exist, sized to rows_cap (rows start untinted); returns 1 when...
static void _scrollbar_update_from_mouse(N_GUI_WIDGET *wgt, float mx, float my, float win_x, float win_content_y, const N_GUI_STYLE *style)
handle scrollbar drag
static _N_GUI_SB_SKIN _sb_skin(const N_GUI_STYLE *style)
helper: the skin of a bar belonging to a widget or a window.
static void _draw_markdownview(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, const N_GUI_STYLE *style)
draw a sortable data grid: fixed header row plus scrollable data rows
static void _draw_window(N_GUI_WINDOW *win, ALLEGRO_FONT *default_font, N_GUI_STYLE *style)
draw a window chrome + its widgets
static void _n_gui_kv_split_a_changed(int widget_id, float ratio, void *user_data)
static ALLEGRO_COLOR _color_mix(ALLEGRO_COLOR a, ALLEGRO_COLOR b, float t)
Helper: mix two colours, t of the way from a to b.
static float _win_tbh(const N_GUI_WINDOW *win)
helper: effective title bar height (0 for frameless windows)
static const N_GUI_WIDGET * _find_widget_const(const N_GUI_CTX *ctx, int widget_id)
find a widget without a non-const context, for the queries that only read
#define N_GUI_KEY_PRESS_FLASH_SEC
static void _compute_gui_bounds(N_GUI_CTX *ctx)
helper: compute the bounding box of all open windows
int enabled
enabled checkbox state
int newline
the character is ' '
static void _draw_label(N_GUI_WIDGET *wgt, float ox, float oy, ALLEGRO_FONT *default_font, float win_w, N_GUI_STYLE *style)
static void _n_gui_widget_capture_normalized(const N_GUI_WINDOW *win, N_GUI_WIDGET *wgt)
capture normalized coords for a single widget relative to its parent window
char * desc
owned copy of the description text
static float _label_lines_top(float ay, float h, int lines, float fh)
helper: the top of a multi-line label's first line: the block of lines centred in the box as a single...
static void _destroy_window(void *ptr)
helper: destroy a single window (called by list destructor)
static void _apply_cursor(N_GUI_CTX *ctx, int shape, ALLEGRO_MOUSE_CURSOR *custom)
helper: show a cursor on the GUI's display, recording it whether or not there is a display,...
static ALLEGRO_COLOR _json_get_color(cJSON *parent, const char *name, ALLEGRO_COLOR fallback)
helper: read an RGBA colour from a JSON array [r,g,b,a]
static float _label_line_x(const N_GUI_LABEL_DATA *lb, float line_w, float ax, float effective_w, float pad)
helper: where a line of a multi-line label starts on screen, by the label's alignment.
static int _split_words(const char *text, ALLEGRO_FONT *font, int *starts, int *lens, float *widths, int max_words, int *nl_before)
helper: split text into whitespace-separated words, recording each word's byte offset in text,...
static void _hexview_reveal(N_GUI_HEXVIEW_DATA *hd, int visible_rows)
scroll an editable hex view so its cursor row is visible
const ALLEGRO_FONT * font
static int _utf8_char_len(unsigned char c)
return the byte length of a UTF-8 character from its lead byte
static void _json_add_color(cJSON *parent, const char *name, ALLEGRO_COLOR c)
helper: add an RGBA colour as a JSON array [r,g,b,a] (0-255)
static void _slider_value_text(const N_GUI_SLIDER_DATA *sd, double value, char *out, size_t out_len)
draw a slider widget (horizontal or vertical)
static void _native_apply_minimised(N_GUI_WINDOW *win)
helper: mirror an own-chrome window's minimised state onto its OS window by shrinking the display to ...
static void _syntaxview_ensure_lines(N_GUI_SYNTAXVIEW_DATA *yd)
forward declaration: (re)build a syntaxview's cached line count and headers-end index when stale.
static int _label_char_at_x(const N_GUI_LABEL_DATA *lb, ALLEGRO_FONT *font, float click_x)
draw a label widget.
static void _apply_pending_widget(N_GUI_CTX *ctx, const char *title, const N_GUI_WIDGET *wgt)
static void _text_dims(ALLEGRO_FONT *font, const char *text, int *x, int *y, int *w, int *h)
helper: memoized al_get_text_dimensions (bounding box x/y/w/h).
static void _syntax_run(SYNTAX_RUN *r, ALLEGRO_COLOR col, const char *s, int len)
draw one coloured run of a syntax line and advance the pen past it.
static int _suggest_is_sep(const N_GUI_TEXTAREA_DATA *td, char c)
is c one of the characters that end a word in this field
static void _n_gui_kv_remove_clicked(int widget_id, void *user_data)
static void _suggest_close(N_GUI_CTX *ctx, N_GUI_WIDGET *wgt)
put the panel away, and forget which word it answered
static void _track_modifiers(N_GUI_CTX *ctx, const ALLEGRO_EVENT *event)
follow the modifier keys through one event
static void _wrap_words_emit(size_t first, size_t last, size_t line, double width, void *user)
static N_GUI_WINDOW * _topmost_window_at(const N_GUI_CTX *ctx, float px, float py)
helper: the top-most open window of the current pass under a point, or NULL.
static int _syntax_js_keyword(const char *s, int n)
whether the n bytes at s form a JavaScript keyword or literal name
#define N_GUI_MEAS_CACHE_SIZE
static void _n_gui_sectionlist_set_header_label(N_GUI_SECTIONLIST *sl, int idx)
static void _datagrid_hmetrics(const N_GUI_WIDGET *wgt, const N_GUI_DATAGRID_DATA *gd, ALLEGRO_FONT *font, const N_GUI_STYLE *style, float *content_w, float *pane_w, int *need_hsb)
Compute the datagrid horizontal-scroll metrics used identically by the draw path and the mouse handle...
static void _clear_syntaxview_selection(N_GUI_CTX *ctx)
drop any active syntax-view text selection (used when focus moves to another selectable widget,...
static float _markdownview_measure(const N_GUI_WIDGET *wgt, N_GUI_MARKDOWNVIEW_DATA *md, const N_GUI_STYLE *style)
Measure the document if anything it depends on has changed, and clamp the scroll to what is left.
#define _N_GUI_HELD_RSHIFT
#define _N_GUI_HELD_LCTRL
bits of N_GUI_CTX::held_modifier_keys, one per modifier key
static int _utf8_encode(int cp, char *out)
encode a Unicode code point into UTF-8, return the number of bytes written (0 on error)
static void _n_gui_kv_content_put(N_GUI_KVTABLE *table, int idx, const N_GUI_KV_CONTENT *in)
The look of one scrollbar: the style values a bar's paint reads, gathered so that the painter does no...
one step of a textarea's per-character wrapped layout
a scrollbar thumb: length along the track, and offset from the track start
accumulator for _wrap_words: records the first word index of each line, and whether the line ends a p...
handle textarea key input.
draw a run of text and advance the pen x by its width.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.
int n_gui_md_link_at(const N_GUI_MD_FONTS *fonts, const N_GUI_MD_STYLE *style, float x, float y, float width, const char *text, float px, float py, char *url, size_t url_cap)
the url of the link under (px, py), if there is one
float n_gui_md_draw(const N_GUI_MD_FONTS *fonts, const N_GUI_MD_STYLE *style, float x, float y, float width, const char *text)
draw text as markdown at (x, y), wrapped to width
void n_gui_md_style_default(N_GUI_MD_STYLE *out, ALLEGRO_COLOR text, ALLEGRO_COLOR background, float line_height)
fill a style from two colours and a line height
float n_gui_md_height(const N_GUI_MD_FONTS *fonts, const N_GUI_MD_STYLE *style, float width, const char *text)
height of text laid out as markdown at width, in pixels
Lay out and draw n_markdown's block model with Allegro fonts.
ALLEGRO_FONT * regular
body text, and the fallback for every other face.
static uint64_t le(const unsigned char *p, int n)
read a little endian unsigned value
size_t n_wrap_layout(const n_wrap_item *items, size_t count, double max_width, n_wrap_emit emit, void *user)
Break items into lines no wider than max_width.
Greedy word-wrap over pre-measured, styled items.
#define N_WRAP_SPACE
the item is a legal break point (typically a space); it is DROPPED when a line breaks there,...
#define N_WRAP_NEWLINE
the item is a hard line break; it ends the line and occupies no cell
double width
advance width in the caller's units (pixels, columns, ...)
unsigned int flags
N_WRAP_SPACE / N_WRAP_NEWLINE, or 0
One pre-measured layout item: a glyph, an emoji cell, an inline image, or a whole word,...