Table of Contents
- xtk_pathbar.h
- Types
- Functions
- xtk_pathbar_create
- xtk_pathbar_destroy
- xtk_pathbar_get_window
- xtk_pathbar_set_position
- xtk_pathbar_resize
- xtk_pathbar_get_size
- xtk_pathbar_show
- xtk_pathbar_hide
- xtk_pathbar_set_path
- xtk_pathbar_set_place
- xtk_pathbar_get_path
- xtk_pathbar_set_go_callback
- xtk_pathbar_set_edited_callback
- xtk_pathbar_begin_edit
- xtk_pathbar_end_edit
- xtk_pathbar_is_editing
- xtk_pathbar_set_placeholder
- xtk_pathbar_set_ime
- xtk_pathbar_handle_event
- xtk_pathbar_update_blink
- xtk_pathbar_draw
- xtk_pathbar_set_theme
- xtk_pathbar_config_init_defaults
- xtk_pathbar_config_parse_styling
- xtk_pathbar_config_write_styling
xtk_pathbar.h
A folder's path as breadcrumbs: a click on a folder goes there, a click elsewhere types a path.
What it is for. Showing where a file dialog or a file manager is, and going somewhere else: the path is written in one box the color of a text field, as "/ home > me > src". The pointer over a folder's name lights it up as a pill in the accent color; a click on it gives that folder to the program. A path too long for the box keeps "/" and the last folders, with "..." for the ones left out, so the folder shown is always there.
Typing a path. A click on the box but on no name, or xtk_pathbar_begin_edit() (a program's Ctrl+L), turns the box into a text field (an XtkEntry the same size, in the same place) holding the path, all selected so typing replaces it. Return gives the typed text to the program; Escape, or a click outside the field, gives the breadcrumbs back. While the field shows, every key press given to the bar is the field's.
Making one. xtk_pathbar_create() makes it mapped, showing "/". Set the folder with xtk_pathbar_set_path(), or a place that is not a folder (a program's Trash) with xtk_pathbar_set_place(). The program learns of a click through xtk_pathbar_set_go_callback() and of a typed path through xtk_pathbar_set_edited_callback(); a callback may set the bar's path, or destroy it.
Events. Give every event to xtk_pathbar_handle_event(); call xtk_pathbar_update_blink() from the main loop for the field's caret.
Theme keys. [pathbar]: background (the box), color (the names and the separators), hover-background (the pill), hover-color (the name in the pill), border (the box's edge). The names are drawn in [main] font-family and font-size; the field is an entry, in [entry-text]'s colors.
Example.
staticvoidwent(XtkPathBar*bar,constchar*path,intbutton,void*user_data){
xtk_pathbar_set_path(bar,path);//arealprogramliststhefolderfirst
}
XtkPathBar*bar=xtk_pathbar_create(display,screen,window,&config,clipboard,8,8,400,30);
xtk_pathbar_set_path(bar,"/home/me/src");
xtk_pathbar_set_go_callback(bar,went,NULL);
while(running){
XNextEvent(display,&event);
xtk_pathbar_handle_event(bar,&event);
xtk_pathbar_update_blink(bar);
}
xtk_pathbar_destroy(bar);
Limitations. It shows a path, not a URI: a place that is not a folder is one name (xtk_pathbar_set_place()). A name has no menu of the folders beside it.
#include "xtk_pathbar.h"
Types: XtkPathBar, XtkPathBarGoCallback, XtkPathBarEditedCallback
Functions: xtk_pathbar_create, xtk_pathbar_destroy, xtk_pathbar_get_window, xtk_pathbar_set_position, xtk_pathbar_resize, xtk_pathbar_get_size, xtk_pathbar_show, xtk_pathbar_hide, xtk_pathbar_set_path, xtk_pathbar_set_place, xtk_pathbar_get_path, xtk_pathbar_set_go_callback, xtk_pathbar_set_edited_callback, xtk_pathbar_begin_edit, xtk_pathbar_end_edit, xtk_pathbar_is_editing, xtk_pathbar_set_placeholder, xtk_pathbar_set_ime, xtk_pathbar_handle_event, xtk_pathbar_update_blink, xtk_pathbar_draw, xtk_pathbar_set_theme, xtk_pathbar_config_init_defaults, xtk_pathbar_config_parse_styling, xtk_pathbar_config_write_styling
Types
XtkPathBar
typedef struct XtkPathBar XtkPathBar;
XtkPathBarGoCallback
typedef void (*XtkPathBarGoCallback)(XtkPathBar *pathbar, const char *path, int button, void *user_data);
Called when a folder's name is clicked.
XtkPathBarEditedCallback
typedef void (*XtkPathBarEditedCallback)(XtkPathBar *pathbar, const char *text, void *user_data);
Called when the path field closes.
Functions
xtk_pathbar_create
XtkPathBar *xtk_pathbar_create(
Display *display,
int screen,
Window parent,
const XtkConfig *config,
XtkClipboard *clipboard,
int x,
int y,
int width,
int height);
Make a path bar, mapped, showing "/".
| Parameter | Description |
|---|---|
display |
The X display |
screen |
The screen number |
parent |
The window it sits in |
config |
The theme; kept, not copied (the program keeps it alive) |
clipboard |
For the path field's copy and paste, or NULL |
x |
The x position in the parent |
y |
The y position in the parent |
width |
Its width |
height |
Its height (the field's too) |
Returns: The path bar, or NULL if display or config is NULL or memory runs out
xtk_pathbar_destroy
void xtk_pathbar_destroy(XtkPathBar *pathbar);
Destroy the path bar, its field and its window. NULL does nothing.
xtk_pathbar_get_window
Window xtk_pathbar_get_window(const XtkPathBar *pathbar);
The bar's window (the breadcrumbs'), or None.
xtk_pathbar_set_position
void xtk_pathbar_set_position(XtkPathBar *pathbar, int x, int y);
Move the bar in its parent; a hidden bar stays hidden.
xtk_pathbar_resize
void xtk_pathbar_resize(XtkPathBar *pathbar, int width, int height);
Resize the bar (and its field).
xtk_pathbar_get_size
void xtk_pathbar_get_size(const XtkPathBar *pathbar, int *width, int *height);
The bar's size.
xtk_pathbar_show
void xtk_pathbar_show(XtkPathBar *pathbar);
Show the bar (the breadcrumbs, or the field if it was being typed in).
xtk_pathbar_hide
void xtk_pathbar_hide(XtkPathBar *pathbar);
Hide the bar; a field being typed in closes, as with Escape.
xtk_pathbar_set_path
void xtk_pathbar_set_path(XtkPathBar *pathbar, const char *path);
Show a folder's path. The pill under the pointer goes; an open path field stays open.
| Parameter | Description |
|---|---|
pathbar |
The path bar |
path |
A full path ("/" for the top) |
xtk_pathbar_set_place
void xtk_pathbar_set_place(XtkPathBar *pathbar, const char *label, const char *location);
Show a place that is not a folder as one name ("Trash").
| Parameter | Description |
|---|---|
pathbar |
The path bar |
label |
The name shown |
location |
What a click on it gives the go callback, and the path field holds ("trash:///") |
xtk_pathbar_get_path
const char *xtk_pathbar_get_path(const XtkPathBar *pathbar);
The path or place location shown.
xtk_pathbar_set_go_callback
void xtk_pathbar_set_go_callback(
XtkPathBar *pathbar,
XtkPathBarGoCallback callback,
void *user_data);
Set the function called when a name is clicked (NULL for none).
xtk_pathbar_set_edited_callback
void xtk_pathbar_set_edited_callback(
XtkPathBar *pathbar,
XtkPathBarEditedCallback callback,
void *user_data);
Set the function called when the path field closes (NULL for none).
xtk_pathbar_begin_edit
void xtk_pathbar_begin_edit(XtkPathBar *pathbar, const char *text);
Turn the box into the path field and give it the keyboard.
| Parameter | Description |
|---|---|
pathbar |
The path bar |
text |
The field's text, the caret after it; NULL for the path shown, all selected |
xtk_pathbar_end_edit
void xtk_pathbar_end_edit(XtkPathBar *pathbar);
Close the field as Escape does (the edited callback is called with NULL).
xtk_pathbar_is_editing
int xtk_pathbar_is_editing(const XtkPathBar *pathbar);
1 while the path field shows.
xtk_pathbar_set_placeholder
void xtk_pathbar_set_placeholder(XtkPathBar *pathbar, const char *text);
The grey text the empty field shows (NULL for none).
xtk_pathbar_set_ime
void xtk_pathbar_set_ime(XtkPathBar *pathbar, XIM input_method);
The input method the field types through (xtk_ime_open()), or NULL.
xtk_pathbar_handle_event
int xtk_pathbar_handle_event(XtkPathBar *pathbar, XEvent *event);
Give the bar an X event.
Returns: 1 when it took it: an event of its window or its field's, or, while the field shows, any key press
xtk_pathbar_update_blink
void xtk_pathbar_update_blink(XtkPathBar *pathbar);
The field's caret blink; call it from every pass of the main loop.
xtk_pathbar_draw
void xtk_pathbar_draw(XtkPathBar *pathbar);
Draw the breadcrumbs again.
xtk_pathbar_set_theme
void xtk_pathbar_set_theme(XtkPathBar *pathbar, const XtkConfig *config);
Take a new theme (kept, not copied), and draw in it.
xtk_pathbar_config_init_defaults
void xtk_pathbar_config_init_defaults(PathBarBlock *pathbar_config);
The [pathbar] colors a config starts with (a dark look).
xtk_pathbar_config_parse_styling
int xtk_pathbar_config_parse_styling(
PathBarBlock *pathbar_config,
const char *key,
const char *value);
Read one [pathbar] key; 1 when it was one.
xtk_pathbar_config_write_styling
int xtk_pathbar_config_write_styling(FILE *file, const PathBarBlock *pathbar_config);
Write the [pathbar] section.
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