30#define ALLEGRO_UNSTABLE 1
55 for (i = 0; i < tree->
nb_visible && i < max; i++)
67 for (i = 0; i < count; i++)
71 for (i = 0; i < n; i++) {
72 if (strcmp(got[i], want[i]) != 0) {
73 n_log(
LOG_ERR,
"row %d: expected %s, got %s", i, want[i], got[i]);
79int main(
int argc,
char** argv) {
84 if (!al_init() || !al_init_font_addon()) {
88 ALLEGRO_FONT*
font = al_create_builtin_font();
96 al_destroy_font(
font);
104 int home = -1, data = -1, music = -1, prog = -1, root = -1;
122 static const char*
const want[] = {
"home",
"data",
"music",
"tmp"};
134 static const char*
const want[] = {
"home",
"data",
"prog",
"photos",
"music",
145 static const char*
const want[] = {
"home",
"data",
"prog",
"afterapro",
146 "photos",
"music",
"tmp"};
155 static const char*
const want[] = {
"home",
"data",
"prog",
"afterapro",
156 "photos",
"music",
"tmp",
"cache"};
164 static const char*
const want[] = {
"home",
"data",
"music",
"tmp",
"cache"};
173 expect_true(
"selection is on the row it is drawn at",
181 al_destroy_font(
font);
184 printf(
"ex_gui_tree_order: FAILED, %d check(s)\n",
failures);
186 printf(
"ex_gui_tree_order: ok\n");
static void expect_true(const char *label, int cond)
static void expect_order(N_GUI_TREE *tree, const char *const *want, int n)
static void visible_labels(N_GUI_TREE *tree, const char **out, int max, int *count)
FONT * font
the default 8x8 font, valid after allegro_init()
N_GUI_TREE_NODE nodes[2048]
node storage
int listbox_id
listbox widget ID
char label[128]
display text
int visible_map[2048]
visible row to node index
int nb_nodes
number of nodes
int nb_visible
number of visible rows
int depth
depth in tree (0 = root)
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.
int n_gui_listbox_get_selected(N_GUI_CTX *ctx, int widget_id)
get the index of the first selected item in a listbox
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_tree_free(N_GUI_TREE **tree)
free a tree view (does not destroy the N_GUI listbox)
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 ...
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.
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
void n_gui_tree_toggle_expand(N_GUI_TREE *tree, int node_index)
toggle expand/collapse of a node.
void n_gui_destroy_ctx(N_GUI_CTX **ctx)
Destroy a GUI context and all its windows/widgets.
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
The top-level GUI context that holds all windows.
tree view built from an N_GUI listbox
#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 ).
Common headers and low-level functions & define.
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.