GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget.h
Go to the documentation of this file.
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2024 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
14#ifndef GP_WIDGET_H
15#define GP_WIDGET_H
16
17#include <stdlib.h>
18#include <stdint.h>
19#include <inttypes.h>
20#include <stdbool.h>
21#include <core/gp_debug.h>
22#include <utils/gp_types.h>
23#include <widgets/gp_common.h>
26
28struct gp_widget {
39 unsigned int type;
47 unsigned int widget_class;
62
69 void *priv;
70
74 unsigned int x, y;
75
79 unsigned int w, h;
80
84 unsigned int min_w, min_h;
85
87 unsigned int align:16;
88
97 unsigned int no_shrink:1;
98 unsigned int no_resize:1;
99
106 unsigned int redraw:1;
107 /*
108 * If set there is a child widget to be repainted, the widget_ops_render()
109 * function is called but the widget itself shouldn't be repainted.
110 */
111 unsigned int redraw_child:1;
112 /*
113 * Redraw whole subtree, i.e. all children and their children, etc.
114 */
115 unsigned int redraw_children:1;
116
120 unsigned int focused:1;
121
127 unsigned int resized:1;
128
135 unsigned int no_events:1;
136
142 unsigned int disabled:1;
143
150 uint32_t event_mask;
151
152 union {
153 struct gp_widget_grid *grid;
154 struct gp_widget_tabs *tabs;
155
156 struct gp_widget_bool *b;
157 struct gp_widget_bool *button;
158 struct gp_widget_bool *checkbox;
159
160 struct gp_widget_label *label;
161
162 struct gp_widget_int *i;
163 struct gp_widget_pbar *pbar;
164 struct gp_widget_int *spin;
165 struct gp_widget_int *slider;
166
167 struct gp_widget_tbox *tbox;
168
169 struct gp_widget_choice *choice;
170
171 struct gp_widget_table *tbl;
172
173 struct gp_widget_pixmap *pixmap;
174
175 struct gp_widget_stock *stock;
176
177 struct gp_widget_scroll_area *scroll;
178
179 struct gp_widget_frame *frame;
180
181 struct gp_widget_markup *markup;
182
183 struct gp_widget_switch *switch_;
184
185 struct gp_widget_overlay *overlay;
186
187 struct gp_widget_log *log;
188
189 struct gp_widget_graph *graph;
190
191 void *payload;
192 };
193 char buf[];
194};
195
243
274
282const char *gp_widget_class_name(enum gp_widget_class widget_class);
283
366 GP_LEFT = 0x02,
368 GP_RIGHT = 0x03,
370 GP_HFILL = 0x08,
371
375 GP_TOP = 0x20,
377 GP_BOTTOM = 0x30,
379 GP_VFILL = 0x80,
380
387
388 GP_HCENTER_WEAK = 0x00,
389 GP_VCENTER_WEAK = 0x00,
390};
391
402 enum gp_widget_class widget_class,
403 size_t payload_size);
404
413#define GP_WIDGET_ASSERT(self, ret) do { \
414 if (!self) {\
415 GP_BUG("NULL widget!"); \
416 return ret; \
417 } \
418 } while (0)
419
430#define GP_WIDGET_CLASS_ASSERT(self, wclass, ret) do { \
431 GP_WIDGET_ASSERT(self, ret); \
432 if (self->widget_class != wclass) { \
433 GP_BUG("Invalid widget (%p) class %u != %u", \
434 self, self->widget_class, wclass); \
435 return ret; \
436 } \
437 } while (0)
438
449#define GP_WIDGET_TYPE_ASSERT(self, wtype, ret) do { \
450 GP_WIDGET_ASSERT(self, ret); \
451 if (self->type != wtype) {\
452 GP_BUG("Invalid widget type %s != %s", \
453 gp_widget_type_id(self), gp_widget_type_name(wtype)); \
454 return ret; \
455 } \
456 } while (0)
457
506
514
524
526
527#endif /* GP_WIDGET_H */
A debug message layer.
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.
int gp_widget_focus_set(gp_widget *self)
Sets focus to a particular widget.
gp_widget_alignment
A widget alignment.
Definition gp_widget.h:362
@ GP_BOTTOM
Align to the bottom.
Definition gp_widget.h:377
@ GP_RIGHT
Align to the right.
Definition gp_widget.h:368
@ GP_VCENTER
Center vertically.
Definition gp_widget.h:373
@ GP_HFILL
Fill available horizontal space, will strech the widget.
Definition gp_widget.h:370
@ GP_HCENTER
Center horizontally.
Definition gp_widget.h:364
@ GP_FILL
Shortcut for setting both hfill and vfill.
Definition gp_widget.h:386
@ GP_TOP
Align to the top.
Definition gp_widget.h:375
@ GP_VALIGN_MASK
Vertical alignment mask.
Definition gp_widget.h:384
@ GP_HALIGN_MASK
Horizontal alignment mask.
Definition gp_widget.h:382
@ GP_LEFT
Align to the left.
Definition gp_widget.h:366
@ GP_VFILL
Fill available vertical space, will strech the widget.
Definition gp_widget.h:379
void gp_widget_free(gp_widget *self)
Frees widget memory.
gp_widget_class
Widget classes.
Definition gp_widget.h:249
@ GP_WIDGET_CLASS_NONE
Widget has no class, most common case.
Definition gp_widget.h:251
@ GP_WIDGET_CLASS_INT
An integer widget with minimum and maximun.
Definition gp_widget.h:265
@ GP_WIDGET_CLASS_BOOL
Boolean class.
Definition gp_widget.h:259
@ GP_WIDGET_CLASS_CHOICE
A widget to choose a single element from a set.
Definition gp_widget.h:271
gp_widget_type
Widget types.
Definition gp_widget.h:197
@ GP_WIDGET_MAX
A numeber of widgets.
Definition gp_widget.h:241
@ GP_WIDGET_LOG
A widget log widget.
Definition gp_widget.h:237
@ GP_WIDGET_TABLE
A table widget.
Definition gp_widget.h:221
@ GP_WIDGET_GRID
A container widget to create layout.
Definition gp_widget.h:199
@ GP_WIDGET_GRAPH
A graph widget.
Definition gp_widget.h:239
@ GP_WIDGET_RADIOBUTTON
A radiobutton widget.
Definition gp_widget.h:217
@ GP_WIDGET_LABEL
A label widget.
Definition gp_widget.h:207
@ GP_WIDGET_SLIDER
A slider widget.
Definition gp_widget.h:213
@ GP_WIDGET_PIXMAP
A pixmap widget.
Definition gp_widget.h:223
@ GP_WIDGET_SPINBUTTON
A spinnbutton widget.
Definition gp_widget.h:219
@ GP_WIDGET_SPINNER
A spinner widget.
Definition gp_widget.h:211
@ GP_WIDGET_OVERLAY
An overlay widget.
Definition gp_widget.h:235
@ GP_WIDGET_BUTTON
A button widget.
Definition gp_widget.h:203
@ GP_WIDGET_PROGRESSBAR
A progress bar widget.
Definition gp_widget.h:209
@ GP_WIDGET_STOCK
A stock image widget.
Definition gp_widget.h:225
@ GP_WIDGET_SCROLL_AREA
A scroll area widget.
Definition gp_widget.h:227
@ GP_WIDGET_MARKUP
A markup widget.
Definition gp_widget.h:231
@ GP_WIDGET_SWITCH
A layout switch widget.
Definition gp_widget.h:233
@ GP_WIDGET_TABS
A tabs widget.
Definition gp_widget.h:201
@ GP_WIDGET_CHECKBOX
A checkbox widget.
Definition gp_widget.h:205
@ GP_WIDGET_FRAME
A frame widget.
Definition gp_widget.h:229
@ GP_WIDGET_TBOX
A textbox widget.
Definition gp_widget.h:215
const char * gp_widget_class_name(enum gp_widget_class widget_class)
Returns widget class name.
void gp_widget_set_parent(gp_widget *self, gp_widget *parent)
Sets widget parent.
Functions to disable and enable widgets.
Widget event handling.
Common widget types.
Event structure passed to widget event handler.
A widget base.
Definition gp_widget.h:28
unsigned int disabled
Internal disabled flag.
Definition gp_widget.h:142
uint32_t event_mask
A mask to enable and disable a widget events.
Definition gp_widget.h:150
gp_widget * parent
Parent widget in the widget tree.
Definition gp_widget.h:54
unsigned int widget_class
A widget class enum gp_widget_class.
Definition gp_widget.h:47
unsigned int align
Widget alignment in parent container, enum gp_widget_alignment.
Definition gp_widget.h:87
unsigned int focused
Set if widget is focused.
Definition gp_widget.h:120
unsigned int type
A widget type enum gp_widget_type.
Definition gp_widget.h:39
unsigned int resized
Internal widget resize flag.
Definition gp_widget.h:127
unsigned int no_shrink
Widget no-shrink flag.
Definition gp_widget.h:97
int(* on_event)(gp_widget_event *)
An application event handler.
Definition gp_widget.h:61
unsigned int no_events
Internal widget flag.
Definition gp_widget.h:135
void * priv
A pointer to arbitrary application data.
Definition gp_widget.h:69
unsigned int redraw
Internal widget repaint flag.
Definition gp_widget.h:106
unsigned int x
A relative offset to the parent widget in pixels.
Definition gp_widget.h:74
unsigned int min_w
Cached widget minimal size in pixel.
Definition gp_widget.h:84
unsigned int w
Current widget size in pixels.
Definition gp_widget.h:79
Common header for types.