Table of Contents
- xtk_frame.h
- Types
- Functions
- xtk_frame_create
- xtk_frame_destroy
- xtk_frame_get_window
- xtk_frame_set_position
- xtk_frame_resize
- xtk_frame_set_title
- xtk_frame_get_content_area
- xtk_frame_set_child
- xtk_frame_handle_event
- xtk_frame_draw
- xtk_frame_set_theme
- xtk_frame_config_init_defaults
- xtk_frame_config_parse_styling
- xtk_frame_config_write_styling
- xtk_frame_widget_config_init_defaults
- xtk_frame_widget_config_parse
- xtk_frame_widget_config_write
xtk_frame.h
A titled group box: a border around a group of widgets, with a title in its top edge.
A frame draws a rounded border and, if it has a title, puts the title into a gap in the top edge (the "group box" of other toolkits). It shows that a set of widgets belongs together. The frame takes no input: it only draws. Its window has the parent's background (ParentRelative), so the parent shows through inside and around the border.
A frame can hold its widgets in two ways:
- Side by side: make the frame and the widgets as children of the same parent window, with the frame's box around theirs. The frame lowers its window when it is made, so it stays behind them whatever the order they were made in. The frame knows nothing of them and does not move them.
- Inside: make the widgets with
xtk_frame_get_window()as their parent and place them in the boxxtk_frame_get_content_area()gives. For one child (a panel, or a window laid out by xtk_grid.h),xtk_frame_set_child()moves the child into the frame and keeps it filling the content area whenever the frame is resized.
Making it. Call xtk_frame_create() with the parent window, the box, the title and the whole XtkConfig. The frame maps its window and draws at once. The program owns the frame and frees it with xtk_frame_destroy(), which destroys its window and with it every window inside it.
Events. Pass each XEvent to xtk_frame_handle_event(). It redraws on the last Expose of a series and returns 1 for every event on the frame's own window, 0 for others. Events of child windows are not the frame's. xtk_frame_resize(), xtk_frame_set_title() and xtk_frame_set_theme() redraw at once.
Theme keys. Section [frame]:
border: the color of the border line. Default#595959.font-family: the title's font family. Defaultsans.font-size: the title's font size in pixels; 0 hides the title. Default 11.
Section [frame-widget] (sizes in pixels):
border-width: how many pixels thick the border line is; 0 or less draws no border. The value also widens the margin of the content area. Default 1.border-radius: the corner radius. Default 6.title-gap: the space between the title and the border line on each side of the title. Default 6.title-indent: how far the gap for the title starts from the left edge. Default 12.
The title's color is the [label] section's color. The defaults are those xtk_config_init_defaults() sets; a theme applied with xtk_theme_apply() replaces the colors.
Example.
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);
XtkFrame *frame = xtk_frame_create(display, screen, window,
10, 10, 300, 200, "Options", &config);
int x, y, width, height;
xtk_frame_get_content_area(frame, &x, &y, &width, &height);
// make the frame's widgets with xtk_frame_get_window(frame) as their
// parent, inside the box x, y, width, height
XEvent event;
while (running) {
XNextEvent(display, &event);
if (xtk_frame_handle_event(frame, &event)) continue;
// ... the frame's widgets and the program's other windows
}
xtk_frame_destroy(frame);
*
Limitations.
- The title keeps at most 127 bytes. A title wider than the frame is cut off at the frame's right edge.
- With a NULL config the frame draws nothing (no border, no title) until
xtk_frame_set_theme()is called.
#include "xtk_frame.h"
Types: XtkFrame
Functions: xtk_frame_create, xtk_frame_destroy, xtk_frame_get_window, xtk_frame_set_position, xtk_frame_resize, xtk_frame_set_title, xtk_frame_get_content_area, xtk_frame_set_child, xtk_frame_handle_event, xtk_frame_draw, xtk_frame_set_theme, xtk_frame_config_init_defaults, xtk_frame_config_parse_styling, xtk_frame_config_write_styling, xtk_frame_widget_config_init_defaults, xtk_frame_widget_config_parse, xtk_frame_widget_config_write
Types
XtkFrame
typedef struct XtkFrame XtkFrame;
A titled group box; opaque, made by xtk_frame_create().
Functions
xtk_frame_create
XtkFrame *xtk_frame_create(
Display *display,
int screen,
Window parent,
int x,
int y,
int width,
int height,
const char *title,
const XtkConfig *config);
Create a frame, map its window below its siblings and draw it.
| Parameter | Description |
|---|---|
display |
The X display |
screen |
The screen number |
parent |
The parent window |
x |
The X position in the parent, in pixels |
y |
The Y position in the parent, in pixels |
width |
The width in pixels; values below 1 become 1 |
height |
The height in pixels; values below 1 become 1 |
title |
The title shown in the top edge, copied (at most 127 bytes); NULL or "" for none |
config |
The configuration: it reads the frame and frame_widget blocks and the label text color, and copies them. May be NULL (the frame then draws nothing until xtk_frame_set_theme()). |
Returns: The new frame, or NULL if display is NULL, memory runs out or the window cannot be made
xtk_frame_destroy
void xtk_frame_destroy(XtkFrame *frame);
Destroy the frame, its font and its window.
Destroying the window also destroys every window inside it, such as a child set with xtk_frame_set_child(); destroy the widgets inside the frame first.
| Parameter | Description |
|---|---|
frame |
The frame (NULL does nothing) |
xtk_frame_get_window
Window xtk_frame_get_window(const XtkFrame *frame);
Get the frame's X window, the parent for widgets inside it.
| Parameter | Description |
|---|---|
frame |
The frame |
Returns: The window, or None if frame is NULL
xtk_frame_set_position
void xtk_frame_set_position(XtkFrame *frame, int x, int y);
Move the frame within its parent.
Windows inside the frame move with it; widgets beside it (side by side) do not.
| Parameter | Description |
|---|---|
frame |
The frame (NULL does nothing) |
x |
The new X position in the parent, in pixels |
y |
The new Y position in the parent, in pixels |
xtk_frame_resize
void xtk_frame_resize(XtkFrame *frame, int width, int height);
Resize the frame, fit its child (if one was set with xtk_frame_set_child()) to the new content area, and redraw.
| Parameter | Description |
|---|---|
frame |
The frame (NULL does nothing) |
width |
The new width in pixels; values below 1 become 1 |
height |
The new height in pixels; values below 1 become 1 |
xtk_frame_set_title
void xtk_frame_set_title(XtkFrame *frame, const char *title);
Set the title shown in the top edge, fit the child (if one was set with xtk_frame_set_child()) to the content area, which a title added or removed moves, and redraw.
| Parameter | Description |
|---|---|
frame |
The frame (NULL does nothing) |
title |
The title, copied (at most 127 bytes); NULL or "" for none |
xtk_frame_get_content_area
void xtk_frame_get_content_area(
const XtkFrame *frame,
int *x,
int *y,
int *width,
int *height);
Get the content area: the box inside the border and below the title, in the coordinates of the frame's window.
Place widgets made with xtk_frame_get_window() as their parent inside this box. It leaves a margin of border-width plus 4 pixels on each side. The width and height are at least 1. Any pointer may be NULL.
| Parameter | Description |
|---|---|
frame |
The frame; if NULL, all four values are 0 |
x |
Receives the X of the box |
y |
Receives the Y of the box |
width |
Receives the width of the box |
height |
Receives the height of the box |
xtk_frame_set_child
void xtk_frame_set_child(XtkFrame *frame, Window child);
Move a window into the frame, fit it to the content area and map it.
The frame then keeps the child filling the content area whenever xtk_frame_resize() or xtk_frame_set_theme() is called. The frame holds one child; a new call replaces the old one (which stays where it is). With None the frame stops fitting its child, but the child stays inside the frame's window and is not destroyed.
| Parameter | Description |
|---|---|
frame |
The frame (NULL does nothing) |
child |
The window to hold, or None to let go of the current one |
xtk_frame_handle_event
int xtk_frame_handle_event(XtkFrame *frame, XEvent *event);
Give an X event to the frame.
On the last Expose of a series (count 0) the frame redraws itself.
| Parameter | Description |
|---|---|
frame |
The frame |
event |
The event |
Returns: 1 if the event was for the frame's own window, 0 if it was for another window or frame or event is NULL
xtk_frame_draw
void xtk_frame_draw(XtkFrame *frame);
Redraw the frame's border and title now.
| Parameter | Description |
|---|---|
frame |
The frame (NULL does nothing) |
xtk_frame_set_theme
void xtk_frame_set_theme(XtkFrame *frame, const XtkConfig *config);
Take new styles from a configuration, fit the child to the new content area, and redraw.
Call it after a new theme is applied to the configuration.
| Parameter | Description |
|---|---|
frame |
The frame (NULL does nothing) |
config |
The configuration (NULL does nothing): its frame and frame_widget blocks and the label text color |
xtk_frame_config_init_defaults
void xtk_frame_config_init_defaults(FrameBlock *frame_config);
Set a FrameBlock to the [frame] defaults (listed above).
xtk_config_init_defaults() already calls it for config.frame.
| Parameter | Description |
|---|---|
frame_config |
The block to set (NULL does nothing) |
xtk_frame_config_parse_styling
int xtk_frame_config_parse_styling(
FrameBlock *frame_config,
const char *key,
const char *value);
Set one [frame] key of a FrameBlock from its text value.
The config file reader calls it for each key of the section.
| Parameter | Description |
|---|---|
frame_config |
The block to change |
key |
The key, for example "font-size" |
value |
The value as written in the file |
Returns: 1 if the key is a [frame] key, 0 if not or an argument is NULL
xtk_frame_config_write_styling
int xtk_frame_config_write_styling(FILE *file, const FrameBlock *frame_config);
Write a FrameBlock as a [frame] section, with every key.
| Parameter | Description |
|---|---|
file |
The file to write to |
frame_config |
The block to write |
Returns: 1 on success, 0 if an argument is NULL
xtk_frame_widget_config_init_defaults
void xtk_frame_widget_config_init_defaults(XtkConfig *config);
Set the [frame-widget] defaults (listed above) in a configuration.
xtk_config_init_defaults() already calls it.
| Parameter | Description |
|---|---|
config |
The configuration to change (NULL does nothing) |
xtk_frame_widget_config_parse
int xtk_frame_widget_config_parse(XtkConfig *config, const char *key, const char *value);
Set one [frame-widget] key of a configuration from its text value.
The config file reader calls it for each key of the section.
| Parameter | Description |
|---|---|
config |
The configuration to change |
key |
The key, for example "title-indent" |
value |
The value as written in the file (a whole number) |
Returns: 1 if the key is a [frame-widget] key, 0 if not or an argument is NULL
xtk_frame_widget_config_write
int xtk_frame_widget_config_write(FILE *file, const XtkConfig *config);
Write a configuration's [frame-widget] section, with every key.
| Parameter | Description |
|---|---|
file |
The file to write to |
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