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 <core/gp_compiler.h>
23#include <utils/gp_types.h>
24#include <widgets/gp_common.h>
27
29struct gp_widget {
40 unsigned int type;
48 unsigned int widget_class;
63
70 void *priv;
71
75 unsigned int x, y;
76
80 unsigned int w, h;
81
85 unsigned int min_w, min_h;
86
88 unsigned int align:16;
89
98 unsigned int no_shrink:1;
99 unsigned int no_resize:1;
100
107 unsigned int redraw:1;
108 /*
109 * If set there is a child widget to be repainted, the widget_ops_render()
110 * function is called but the widget itself shouldn't be repainted.
111 */
112 unsigned int redraw_child:1;
113 /*
114 * Redraw whole subtree, i.e. all children and their children, etc.
115 */
116 unsigned int redraw_children:1;
117
121 unsigned int focused:1;
122
128 unsigned int resized:1;
129
136 unsigned int no_events:1;
137
143 unsigned int disabled:1;
144
151 uint32_t event_mask;
152
162 char payload_data[] GP_ALIGNED;
163};
164
170#define GP_WIDGET_PAYLOAD(self) (void*)((self)->payload_data)
171
223
254
262const char *gp_widget_class_name(enum gp_widget_class widget_class);
263
346 GP_LEFT = 0x02,
348 GP_RIGHT = 0x03,
350 GP_HFILL = 0x08,
351
355 GP_TOP = 0x20,
357 GP_BOTTOM = 0x30,
359 GP_VFILL = 0x80,
360
367
368 GP_HCENTER_WEAK = 0x00,
369 GP_VCENTER_WEAK = 0x00,
370};
371
382 enum gp_widget_class widget_class,
383 size_t payload_size);
384
393#define GP_WIDGET_ASSERT(self, ret) do { \
394 if (!self) {\
395 GP_BUG("NULL widget!"); \
396 return ret; \
397 } \
398 } while (0)
399
410#define GP_WIDGET_CLASS_ASSERT(self, wclass, ret) do { \
411 GP_WIDGET_ASSERT(self, ret); \
412 if (self->widget_class != wclass) { \
413 GP_BUG("Invalid widget (%p) class %u != %u", \
414 self, self->widget_class, wclass); \
415 return ret; \
416 } \
417 } while (0)
418
429#define GP_WIDGET_TYPE_ASSERT(self, wtype, ret) do { \
430 GP_WIDGET_ASSERT(self, ret); \
431 if (self->type != wtype) {\
432 GP_BUG("Invalid widget type %s != %s", \
433 gp_widget_type_id(self), gp_widget_type_name(wtype)); \
434 return ret; \
435 } \
436 } while (0)
437
486
496
506
508
509#endif /* GP_WIDGET_H */
A compiler dependent macros.
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:342
@ GP_BOTTOM
Align to the bottom.
Definition gp_widget.h:357
@ GP_RIGHT
Align to the right.
Definition gp_widget.h:348
@ GP_VCENTER
Center vertically.
Definition gp_widget.h:353
@ GP_HFILL
Fill available horizontal space, will strech the widget.
Definition gp_widget.h:350
@ GP_HCENTER
Center horizontally.
Definition gp_widget.h:344
@ GP_FILL
Shortcut for setting both hfill and vfill.
Definition gp_widget.h:366
@ GP_TOP
Align to the top.
Definition gp_widget.h:355
@ GP_VALIGN_MASK
Vertical alignment mask.
Definition gp_widget.h:364
@ GP_HALIGN_MASK
Horizontal alignment mask.
Definition gp_widget.h:362
@ GP_LEFT
Align to the left.
Definition gp_widget.h:346
@ GP_VFILL
Fill available vertical space, will strech the widget.
Definition gp_widget.h:359
void gp_widget_free(gp_widget *self)
Frees widget memory.
gp_widget_class
Widget classes.
Definition gp_widget.h:229
@ GP_WIDGET_CLASS_NONE
Widget has no class, most common case.
Definition gp_widget.h:231
@ GP_WIDGET_CLASS_INT
An integer widget with minimum and maximun.
Definition gp_widget.h:245
@ GP_WIDGET_CLASS_BOOL
Boolean class.
Definition gp_widget.h:239
@ GP_WIDGET_CLASS_CHOICE
A widget to choose a single element from a set.
Definition gp_widget.h:251
gp_widget_type
Widget types.
Definition gp_widget.h:173
@ GP_WIDGET_MAX
A numeber of widgets.
Definition gp_widget.h:221
@ GP_WIDGET_LOG
A widget log widget.
Definition gp_widget.h:213
@ GP_WIDGET_TABLE
A table widget.
Definition gp_widget.h:197
@ GP_WIDGET_GRID
A container widget to create layout.
Definition gp_widget.h:175
@ GP_WIDGET_GRAPH
A graph widget.
Definition gp_widget.h:215
@ GP_WIDGET_RADIOBUTTON
A radiobutton widget.
Definition gp_widget.h:193
@ GP_WIDGET_LABEL
A label widget.
Definition gp_widget.h:183
@ GP_WIDGET_SLIDER
A slider widget.
Definition gp_widget.h:189
@ GP_WIDGET_LAYOUT_SWITCH
A layout switch widget.
Definition gp_widget.h:209
@ GP_WIDGET_PIXMAP
A pixmap widget.
Definition gp_widget.h:199
@ GP_WIDGET_SPINBUTTON
A spinnbutton widget.
Definition gp_widget.h:195
@ GP_WIDGET_SPINNER
A spinner widget.
Definition gp_widget.h:187
@ GP_WIDGET_OVERLAY
An overlay widget.
Definition gp_widget.h:211
@ GP_WIDGET_BUTTON
A button widget.
Definition gp_widget.h:179
@ GP_WIDGET_PROGRESSBAR
A progress bar widget.
Definition gp_widget.h:185
@ GP_WIDGET_STOCK
A stock image widget.
Definition gp_widget.h:201
@ GP_WIDGET_SCROLL_AREA
A scroll area widget.
Definition gp_widget.h:203
@ GP_WIDGET_MARKUP
A markup widget.
Definition gp_widget.h:207
@ GP_WIDGET_SWITCH
A switch widget.
Definition gp_widget.h:217
@ GP_WIDGET_STOCK_SWITCH
A stock switch widget.
Definition gp_widget.h:219
@ GP_WIDGET_TABS
A tabs widget.
Definition gp_widget.h:177
@ GP_WIDGET_CHECKBOX
A checkbox widget.
Definition gp_widget.h:181
@ GP_WIDGET_FRAME
A frame widget.
Definition gp_widget.h:205
@ GP_WIDGET_TBOX
A textbox widget.
Definition gp_widget.h:191
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:29
unsigned int disabled
Internal disabled flag.
Definition gp_widget.h:143
uint32_t event_mask
A mask to enable and disable a widget events.
Definition gp_widget.h:151
gp_widget * parent
Parent widget in the widget tree.
Definition gp_widget.h:55
unsigned int widget_class
A widget class enum gp_widget_class.
Definition gp_widget.h:48
unsigned int align
Widget alignment in parent container, enum gp_widget_alignment.
Definition gp_widget.h:88
unsigned int focused
Set if widget is focused.
Definition gp_widget.h:121
unsigned int type
A widget type enum gp_widget_type.
Definition gp_widget.h:40
unsigned int resized
Internal widget resize flag.
Definition gp_widget.h:128
unsigned int no_shrink
Widget no-shrink flag.
Definition gp_widget.h:98
int(* on_event)(gp_widget_event *)
An application event handler.
Definition gp_widget.h:62
unsigned int no_events
Internal widget flag.
Definition gp_widget.h:136
void * priv
A pointer to arbitrary application data.
Definition gp_widget.h:70
unsigned int redraw
Internal widget repaint flag.
Definition gp_widget.h:107
unsigned int x
A relative offset to the parent widget in pixels.
Definition gp_widget.h:75
unsigned int min_w
Cached widget minimal size in pixel.
Definition gp_widget.h:85
unsigned int w
Current widget size in pixels.
Definition gp_widget.h:80
Common header for types.