Tree view row-order regression test (headless): a child added after its parent's siblings is drawn under its parent, not at the bottom of the tree.
Tree view row-order regression test (headless): a child added after its parent's siblings is drawn under its parent, not at the bottom of the tree. This is what a tree filled on demand does, and the only order in which a file browser can be built.
#define ALLEGRO_UNSTABLE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
if (!cond) {
}
}
int i = 0;
*count = 0;
}
const char* got[32];
int count = 0, i = 0;
if (count != n) {
for (i = 0; i < count; i++)
return;
}
for (i = 0; i < n; i++) {
if (strcmp(got[i], want[i]) != 0) {
n_log(
LOG_ERR,
"row %d: expected %s, got %s", i, want[i], got[i]);
}
}
}
int main(
int argc,
char** argv) {
(void)argc;
(void)argv;
if (!al_init() || !al_init_font_addon()) {
return 1;
}
ALLEGRO_FONT*
font = al_create_builtin_font();
return 1;
}
return 1;
}
{
int home = -1, data = -1, music = -1, prog = -1, root = -1;
if (!tree)
return 1;
{
static const char* const want[] = {"home", "data", "music", "tmp"};
}
{
static const char* const want[] = {"home", "data", "prog", "photos", "music",
"tmp"};
}
{
static const char* const want[] = {"home", "data", "prog", "afterapro",
"photos", "music", "tmp"};
}
{
static const char* const want[] = {"home", "data", "prog", "afterapro",
"photos", "music", "tmp", "cache"};
}
{
static const char* const want[] = {"home", "data", "music", "tmp", "cache"};
}
root);
}
printf(
"ex_gui_tree_order: FAILED, %d check(s)\n",
failures);
else
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.