18#define ALLEGRO_UNSTABLE 1
46 while ((opt = getopt(argc, argv,
"V:")) != -1) {
58 const unsigned char* p = (
const unsigned char*)s;
61 int n = (*p & 0x80) == 0 ? 1 : (*p & 0xE0) == 0xC0 ? 2
62 : (*p & 0xF0) == 0xE0 ? 3
63 : (*p & 0xF8) == 0xF0 ? 4
67 for (k = 1; k < n; k++)
68 if ((p[k] & 0xC0) != 0x80)
return 0;
74int main(
int argc,
char** argv) {
80 fprintf(stderr,
"Usage: %s [-V LOG_LEVEL]\n", argv[0]);
84 if (!al_init() || !al_init_font_addon()) {
88 ALLEGRO_FONT*
font = al_create_builtin_font();
90 cw = (float)al_get_text_width(
font,
"a");
91 expect_true(
"the builtin font is monospaced", al_get_text_width(
font,
"abcdefghij") == (
int)(cw * 10.0f));
95 strcmp(out,
"short") == 0);
98 expect_true(
"the end is cut: abc...", strcmp(out,
"abc...") == 0);
100 expect_true(
"the start is cut: ...hij", strcmp(out,
"...hij") == 0);
104 expect_true(
"a path loses whole leading components and keeps its file name",
105 strcmp(out,
".../IMG_0001.CR3") == 0);
108 expect_true(
"either separator counts", strcmp(out,
".../Pictures\\IMG_0001.CR3") == 0);
111 expect_true(
"a file name wider than the box alone keeps its end",
112 strcmp(out,
"...ame.CR3") == 0);
127 al_destroy_font(
font);
134 expect_true(
"a label cuts at the end until told otherwise",
144 al_destroy_font(
font);
146 fprintf(stderr,
"ex_gui_text_shorten: %d failure(s)\n",
failures);
149 printf(
"ex_gui_text_shorten: ok\n");
void process_args(int argc, char **argv)
static void expect_true(const char *label, int cond)
static int utf8_whole(const char *s)
1 when s is whole UTF-8 sequences, none cut in half
FONT * font
the default 8x8 font, valid after allegro_init()
void n_gui_set_display_size(N_GUI_CTX *ctx, float w, float h)
set the display (viewport) size so global scrollbars can be computed.
#define N_GUI_ALIGN_LEFT
left aligned text
void n_gui_label_set_truncate(N_GUI_CTX *ctx, int widget_id, int mode)
set the text of a label widget
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...
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.
#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_add_window(N_GUI_CTX *ctx, const char *title, float x, float y, float w, float h)
Add a new pseudo-window to the context.
N_GUI_CTX * n_gui_new_ctx(ALLEGRO_FONT *default_font)
Create a new GUI context.
#define N_GUI_TRUNCATE_END
text too wide for its box is cut at the end, "Long senten...": the default, right for a sentence
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
#define N_GUI_TRUNCATE_PATH
a path too wide for its box loses whole leading components, ".../photos/IMG_0001.CR3",...
int n_gui_label_get_truncate(N_GUI_CTX *ctx, int widget_id)
a label's truncate mode
#define N_GUI_SHAPE_ROUNDED
rounded rectangle shape
int n_gui_add_button(N_GUI_CTX *ctx, int window_id, const char *label, float x, float y, float w, float h, int shape, void(*on_click)(int, void *), void *user_data)
Add a button widget to a window.
The top-level GUI context that holds all windows.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL ).
#define LOG_INFO
informational
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.