libGumball 0.0.2
C23-Based, libGimbal-powered UI Library
Loading...
Searching...
No Matches
gumball_container.h
Go to the documentation of this file.
1#ifndef GUM_CONTAINER_H
2#define GUM_CONTAINER_H
3
4// View this file's documentation online: https://libgumball.psyops.studio/gumball__container_8h.html
5
6/*! \file
7 * \ref GUM_Container "GUM_Container data structure and hierarchy graph"
8 * \ingroup elements
9 *
10 * GUM_Container is a container element that can hold other widgets.
11 * It can be used to group widgets together, and to optionally automatically resize / align them as needed.
12 *
13 * \todo
14 * - Make variables private
15 * - Make orientation an enum
16 * - Add scrolling
17 *
18 * \author 2025 Agustín Bellagamba
19 * \copyright MIT License
20*/
21
22#include "gimbal/meta/classes/gimbal_primitives.h"
23#include "gumball_widget.h"
24#include <stdint.h>
25
26/*! \name Type System
27 * \brief Type UUID and cast operators
28 * @{
29*/
30#define GUM_CONTAINER_TYPE (GBL_TYPEID (GUM_Container)) //!< Returns the GUM_Container Type UUID
31#define GUM_CONTAINER(self) (GBL_CAST (GUM_Container, self)) //!< Casts an instance of a compatible element to a GUM_Container
32#define GUM_CONTAINER_CLASS(klass) (GBL_CLASS_CAST (GUM_Container, klass)) //!< Casts a class of a compatible element to a GUM_ContainerClass
33#define GUM_CONTAINER_CLASSOF(self) (GBL_CLASSOF (GUM_Container, self)) //!< Casts an instance of a compatible element to a GUM_ContainerClass
34//! @}
35
36#define GBL_SELF_TYPE GUM_Container
37
38GBL_DECLS_BEGIN
39GBL_FORWARD_DECLARE_STRUCT(GUM_Container);
40
41/*!
42 \struct GUM_ContainerClass
43 \extends GUM_WidgetClass
44 \brief GUM_Container structure
45
46 GUM_ContainerClass derives from GUM_WidgetClass,
47 adding a virtual function to update the content of the container.
48*/
49GBL_CLASS_DERIVE(GUM_Container, GUM_Widget)
50 GBL_RESULT (*pFnUpdateContent)(GBL_SELF); //!< Updates the content of the container, resizing and realigning child widgets as needed.
52
53/*!
54 * \class GUM_Container
55 * \extends GUM_Widget
56 * \brief Container element
57 *
58*/
59
60/*!
61 \name Properties
62 \brief Properties you can set/get at or after creation.
63 \note You can also set/get properties from parent classes (see \ref GUM_Container).
64 @{
65*/
67 float padding; //!< The space between the container's border and its child widgets. Default value is 5
68 float margin; //!< The space between child widgets. Default value is 5
69 float minChildSize; /*! The minimum amount of space a child widget should take,
70 in percentage of the container's size. Default value is 0.15 (15%) */
71 char orientation; //!< 'h' for horizontal, 'v' for vertical layout of child widgets. Default value is 'v' \warning This is planned to be replaced by an enum.
72 bool resizeWidgets; //!< If child widgets should be resized to take an equal amount of space. Default value is true
73 bool alignWidgets; //!< If child widgets should be aligned. Default value is true
74 bool scrollable; //!< If the container should become scrollable when its content is bigger than itself Default value is true
75
76 // TODO: private!
77 float scrollOffsetX; // Horizontal scroll offset
78 float scrollOffsetY; // Vertical scroll offset
79GBL_INSTANCE_END
80//! @}
81
82GBL_PROPERTIES(GUM_Container,
83 (padding, GBL_GENERIC, (READ, WRITE), GBL_FLOAT_TYPE),
84 (margin, GBL_GENERIC, (READ, WRITE), GBL_FLOAT_TYPE),
85 (minChildSize, GBL_GENERIC, (READ, WRITE), GBL_FLOAT_TYPE),
86 (orientation, GBL_GENERIC, (READ, WRITE), GBL_CHAR_TYPE ),
87 (resizeWidgets, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE ),
88 (alignWidgets, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE ),
89 (scrollable, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE )
90)
91
92GblType GUM_Container_type(void);
93
94//! Returns a new GUM_Container. Optionally takes in a list of Name/Value pairs for properties
95#define GUM_Container_create(/* propertyName, propertyValue */ ...) GBL_NEW(GUM_Container __VA_OPT__(,) __VA_ARGS__)
96
97GBL_DECLS_END
98#undef GBL_SELF_TYPE
99
100#endif // GUM_CONTAINER_H
Container element.
bool resizeWidgets
If child widgets should be resized to take an equal amount of space.
Definition gumball_container.h:72
char orientation
The minimum amount of space a child widget should take, in percentage of the container's size.
Definition gumball_container.h:71
bool scrollable
If the container should become scrollable when its content is bigger than itself Default value is tru...
Definition gumball_container.h:74
float margin
The space between child widgets.
Definition gumball_container.h:68
bool alignWidgets
If child widgets should be aligned.
Definition gumball_container.h:73