libGumball 0.0.1
C23-Based, libGimbal-powered UI Library
Loading...
Searching...
No Matches
gumball_widget.h
Go to the documentation of this file.
1#ifndef GUM_WIDGET_H
2#define GUM_WIDGET_H
3
4// View this file's documentation online: https://libgumball.psyops.studio/gumball__widget_8h.html
5
6/*! \file
7 * \ref GUM_Widget "GUM_Widget data structure and hierarchy graph"
8 * \ingroup elements
9 *
10 * GUM_Widget is the most basic, fundamental element.
11 *
12 * It is the parent class for all drawable elements in libGumball,
13 * holding variables that are common to all drawable elements, such as position, size, and color.
14 *
15 * \todo
16 * - Make variables private
17 * - Separate isRelative into position and size relative
18 * - Add GUM_Vector2 position and size as properties
19 * - Make border highlight configurable (color, thickness)
20 *
21 * \author 2025 Agustín Bellagamba
22 * \copyright MIT License
23*/
24
25#include <gimbal/gimbal_meta.h>
26#include <gimbal/gimbal_strings.h>
27#include <gimbal/gimbal_core.h>
28
29#include <gumball/types/gumball_font.h>
30#include <gumball/types/gumball_texture.h>
31#include <gumball/types/gumball_renderer.h>
32
33/*! \name Type System
34 * \brief Type UUID and cast operators
35 * @{
36*/
37#define GUM_WIDGET_TYPE (GBL_TYPEID (GUM_Widget)) //!< Returns the GUM_Widget Type UUID
38#define GUM_WIDGET(self) (GBL_CAST (GUM_Widget, self)) //!< Casts an instance of a compatible element to a GUM_Widget
39#define GUM_WIDGET_CLASS(klass) (GBL_CLASS_CAST (GUM_Widget, klass)) //!< Casts an class of a compatible element to a GUM_WidgetClass
40#define GUM_WIDGET_CLASSOF(self) (GBL_CLASSOF (GUM_Widget, self)) //!< Casts an instance of a compatible element to a GUM_Widget
41//! @}
42
43#define GBL_SELF_TYPE GUM_Widget
44
45GBL_DECLS_BEGIN
46GBL_FORWARD_DECLARE_STRUCT(GUM_Widget);
47
48/*!
49 * \struct GUM_WidgetClass
50 * \extends GblObjectClass
51 * \brief GUM_Widget structure
52 *
53 * GUM_WidgetClass derives from GblObjectClass,
54 * adding additional virtual functions to handle activating, deactivating, updating, and drawing elements.
55*/
56//! \cond
57GBL_CLASS_DERIVE(GUM_Widget, GblObject)
58 GBL_RESULT (*pFnActivate) (GBL_SELF);
59 GBL_RESULT (*pFnDeactivate) (GBL_SELF);
60 GBL_RESULT (*pFnUpdate) (GBL_SELF);
61 GBL_RESULT (*pFnDraw) (GBL_SELF, GUM_Renderer *pRenderer);
62GBL_CLASS_END
63//! \endcond
64
65/*!
66 * \class GUM_Widget
67 * \extends GblObject
68 * \brief Basic widget element
69*/
70
71/*!
72 * \name Properties
73 * \brief Widget properties you can set/get at or after creation.
74 * @{
75*/
76//! \cond
77GBL_INSTANCE_DERIVE(GUM_Widget, GblObject)
78//! \endcond
79 float x; //!< Horizontal position of the widget. Default value is 0
80 float y; //!< Vertical position of the widget. Default value is 0
81 float w; //!< Width of the widget. Default value is 200
82 float h; //!< Height of the widget. Default value is 200
83 uint8_t r; //!< Red component of the widget color. Default value is 0
84 uint8_t g; //!< Green component of the widget color. Default value is 255
85 uint8_t b; //!< Blue component of the widget color. Default value is 0
86 uint8_t a; //!< Alpha component of the widget color. Default value is 255
87 uint8_t border_r; //!< Red component of the border color. Default value is 0
88 uint8_t border_g; //!< Green component of the border color. Default value is 0
89 uint8_t border_b; //!< Blue component of the border color. Default value is 0
90 uint8_t border_a; //!< Alpha component of the border color. Default value is 0
91 uint8_t border_width; //!< Width of the border, in pixels. Default value is 4
92 float border_radius; //!< Radius of the border. Default value is 0
93 bool border_highlight; //!< If the border should be highlighted. Default value is false
94 bool isRelative; //!< If the widget's position and size should be relative to its parent. Default value is false
95 GblStringRef *label; //!< Optional text label of the widget. Default value is nullptr
96 GUM_Font *font; //!< Optional font for the widget's label. If not set, the default font is used. Default value is nullptr
97 GUM_TextAlignment textAlignment; //!< Alignment of the widget's label. Default value is GUM_TEXT_ALIGN_CENTER \bug This is not working at the moment.
98 GUM_Texture *texture; //!< Optional texture for rendering inside the widget. Default value is nullptr
99 uint8_t font_size; //!< Font size of the widget's label. Default value is 22
100 uint8_t font_r; //!< Red component of the font color. Default value is 255
101 uint8_t font_g; //!< Green component of the font color. Default value is 255
102 uint8_t font_b; //!< Blue component of the font color. Default value is 255
103 uint8_t font_a; //!< Alpha component of the font color. Default value is 255
104 uint8_t font_border_r; //!< Red component of the font border color. Default value is 0
105 uint8_t font_border_g; //!< Green component of the font border color. Default value is 0
106 uint8_t font_border_b; //!< Blue component of the font border color. Default value is 0
107 uint8_t font_border_a; //!< Alpha component of the font border color. Default value is 0
108 uint8_t font_border_thickness; //!< Width of the font border, in pixels. Default value is 1
109 uint8_t z_index; //!< Z-index of the widget. The higher the value, the higher the priority. Default value is 50
110GBL_INSTANCE_END
111//! @}
112
113GBL_PROPERTIES(GUM_Widget,
114 (x, GBL_GENERIC, (READ, WRITE), GBL_FLOAT_TYPE),
115 (y, GBL_GENERIC, (READ, WRITE), GBL_FLOAT_TYPE),
116 (w, GBL_GENERIC, (READ, WRITE), GBL_FLOAT_TYPE),
117 (h, GBL_GENERIC, (READ, WRITE), GBL_FLOAT_TYPE),
118 (isRelative, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
119 (color, GBL_GENERIC, (READ, WRITE), GBL_UINT32_TYPE),
120 (border_color, GBL_GENERIC, (READ, WRITE), GBL_UINT32_TYPE),
121 (font_border_color, GBL_GENERIC, (READ, WRITE), GBL_UINT32_TYPE),
122 (r, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
123 (g, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
124 (b, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
125 (a, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
126 (border_r, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
127 (border_g, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
128 (border_b, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
129 (border_a, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
130 (border_width, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
131 (border_radius, GBL_GENERIC, (READ, WRITE), GBL_FLOAT_TYPE),
132 (border_highlight, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE),
133 (label, GBL_GENERIC, (READ, WRITE), GBL_STRING_TYPE),
134 (texture, GBL_GENERIC, (READ, WRITE), GUM_TEXTURE_TYPE),
135 (textAlignment, GBL_GENERIC, (READ, WRITE), GUM_TEXT_ALIGNMENT_TYPE),
136 (font, GBL_GENERIC, (READ, WRITE), GUM_FONT_TYPE),
137 (font_size, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
138 (font_r, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
139 (font_g, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
140 (font_b, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
141 (font_a, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
142 (font_border_r, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
143 (font_border_g, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
144 (font_border_b, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
145 (font_border_a, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
146 (font_border_thickness, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
147 (z_index, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE)
148)
149
150GblType GUM_Widget_type(void);
151
152//! \cond
153GUM_Vector2 GUM_get_absolute_position_(GBL_SELF);
154//! \endcond
155
156//! Returns a new GUM_Widget. Optionally takes in a list of Name/Value pairs for properties
157#define GUM_Widget_create(/* property_name, property_value */...) GBL_NEW(GUM_Widget __VA_OPT__(,) __VA_ARGS__)
158
159GBL_DECLS_END
160#undef GBL_SELF_TYPE
161
162#endif // GUM_WIDGET_H
uint8_t font_border_g
Green component of the font border color.
Definition gumball_widget.h:105
bool isRelative
If the widget's position and size should be relative to its parent.
Definition gumball_widget.h:94
uint8_t g
Green component of the widget color.
Definition gumball_widget.h:84
uint8_t font_border_r
Red component of the font border color.
Definition gumball_widget.h:104
uint8_t font_border_thickness
Width of the font border, in pixels.
Definition gumball_widget.h:108
uint8_t b
Blue component of the widget color.
Definition gumball_widget.h:85
uint8_t r
Red component of the widget color.
Definition gumball_widget.h:83
float w
Width of the widget.
Definition gumball_widget.h:81
uint8_t border_r
Red component of the border color.
Definition gumball_widget.h:87
uint8_t font_b
Blue component of the font color.
Definition gumball_widget.h:102
GUM_TextAlignment textAlignment
Alignment of the widget's label.
Definition gumball_widget.h:97
uint8_t font_g
Green component of the font color.
Definition gumball_widget.h:101
bool border_highlight
If the border should be highlighted.
Definition gumball_widget.h:93
uint8_t font_size
Font size of the widget's label.
Definition gumball_widget.h:99
float h
Height of the widget.
Definition gumball_widget.h:82
uint8_t border_width
Width of the border, in pixels.
Definition gumball_widget.h:91
uint8_t font_r
Red component of the font color.
Definition gumball_widget.h:100
float border_radius
Radius of the border.
Definition gumball_widget.h:92
GblStringRef * label
Optional text label of the widget.
Definition gumball_widget.h:95
GUM_Texture * texture
Optional texture for rendering inside the widget.
Definition gumball_widget.h:98
float y
Vertical position of the widget.
Definition gumball_widget.h:80
GUM_Font * font
Optional font for the widget's label.
Definition gumball_widget.h:96
uint8_t font_border_a
Alpha component of the font border color.
Definition gumball_widget.h:107
float x
Horizontal position of the widget.
Definition gumball_widget.h:79
uint8_t font_border_b
Blue component of the font border color.
Definition gumball_widget.h:106
uint8_t z_index
Z-index of the widget.
Definition gumball_widget.h:109
uint8_t font_a
Alpha component of the font color.
Definition gumball_widget.h:103
uint8_t border_g
Green component of the border color.
Definition gumball_widget.h:88
uint8_t a
Alpha component of the widget color.
Definition gumball_widget.h:86
uint8_t border_b
Blue component of the border color.
Definition gumball_widget.h:89
uint8_t border_a
Alpha component of the border color.
Definition gumball_widget.h:90