Table of Contents
- xtk_treeview.h
- Types
- XtkTreeSpan
- XtkTreeItem
- XtkTreeView
- XtkTreeViewChildrenCallback
- XtkTreeViewSelectionCallback
- XtkTreeViewActivateCallback
- XtkTreeViewContextMenuCallback
- XtkTreeViewScrollCallback
- XtkTreeViewDropPosition
- XtkTreeViewReorderCallback
- XtkTreeViewSortMode
- XtkTreeViewExpandedVisitor
- Constants
- XTK_TREEVIEW_ID_MAX
- XTK_TREEVIEW_LABEL_MAX
- XTK_TREEVIEW_SPANS_MAX
- XTK_TREE_SPAN_BOLD
- XTK_TREE_SPAN_BACKGROUND
- Functions
- xtk_treeview_rgb
- xtk_treeview_create
- xtk_treeview_destroy
- xtk_treeview_set_theme
- xtk_treeview_get_window
- xtk_treeview_set_focused
- xtk_treeview_get_focused
- xtk_treeview_handle_event
- xtk_treeview_resize
- xtk_treeview_set_scroll_offset
- xtk_treeview_refresh
- xtk_treeview_set_selection_callback
- xtk_treeview_set_activate_callback
- xtk_treeview_set_context_menu_callback
- xtk_treeview_set_scroll_callback
- xtk_treeview_set_reorder_callback
- xtk_treeview_update_drag_autoscroll
- xtk_treeview_set_sort_mode
- xtk_treeview_get_sort_mode
- xtk_treeview_get_selected
- xtk_treeview_select
- xtk_treeview_clear_selection
- xtk_treeview_get_item_rect
- xtk_treeview_expand
- xtk_treeview_collapse
- xtk_treeview_visit_expanded
- xtk_treeview_get_content_height
- xtk_treeview_get_content_width
- xtk_treeview_get_hover_row
- xtk_treeview_set_hover_row
- xtk_treeview_config_init_defaults
- xtk_treeview_config_parse_styling
- xtk_treeview_config_write_styling
- xtk_treeview_widget_config_init_defaults
- xtk_treeview_widget_config_parse
- xtk_treeview_widget_config_write
xtk_treeview.h
A tree of rows that expand and collapse, with children loaded on demand.
A tree view shows a hierarchy of rows, such as the files of a project or the symbols of a source file. Each row has an id, a label, an optional icon and optional colored parts of its label. A row with children has a small triangle (the "twisty") that expands or collapses it. The user can select a row, activate it, open a context menu on it, and drag it to another place in the tree.
The widget does not know what the rows mean. It asks the program for the children of a row through an XtkTreeViewChildrenCallback, the first time that row is expanded, and keeps a copy of what it gets. The whole tree is never loaded up front. When the program's data changes, it calls xtk_treeview_refresh(), and the widget asks again for the children of the top level and of every expanded row.
Making one. xtk_treeview_create() takes the parent window, the position and size, the children callback, a TreeViewBlock for the colors and font (usually &config.treeview), and the XtkConfig for the geometry (config.treeview_widget) and the scrollbars (config.scrollbar, config.scrollbar_widget). The widget keeps both pointers and reads them each time it draws, so they must stay valid while the tree exists. It creates and maps its window at once and calls the children callback for the top level before it returns. Free it with xtk_treeview_destroy().
Scrolling. There are two ways to scroll a tree:
- The program makes the window as large as the content (
xtk_treeview_get_content_height(),xtk_treeview_get_content_width()) and moves it inside a smaller viewport, as an xtk_toolwindow does with its content window. The tree then shows no scrollbars of its own. - The window is smaller than the content. The tree then shows a vertical scrollbar at its right edge and, when a row is wider than the window, a horizontal one at its bottom edge, drawn over the rows.
The mouse wheel, the vertical thumb and the auto-scroll during a drag move the rows up or down. When a scroll callback is set (xtk_treeview_set_scroll_callback()), the tree asks the program to scroll through it; otherwise it moves its rows itself. Sideways scrolling (Shift with the wheel, buttons 6 and 7, or the horizontal thumb) is always done by the tree itself.
Events. Pass every X event to xtk_treeview_handle_event(). It returns 1 for every event on the tree's window and 0 for events on other windows.
- Left click on a twisty: the row expands or collapses.
- Left click on a row: the row is selected and the tree takes the keyboard focus. A double-click (within 400 ms) on a row with children expands or collapses it; on a row without children it fires the activate callback.
- Left press and move by more than 4 pixels: a drag starts. A line between rows or a frame around a row shows where the row would go. On release the reorder callback fires; the tree itself moves nothing. A drag also sets the sort order back to
XTK_TREEVIEW_SORT_MANUAL. - Right click: the row under the pointer is selected and the context menu callback fires (with the id "" below the last row).
- Keys, while the tree has the focus: Up and Down move the selection, Home and End go to the first and last row, Right expands the selected row, Left collapses it, and Return or keypad Enter fires the activate callback.
The selection callback fires each time a row is selected by the mouse, the keys or xtk_treeview_select(). The selected row is drawn in the selection colors while the tree has the keyboard focus, and in the inactive selection colors while it does not. The border is drawn in the focus-border color while the tree has the focus.
Theme keys. [treeview] (TreeViewBlock):
font-family: the font of the labels (default "sans-serif"); a row that is new and not saved, and a bold span, use the bold face of it.font-size: the font size in points (default 11).background: behind the rows (default #2E2E2E).foreground: the label text (default D9D9D9).selected-background,selected-foreground: the selected row while the tree has the focus (defaults #406699 and FFFFFF). The background also colors the drop marker during a drag.inactive-selected-background,inactive-selected-foreground: the selected row while the tree does not have the focus (defaults: 35% of selected-background over background, and foreground).hover-background: the row under the pointer (default #383838).branch-line: the twisties (default #999999).border: the outer border (default #595959).focus-border: the outer border while the tree has the focus (default selected-background, #406699).unsaved-foreground: the label of a row whoseunsaved_newis set (default F2A626).
background, hover-background, selected-background and inactive-selected-background can also be gradients.
[treeview-widget] (config.treeview_widget):
row-height: the height of a row in pixels (default 22).indent-width: the indent of each level in pixels (default 16).twisty-size: the size of the twisty in pixels (default 10).border-width: the outer border; 0 draws none (default 1).
The tree's own scrollbars use the colors track, thumb and thumb-hover of [scrollbar], and thickness and min-thumb-length of [scrollbar-widget].
Example.
static int children(const char *parent_id, XtkTreeItem *items, int max_items, void *user_data) {
(void)max_items; (void)user_data;
if (!parent_id) { // the top level
snprintf(items[0].id, sizeof(items[0].id), "src");
snprintf(items[0].label, sizeof(items[0].label), "src");
snprintf(items[0].icon, sizeof(items[0].icon), "folder");
items[0].has_children = 1;
snprintf(items[1].id, sizeof(items[1].id), "README");
snprintf(items[1].label, sizeof(items[1].label), "README");
return 2;
}
if (strcmp(parent_id, "src") == 0) {
snprintf(items[0].id, sizeof(items[0].id), "src/main.c");
snprintf(items[0].label, sizeof(items[0].label), "main.c");
return 1;
}
return 0;
}
static void opened(XtkTreeView *tree, const char *item_id, void *user_data) {
(void)tree; (void)user_data;
printf("open %s\n", item_id);
}
XtkConfig config;
xtk_config_init_defaults(&config);
XtkTheme *theme = xtk_theme_new();
if (theme && xtk_theme_builtin("Dark", theme)) xtk_theme_apply(&config, theme);
xtk_theme_free(theme);
XtkTreeView *tree = xtk_treeview_create(display, screen, window, 0, 0, 240, 400,
children, NULL, &config.treeview, &config);
xtk_treeview_set_activate_callback(tree, opened, NULL);
XEvent event;
for (;;) {
XNextEvent(display, &event);
xtk_treeview_handle_event(tree, &event);
}
*
Limitations.
- Only one row can be selected at a time.
- Rows nested more than 64 levels deep are not shown.
- The keys do not search by typing, and Left does not move to the parent row.
- For a tree with more than 2000 visible rows,
xtk_treeview_get_content_width()measures a sample of the rows, so it can miss the widest one.
#include "xtk_treeview.h"
Types: XtkTreeSpan, XtkTreeItem, XtkTreeView, XtkTreeViewChildrenCallback, XtkTreeViewSelectionCallback, XtkTreeViewActivateCallback, XtkTreeViewContextMenuCallback, XtkTreeViewScrollCallback, XtkTreeViewDropPosition, XtkTreeViewReorderCallback, XtkTreeViewSortMode, XtkTreeViewExpandedVisitor
Constants: XTK_TREEVIEW_ID_MAX, XTK_TREEVIEW_LABEL_MAX, XTK_TREEVIEW_SPANS_MAX, XTK_TREE_SPAN_BOLD, XTK_TREE_SPAN_BACKGROUND
Functions: xtk_treeview_rgb, xtk_treeview_create, xtk_treeview_destroy, xtk_treeview_set_theme, xtk_treeview_get_window, xtk_treeview_set_focused, xtk_treeview_get_focused, xtk_treeview_handle_event, xtk_treeview_resize, xtk_treeview_set_scroll_offset, xtk_treeview_refresh, xtk_treeview_set_selection_callback, xtk_treeview_set_activate_callback, xtk_treeview_set_context_menu_callback, xtk_treeview_set_scroll_callback, xtk_treeview_set_reorder_callback, xtk_treeview_update_drag_autoscroll, xtk_treeview_set_sort_mode, xtk_treeview_get_sort_mode, xtk_treeview_get_selected, xtk_treeview_select, xtk_treeview_clear_selection, xtk_treeview_get_item_rect, xtk_treeview_expand, xtk_treeview_collapse, xtk_treeview_visit_expanded, xtk_treeview_get_content_height, xtk_treeview_get_content_width, xtk_treeview_get_hover_row, xtk_treeview_set_hover_row, xtk_treeview_config_init_defaults, xtk_treeview_config_parse_styling, xtk_treeview_config_write_styling, xtk_treeview_widget_config_init_defaults, xtk_treeview_widget_config_parse, xtk_treeview_widget_config_write
Types
XtkTreeSpan
A part of a row's label in a color of its own.
A program that lists things of several kinds (the symbols of a file, the lines of compiler output) can give the important part of a label its own color; the rest of the label stays in the row's foreground. On the selected row every span is drawn in the selection's foreground with no background, so the selection stays readable whatever the colors are. Spans must be in the order of the label and must not overlap; a span that goes past the end of the label is cut there. Colors are 0xRRGGBB values (xtk_treeview_rgb() makes one from a ConfigColor).
| Field | Type | Description |
|---|---|---|
start |
unsigned short |
The offset of the span's first byte in the label. |
length |
unsigned short |
The length of the span in bytes. |
color |
unsigned int |
The text color, as 0xRRGGBB. |
background |
unsigned int |
The color behind the text, as 0xRRGGBB; drawn only with XTK_TREE_SPAN_BACKGROUND. |
flags |
unsigned int |
A combination of XTK_TREE_SPAN_BOLD and XTK_TREE_SPAN_BACKGROUND. |
XtkTreeItem
One row, as the program gives it to the tree.
The children callback fills an array of these. The tree copies each item by value, so the strings are fixed arrays rather than pointers (except text, which the tree copies too). The items are zeroed before the callback is called, so a field the program does not set is 0 or "".
| Field | Type | Description |
|---|---|---|
id[XTK_TREEVIEW_ID_MAX] |
char |
The id the program knows the row by. It must be unique in the whole tree and not "". |
label[XTK_TREEVIEW_LABEL_MAX] |
char |
The text drawn on the row (unless text is set). |
icon[64] |
char |
An icon key from xtk_icon.h, drawn before the label. "" or an unknown key draws no icon. |
icon_color |
ConfigColor |
The icon's color, used when icon_color_set is 1. |
icon_color_set |
int |
1 to draw the icon in icon_color; 0 to draw it in the row's text color. |
has_children |
int |
1 if the row can be expanded. The tree asks for its children when it is first expanded. |
unsaved_new |
int |
1 to draw the label bold, in the theme's unsaved-foreground color: the program's sign that the row is new and not yet saved. |
spans[XTK_TREEVIEW_SPANS_MAX] |
XtkTreeSpan |
Parts of the label in colors of their own (see XtkTreeSpan). Only the first span_count are used. |
span_count |
int |
The number of spans set in spans; 0 draws the whole label in one color. |
text |
const char * |
The row's text when it can be longer than label holds (a line of compiler output, a line found by a search), or NULL. When it is set, the row draws it instead of label, the spans count its bytes, and sorting by name uses it. The tree makes its own copy, so the string only has to stay valid until the children callback returns. |
XtkTreeView
typedef struct XtkTreeView XtkTreeView;
A tree view widget (opaque). Made by xtk_treeview_create().
XtkTreeViewChildrenCallback
typedef int (*XtkTreeViewChildrenCallback)(const char *parent_id, XtkTreeItem *out_items, int max_items, void *user_data);
Gives the tree the children of a row.
The tree calls it for the top level when it is created, for a row when that row is first expanded, and for the top level and every expanded row on xtk_treeview_refresh() and xtk_treeview_set_sort_mode(). Fill out_items in the order the rows are to be shown and return how many were written. When the return value equals max_items, the tree doubles the array and calls again, so a row can have any number of children; the callback must build its list from the start on each call.
XtkTreeViewSelectionCallback
typedef void (*XtkTreeViewSelectionCallback)(XtkTreeView *treeview, const char *item_id, void *user_data);
Called each time a row is selected.
It fires for a click, a right-click on another row, the arrow, Home and End keys, and xtk_treeview_select(), even when the row was already selected (except for a right-click). It may read the tree but must not refresh or destroy it.
XtkTreeViewActivateCallback
typedef void (*XtkTreeViewActivateCallback)(XtkTreeView *treeview, const char *item_id, void *user_data);
Called when a row is activated.
It fires for a double-click on a row without children, and for Return or keypad Enter on the selected row (with or without children).
XtkTreeViewContextMenuCallback
typedef void (*XtkTreeViewContextMenuCallback)(XtkTreeView *treeview, const char *item_id, int root_x, int root_y, void *user_data);
Called on a right-click in the tree.
The row under the pointer is selected first. The root coordinates can go straight to xtk_popup_menu_show().
XtkTreeViewScrollCallback
typedef void (*XtkTreeViewScrollCallback)(XtkTreeView *treeview, int delta_y, void *user_data);
Asks the program to scroll the tree up or down.
When this callback is set, the tree does not scroll itself vertically: the wheel (40 pixels a step), a drag of its own vertical thumb, and the auto-scroll during a drag (xtk_treeview_update_drag_autoscroll()) call it instead. The program moves the tree's window (or its viewport) by delta_y, as with xtk_toolwindow_scroll_by(). It may move the tree but must not destroy it.
XtkTreeViewDropPosition
Where a dragged row is dropped, relative to the row under the pointer.
The top third of the target row means BEFORE, the bottom third AFTER, and the middle third ONTO. The tree never offers a target that is the dragged row itself or one of its descendants. BEFORE and AFTER do not require the two rows to have the same parent: they mean "make the dragged row a sibling of the target, at this place". The tree does not know which rows may hold children; a program that does not allow a drop simply ignores it.
| Name | Value | Description |
|---|---|---|
XTK_TREEVIEW_DROP_BEFORE |
Make the dragged row the target's sibling, just before it. | |
XTK_TREEVIEW_DROP_AFTER |
Make the dragged row the target's sibling, just after it. | |
XTK_TREEVIEW_DROP_ONTO |
Make the dragged row a child of the target. |
XtkTreeViewReorderCallback
typedef void (*XtkTreeViewReorderCallback)(XtkTreeView *treeview, const char *dragged_id, const char *target_id, XtkTreeViewDropPosition position, void *user_data);
Called when the user drops a dragged row.
The tree does not move the row itself. The program changes its own data and then calls xtk_treeview_refresh(). The tree has already set its sort order back to XTK_TREEVIEW_SORT_MANUAL, so the new order shows. The callback may refresh or destroy the tree.
XtkTreeViewSortMode
The order in which the children of each row are shown.
Sorting changes only what is shown; the program's own order is kept, so going back to XTK_TREEVIEW_SORT_MANUAL shows it again.
| Name | Value | Description |
|---|---|---|
XTK_TREEVIEW_SORT_MANUAL |
0 |
The order the children callback gives. |
XTK_TREEVIEW_SORT_NAME_ASCENDING |
By label (or text), A to Z, ignoring case. |
|
XTK_TREEVIEW_SORT_NAME_DESCENDING |
By label (or text), Z to A, ignoring case. |
XtkTreeViewExpandedVisitor
typedef void (*XtkTreeViewExpandedVisitor)(const char *item_id, void *user_data);
Called with the id of each expanded row.
Use it with xtk_treeview_visit_expanded() to save which rows are expanded. To restore them, call xtk_treeview_expand() for each saved id, and repeat the pass until it expands nothing new: a row whose parent is not yet expanded is not shown, so expanding it does nothing at first.
Constants
XTK_TREEVIEW_ID_MAX
#define XTK_TREEVIEW_ID_MAX 64
The size of XtkTreeItem.id, the NUL included.
XTK_TREEVIEW_LABEL_MAX
#define XTK_TREEVIEW_LABEL_MAX 128
The size of XtkTreeItem.label, the NUL included.
XTK_TREEVIEW_SPANS_MAX
#define XTK_TREEVIEW_SPANS_MAX 4
The most spans a row's label can have.
XTK_TREE_SPAN_BOLD
#define XTK_TREE_SPAN_BOLD 1
A bit of XtkTreeSpan.flags: the span's text is bold.
XTK_TREE_SPAN_BACKGROUND
#define XTK_TREE_SPAN_BACKGROUND 2
A bit of XtkTreeSpan.flags: the span's background is drawn behind its text.
Functions
xtk_treeview_rgb
unsigned int xtk_treeview_rgb(const ConfigColor color);
Converts a ConfigColor to an XtkTreeSpan color.
| Parameter | Description |
|---|---|
color |
The color. Components outside 0 to 1 are clamped; alpha is ignored. |
Returns: The color as 0xRRGGBB.
xtk_treeview_create
XtkTreeView *xtk_treeview_create(
Display *display,
int screen,
Window parent,
int x,
int y,
int width,
int height,
XtkTreeViewChildrenCallback children_function,
void *children_function_user_data,
const TreeViewBlock *theme,
const XtkConfig *config);
Creates a tree view and loads its top level.
The window is created and mapped at once, and children_function is called for the top level before this returns. theme and config are kept as pointers, not copied.
| Parameter | Description |
|---|---|
display |
The X display. |
screen |
The screen number. |
parent |
The parent window. |
x |
The x position in the parent. |
y |
The y position in the parent. |
width |
The width in pixels (at least 1 is used). |
height |
The height in pixels (at least 1 is used). |
children_function |
The callback that gives the children of a row. It must not be NULL. |
children_function_user_data |
Passed to children_function. |
theme |
The colors and font, usually &config.treeview. When it is NULL the tree draws nothing until xtk_treeview_set_theme() gives it one. |
config |
The configuration that holds the geometry (treeview_widget) and the scrollbar style. It must not be NULL. |
Returns: The new tree view, or NULL when display, children_function or config is NULL or the window cannot be created.
xtk_treeview_destroy
void xtk_treeview_destroy(XtkTreeView *treeview);
Destroys the tree view, its window and all its rows.
| Parameter | Description |
|---|---|
treeview |
The tree view. NULL is allowed and does nothing. |
xtk_treeview_set_theme
void xtk_treeview_set_theme(
XtkTreeView *treeview,
const TreeViewBlock *theme,
const XtkConfig *config);
Gives the tree new colors, font or geometry, and redraws it.
The tree reads its TreeViewBlock and XtkConfig through the pointers it keeps, but it opens its font only here and at creation, and it repaints only when something happens. Call this after a theme change, even when the pointers are the same.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
theme |
The new TreeViewBlock, or NULL to keep the current one. |
config |
The new XtkConfig, or NULL to keep the current one. |
xtk_treeview_get_window
Window xtk_treeview_get_window(const XtkTreeView *treeview);
Gives the tree's window.
| Parameter | Description |
|---|---|
treeview |
The tree view, or NULL. |
Returns: The window, or None when treeview is NULL.
xtk_treeview_set_focused
void xtk_treeview_set_focused(XtkTreeView *treeview, int focused);
Gives or takes the keyboard focus.
With 1, the tree sets the X input focus to its window (when the window is viewable) and draws itself as focused. With 0, it only draws itself as not focused; the X focus moves when another widget takes it.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
focused |
1 to take the focus, 0 to draw the tree as not focused. |
xtk_treeview_get_focused
int xtk_treeview_get_focused(const XtkTreeView *treeview);
Tells whether the tree has the keyboard focus.
| Parameter | Description |
|---|---|
treeview |
The tree view, or NULL. |
Returns: 1 if it has the focus, 0 if not or when treeview is NULL.
xtk_treeview_handle_event
int xtk_treeview_handle_event(XtkTreeView *treeview, XEvent *event);
Handles one X event.
Pass every event of the program's event loop; events for other windows are ignored. See the top of this page for what each event does.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
event |
The event. |
Returns: 1 if the event was for the tree's window (it is then handled, or ignored if the tree has no use for it), 0 if it was for another window or treeview is NULL.
xtk_treeview_resize
void xtk_treeview_resize(XtkTreeView *treeview, int width, int height);
Resizes the tree's window and redraws it.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
width |
The new width in pixels. A value of 0 or less is ignored. |
height |
The new height in pixels. A value of 0 or less is ignored. |
xtk_treeview_set_scroll_offset
void xtk_treeview_set_scroll_offset(XtkTreeView *treeview, int offset_x, int offset_y);
Moves the rows within the window by an offset, and redraws.
The rows are drawn and hit-tested this many pixels up and to the left of where they would be. A program that scrolls by moving the window needs this only when the content is larger than an X window can be (about 32000 pixels): it passes what xtk_toolwindow_get_unrepresented_scroll() gives, and (0, 0) otherwise. A tree without a scroll callback also uses this offset for its own vertical scrolling.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
offset_x |
The horizontal offset in pixels. |
offset_y |
The vertical offset in pixels. |
xtk_treeview_refresh
void xtk_treeview_refresh(XtkTreeView *treeview);
Loads the rows again from the children callback, and redraws.
Call it after the program's data changed outside the tree (a row was renamed, added or deleted). The top level and every expanded row are asked again for their children. Rows whose ids are still there keep their expanded state and their loaded children; collapsed rows are loaded again when they are next expanded. If the selected row is gone, nothing is selected, and the selection callback does not fire.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
xtk_treeview_set_selection_callback
void xtk_treeview_set_selection_callback(
XtkTreeView *treeview,
XtkTreeViewSelectionCallback callback,
void *user_data);
Sets the function called each time a row is selected.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
callback |
The function, or NULL for none. |
user_data |
Passed to the function. |
xtk_treeview_set_activate_callback
void xtk_treeview_set_activate_callback(
XtkTreeView *treeview,
XtkTreeViewActivateCallback callback,
void *user_data);
Sets the function called when a row is activated (double-click or Enter).
| Parameter | Description |
|---|---|
treeview |
The tree view. |
callback |
The function, or NULL for none. |
user_data |
Passed to the function. |
xtk_treeview_set_context_menu_callback
void xtk_treeview_set_context_menu_callback(
XtkTreeView *treeview,
XtkTreeViewContextMenuCallback callback,
void *user_data);
Sets the function called on a right-click in the tree.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
callback |
The function, or NULL for none. |
user_data |
Passed to the function. |
xtk_treeview_set_scroll_callback
void xtk_treeview_set_scroll_callback(
XtkTreeView *treeview,
XtkTreeViewScrollCallback callback,
void *user_data);
Sets the function that scrolls the tree up and down.
With a callback, the tree asks the program to scroll; with none (NULL), the tree scrolls its rows itself. See XtkTreeViewScrollCallback.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
callback |
The function, or NULL for none. |
user_data |
Passed to the function. |
xtk_treeview_set_reorder_callback
void xtk_treeview_set_reorder_callback(
XtkTreeView *treeview,
XtkTreeViewReorderCallback callback,
void *user_data);
Sets the function called when a dragged row is dropped.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
callback |
The function, or NULL for none. With none, rows can still be dragged, but a drop does nothing. |
user_data |
Passed to the function. |
xtk_treeview_update_drag_autoscroll
void xtk_treeview_update_drag_autoscroll(XtkTreeView *treeview);
Scrolls during a drag while the pointer is held near an edge.
Call it on every pass of the program's main loop, whether or not an event came: the X server sends no events while the pointer is still. While a drag is under way and the pointer is within 24 pixels of the top or bottom of the visible part of the tree, it calls the scroll callback with 10 pixels and updates the drop target. It does nothing when no drag is under way or no scroll callback is set.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
xtk_treeview_set_sort_mode
void xtk_treeview_set_sort_mode(XtkTreeView *treeview, XtkTreeViewSortMode mode);
Sets the order of the rows, and reloads them.
When the order changes, this calls xtk_treeview_refresh().
| Parameter | Description |
|---|---|
treeview |
The tree view. |
mode |
The new order. |
xtk_treeview_get_sort_mode
XtkTreeViewSortMode xtk_treeview_get_sort_mode(const XtkTreeView *treeview);
Gives the order of the rows.
| Parameter | Description |
|---|---|
treeview |
The tree view, or NULL. |
Returns: The order; XTK_TREEVIEW_SORT_MANUAL when treeview is NULL.
xtk_treeview_get_selected
const char *xtk_treeview_get_selected(const XtkTreeView *treeview);
Gives the id of the selected row.
| Parameter | Description |
|---|---|
treeview |
The tree view, or NULL. |
Returns: The id, which stays valid until the selection changes, or NULL when nothing is selected.
xtk_treeview_select
void xtk_treeview_select(XtkTreeView *treeview, const char *item_id);
Selects a row, fires the selection callback, and redraws.
Only a row that is shown (all its ancestors expanded) can be selected; for any other id this does nothing. It does not scroll the row into view (see xtk_treeview_get_item_rect()).
| Parameter | Description |
|---|---|
treeview |
The tree view. |
item_id |
The id of the row. |
xtk_treeview_clear_selection
void xtk_treeview_clear_selection(XtkTreeView *treeview);
Clears the selection, and redraws.
Unlike xtk_treeview_select(), it does not fire the selection callback; a program that reacts to "nothing selected" does so itself.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
xtk_treeview_get_item_rect
int xtk_treeview_get_item_rect(
const XtkTreeView *treeview,
const char *item_id,
int *out_y,
int *out_h);
Gives the place of a row in the tree's content.
The position is in the content of the tree, from the first row, without any scroll offset: what a program needs to scroll a row into view itself.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
item_id |
The id of the row. |
out_y |
Receives the top of the row in pixels, or NULL. |
out_h |
Receives the height of the row in pixels, or NULL. |
Returns: 1 if the row is shown (all its ancestors expanded), 0 if not; the outputs are then not changed.
xtk_treeview_expand
void xtk_treeview_expand(XtkTreeView *treeview, const char *item_id);
Expands a row, loading its children if needed, and redraws.
It does nothing when the row is not shown (an ancestor is collapsed), is already expanded, or has has_children 0.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
item_id |
The id of the row. |
xtk_treeview_collapse
void xtk_treeview_collapse(XtkTreeView *treeview, const char *item_id);
Collapses a row, and redraws.
It does nothing when the row is not shown, is already collapsed, or has has_children 0. The row's children stay loaded.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
item_id |
The id of the row. |
xtk_treeview_visit_expanded
void xtk_treeview_visit_expanded(
const XtkTreeView *treeview,
XtkTreeViewExpandedVisitor visitor,
void *user_data);
Calls a function for every expanded row.
Rows under a collapsed ancestor are visited too, if they are expanded themselves.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
visitor |
The function called with each id. |
user_data |
Passed to visitor. |
xtk_treeview_get_content_height
int xtk_treeview_get_content_height(const XtkTreeView *treeview);
Gives the height of all shown rows.
This is the height a program that scrolls by moving the window gives that window (for example with xtk_toolwindow_set_content_size()). It includes an 8-pixel margin below the last row, and the height of the tree's own horizontal scrollbar when it shows one.
| Parameter | Description |
|---|---|
treeview |
The tree view, or NULL. |
Returns: The height in pixels; 0 when no row is shown or treeview is NULL.
xtk_treeview_get_content_width
int xtk_treeview_get_content_width(const XtkTreeView *treeview);
Gives the width of the widest shown row.
The width of a row is its indent, the twisty, the icon and the label. An 8-pixel margin is added. With more than 2000 shown rows, only a sample of them is measured.
| Parameter | Description |
|---|---|
treeview |
The tree view, or NULL. |
Returns: The width in pixels; 0 when no row is shown, the tree has no font, or treeview is NULL.
xtk_treeview_get_hover_row
int xtk_treeview_get_hover_row(const XtkTreeView *treeview);
Gives the row drawn as under the pointer.
| Parameter | Description |
|---|---|
treeview |
The tree view, or NULL. |
Returns: The index of the row among the shown rows, from 0, or -1 for none.
xtk_treeview_set_hover_row
void xtk_treeview_set_hover_row(XtkTreeView *treeview, int row);
Draws a row as under the pointer, without the pointer.
A program can use it to show the hover state from the keyboard.
| Parameter | Description |
|---|---|
treeview |
The tree view. |
row |
The index of the row among the shown rows, from 0, or -1 for none. An index past the last row counts as -1. |
xtk_treeview_config_init_defaults
void xtk_treeview_config_init_defaults(TreeViewBlock *treeview_config);
Fills a TreeViewBlock with the default [treeview] values.
xtk_config_init_defaults() already does this for config.treeview.
| Parameter | Description |
|---|---|
treeview_config |
The block to fill. |
xtk_treeview_config_parse_styling
int xtk_treeview_config_parse_styling(
TreeViewBlock *treeview_config,
const char *key,
const char *value);
Reads one [treeview] key into a TreeViewBlock.
It knows background, border, branch-line, font-family, font-size, foreground, hover-background, selected-background, selected-foreground and unsaved-foreground. The other color keys of the section are read by xtk_config_set().
| Parameter | Description |
|---|---|
treeview_config |
The block to change. |
key |
The key. |
value |
The value, as written in the file. |
Returns: 1 if the key is one of those above, 0 if not or an argument is NULL.
xtk_treeview_config_write_styling
int xtk_treeview_config_write_styling(FILE *file, const TreeViewBlock *treeview_config);
Writes the [treeview] section to a file.
It writes the keys that xtk_treeview_config_parse_styling() reads.
| Parameter | Description |
|---|---|
file |
The open file. |
treeview_config |
The block to write. |
Returns: 1 on success, 0 if an argument is NULL.
xtk_treeview_widget_config_init_defaults
void xtk_treeview_widget_config_init_defaults(XtkConfig *config);
Sets the default [treeview-widget] values in a configuration.
| Parameter | Description |
|---|---|
config |
The configuration to change. |
xtk_treeview_widget_config_parse
int xtk_treeview_widget_config_parse(
XtkConfig *config,
const char *key,
const char *value);
Reads one [treeview-widget] key into a configuration.
| Parameter | Description |
|---|---|
config |
The configuration to change. |
key |
The key: border-width, indent-width, row-height or twisty-size. |
value |
The value, as written in the file. |
Returns: 1 if the key is known, 0 if not or an argument is NULL.
xtk_treeview_widget_config_write
int xtk_treeview_widget_config_write(FILE *file, const XtkConfig *config);
Writes the [treeview-widget] section to a file.
| Parameter | Description |
|---|---|
file |
The open file. |
config |
The configuration to write. |
Returns: 1 on success, 0 if an argument is NULL.
xtk API
Widgets
- button
- checkbox
- radiobutton
- label
- entry
- textview
- edit_history
- spinbutton
- slider
- progressbar
- combobox
- scrollbar
- swatch
- panel
- statusbar
- tooltip
- toolbar
- icongrid
- iconview
- pathbar
- treeview
- datagrid
- graph
- scheme_wheel
- zoom
- tray
Containers and menus
Dialogs
Rich text
Drawing and images
Color
Configuration and themes
Input and the X server
Safety
Data formats