GFXprim
2D bitmap graphics library with emphasis on speed and correctness
|
A widget implementation base. More...
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>
#include <core/gp_debug.h>
#include <utils/gp_types.h>
#include <widgets/gp_common.h>
#include <widgets/gp_widget_types.h>
#include <widgets/gp_widget_disable.h>
#include <widgets/gp_widget_event.h>
Go to the source code of this file.
Data Structures | |
struct | gp_widget |
A widget base. More... | |
Macros | |
#define | GP_WIDGET_PAYLOAD(self) (void*)((self)->payload_data) |
An internal macro to get widget specific data pointer. | |
#define | GP_WIDGET_ASSERT(self, ret) |
Asserts a non NULL widget. | |
#define | GP_WIDGET_CLASS_ASSERT(self, wclass, ret) |
Asserts a widget class. | |
#define | GP_WIDGET_TYPE_ASSERT(self, wtype, ret) |
Asserts a widget type. | |
Functions | |
const char * | gp_widget_class_name (enum gp_widget_class widget_class) |
Returns widget class name. | |
gp_widget * | gp_widget_new (enum gp_widget_type type, enum gp_widget_class widget_class, size_t payload_size) |
Internal function to allocate a widget. | |
void | gp_widget_free (gp_widget *self) |
Frees widget memory. | |
void | gp_widget_set_parent (gp_widget *self, gp_widget *parent) |
Sets widget parent. | |
int | gp_widget_focus_set (gp_widget *self) |
Sets focus to a particular widget. | |
A widget implementation base.
Definition in file gp_widget.h.
#define GP_WIDGET_ASSERT | ( | self, | |
ret | |||
) |
Asserts a non NULL widget.
Prints a warning and exits current function when widget is NULL.
self | A widget. |
ret | Value to be returned when assertion fails. |
Definition at line 392 of file gp_widget.h.
#define GP_WIDGET_CLASS_ASSERT | ( | self, | |
wclass, | |||
ret | |||
) |
Asserts a widget class.
Prints a warning and exits current function when widget class does not match expected class.
self | A widget. |
wclass | A widget class, enum gp_widget_class. |
ret | Value to be returned when assertion fails. |
Definition at line 409 of file gp_widget.h.
#define GP_WIDGET_PAYLOAD | ( | self | ) | (void*)((self)->payload_data) |
An internal macro to get widget specific data pointer.
Definition at line 169 of file gp_widget.h.
#define GP_WIDGET_TYPE_ASSERT | ( | self, | |
wtype, | |||
ret | |||
) |
Asserts a widget type.
Prints a warning and exits current function when widget type does not match expected type.
self | A widget. |
wtype | A widget type, enum gp_widget_type. |
ret | Value to be returned when assertion fails. |
Definition at line 428 of file gp_widget.h.
enum gp_widget_alignment |
A widget alignment.
Defines a widget alignment in the parent container, the bottom half of the byte defines horizontal alignment, the top half vertical alignment.
The widgets are organized in a two dimensional tree where each widget/layer is an rectangle in a plane. The rectanles on a given tree layer are distinct and the rectanle on an upper layer contains all rectangles on lower layer.
The widget layout is computed in two steps, first minimal size is computed recursively from the top level widget down to the leaf widgets, then if the window is bigger than the minimal needed size, the leftover space is being distributed between the widgets.
In order for a widget to take more space than the minimal size, i.e. be resizable the horizontal and/or vertical alignment has to be set to fill. Which especially means that layout can be resized only and only if the top level layout widget is resizable. Apart from fill each widget can be set to be positioned top/center/bottom vertically as well as left/center/right horizontally.
Grid horizontal and vertical alignment set to fill button to center
Widget layout in JSON:
Horizontal and vertical alignment set to fill for both
Widget layout in JSON:
Horizontal and vertical alignment set to center for grid
The button alignment does not matter in this case, since it exaclty fits its assigned space.
Widget layout in JSON:
Definition at line 341 of file gp_widget.h.
enum gp_widget_class |
Widget classes.
Class widgets are operated on by a class functions rather than widget specific functions.
Enumerator | |
---|---|
GP_WIDGET_CLASS_NONE | Widget has no class, most common case. |
GP_WIDGET_CLASS_BOOL | Boolean class. The widget has two values, e.g. checkbox. See gp_widget_class_bool.h for the list of functions. |
GP_WIDGET_CLASS_INT | An integer widget with minimum and maximun. See gp_widget_class_int.h for the list of functions. |
GP_WIDGET_CLASS_CHOICE | A widget to choose a single element from a set. See gp_widget_class_choice.h for the list of functions. |
Definition at line 228 of file gp_widget.h.
enum gp_widget_type |
Widget types.
Definition at line 172 of file gp_widget.h.
const char * gp_widget_class_name | ( | enum gp_widget_class | widget_class | ) |
Returns widget class name.
widget_class | A widget class. |
int gp_widget_focus_set | ( | gp_widget * | self | ) |
Sets focus to a particular widget.
Traverses the widget layout tree to the top and sets the focus accordingly.
self | A widget to be focused. |
void gp_widget_free | ( | gp_widget * | self | ) |
Frees widget memory.
Following actions are done when widget is being freed:
self | A widget. |
Referenced by gp_widget_grid_del(), gp_widget_tabs_tab_del(), and gp_widget_tabs_tab_del_by_child().
gp_widget * gp_widget_new | ( | enum gp_widget_type | type, |
enum gp_widget_class | widget_class, | ||
size_t | payload_size | ||
) |
Internal function to allocate a widget.
type | A widget type. |
widget_class | A widget class. |
payload_size | A widet payload size. |