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
162};
163
169#define GP_WIDGET_PAYLOAD(self) (void*)((self)->payload_data)
170
222
253
261const char *gp_widget_class_name(enum gp_widget_class widget_class);
262
345 GP_LEFT = 0x02,
347 GP_RIGHT = 0x03,
349 GP_HFILL = 0x08,
350
354 GP_TOP = 0x20,
356 GP_BOTTOM = 0x30,
358 GP_VFILL = 0x80,
359
366
367 GP_HCENTER_WEAK = 0x00,
368 GP_VCENTER_WEAK = 0x00,
369};
370
381 enum gp_widget_class widget_class,
382 size_t payload_size);
383
392#define GP_WIDGET_ASSERT(self, ret) do { \
393 if (!self) {\
394 GP_BUG("NULL widget!"); \
395 return ret; \
396 } \
397 } while (0)
398
409#define GP_WIDGET_CLASS_ASSERT(self, wclass, ret) do { \
410 GP_WIDGET_ASSERT(self, ret); \
411 if (self->widget_class != wclass) { \
412 GP_BUG("Invalid widget (%p) class %u != %u", \
413 self, self->widget_class, wclass); \
414 return ret; \
415 } \
416 } while (0)
417
428#define GP_WIDGET_TYPE_ASSERT(self, wtype, ret) do { \
429 GP_WIDGET_ASSERT(self, ret); \
430 if (self->type != wtype) {\
431 GP_BUG("Invalid widget type %s != %s", \
432 gp_widget_type_id(self), gp_widget_type_name(wtype)); \
433 return ret; \
434 } \
435 } while (0)
436
485
495
505
507
508#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:341
@ GP_BOTTOM
Align to the bottom.
Definition gp_widget.h:356
@ GP_RIGHT
Align to the right.
Definition gp_widget.h:347
@ GP_VCENTER
Center vertically.
Definition gp_widget.h:352
@ GP_HFILL
Fill available horizontal space, will strech the widget.
Definition gp_widget.h:349
@ GP_HCENTER
Center horizontally.
Definition gp_widget.h:343
@ GP_FILL
Shortcut for setting both hfill and vfill.
Definition gp_widget.h:365
@ GP_TOP
Align to the top.
Definition gp_widget.h:354
@ GP_VALIGN_MASK
Vertical alignment mask.
Definition gp_widget.h:363
@ GP_HALIGN_MASK
Horizontal alignment mask.
Definition gp_widget.h:361
@ GP_LEFT
Align to the left.
Definition gp_widget.h:345
@ GP_VFILL
Fill available vertical space, will strech the widget.
Definition gp_widget.h:358
void gp_widget_free(gp_widget *self)
Frees widget memory.
gp_widget_class
Widget classes.
Definition gp_widget.h:228
@ GP_WIDGET_CLASS_NONE
Widget has no class, most common case.
Definition gp_widget.h:230
@ GP_WIDGET_CLASS_INT
An integer widget with minimum and maximun.
Definition gp_widget.h:244
@ GP_WIDGET_CLASS_BOOL
Boolean class.
Definition gp_widget.h:238
@ GP_WIDGET_CLASS_CHOICE
A widget to choose a single element from a set.
Definition gp_widget.h:250
gp_widget_type
Widget types.
Definition gp_widget.h:172
@ GP_WIDGET_MAX
A numeber of widgets.
Definition gp_widget.h:220
@ GP_WIDGET_LOG
A widget log widget.
Definition gp_widget.h:212
@ GP_WIDGET_TABLE
A table widget.
Definition gp_widget.h:196
@ GP_WIDGET_GRID
A container widget to create layout.
Definition gp_widget.h:174
@ GP_WIDGET_GRAPH
A graph widget.
Definition gp_widget.h:214
@ GP_WIDGET_RADIOBUTTON
A radiobutton widget.
Definition gp_widget.h:192
@ GP_WIDGET_LABEL
A label widget.
Definition gp_widget.h:182
@ GP_WIDGET_SLIDER
A slider widget.
Definition gp_widget.h:188
@ GP_WIDGET_LAYOUT_SWITCH
A layout switch widget.
Definition gp_widget.h:208
@ GP_WIDGET_PIXMAP
A pixmap widget.
Definition gp_widget.h:198
@ GP_WIDGET_SPINBUTTON
A spinnbutton widget.
Definition gp_widget.h:194
@ GP_WIDGET_SPINNER
A spinner widget.
Definition gp_widget.h:186
@ GP_WIDGET_OVERLAY
An overlay widget.
Definition gp_widget.h:210
@ GP_WIDGET_BUTTON
A button widget.
Definition gp_widget.h:178
@ GP_WIDGET_PROGRESSBAR
A progress bar widget.
Definition gp_widget.h:184
@ GP_WIDGET_STOCK
A stock image widget.
Definition gp_widget.h:200
@ GP_WIDGET_SCROLL_AREA
A scroll area widget.
Definition gp_widget.h:202
@ GP_WIDGET_MARKUP
A markup widget.
Definition gp_widget.h:206
@ GP_WIDGET_SWITCH
A switch widget.
Definition gp_widget.h:216
@ GP_WIDGET_STOCK_SWITCH
A stock switch widget.
Definition gp_widget.h:218
@ GP_WIDGET_TABS
A tabs widget.
Definition gp_widget.h:176
@ GP_WIDGET_CHECKBOX
A checkbox widget.
Definition gp_widget.h:180
@ GP_WIDGET_FRAME
A frame widget.
Definition gp_widget.h:204
@ GP_WIDGET_TBOX
A textbox widget.
Definition gp_widget.h:190
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
char payload_data[]
Private widget data area.
Definition gp_widget.h:161
Common header for types.