Stardew Engine
Loading...
Searching...
No Matches
Widget.h
Go to the documentation of this file.
1#ifndef WIDGET_H
2#define WIDGET_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7#include "ObjectPool.h"
8#include "HandleDefs.h"
9#include <stdbool.h>
10#include "DynArray.h"
11#include "Geometry.h"
12
13
14struct UIWidget;
16struct DataNode;
17
18
19
20#ifdef __cplusplus
21typedef int(*PrintfFn)(const char* fmt, ...);
22
23#else
24typedef int(*PrintfFn)(const char* restrict fmt, ...);
25#endif // __cplusplus
26
31
32typedef float(*GetUIWidgetDimensionFn)(struct UIWidget* pWidget, struct UIWidget* pParent);
33typedef void(*LayoutChildrenFn)(struct UIWidget* pWidget, struct UIWidget* pParent);
34typedef void(*OnDestroyWidgetFn)(struct UIWidget* pWidget);
35typedef void*(*OutputWidgetVerticesFn)(struct UIWidget* pThisWidget, VECTOR(WidgetVertex) pOutVerts);
36typedef void(*OnWidgetInitFn)(struct UIWidget* pWidget);
37typedef void(*OnBoundPropertyChangedFn)(struct UIWidget* pThisWidget, struct WidgetPropertyBinding* pBinding);
38
39typedef struct WidgetDim* (*WidgetDimGetterFn)(struct UIWidget* pWidget);
40
41typedef void (*FocusedWidgetRecieveKeystrokeFn)(struct UIWidget* pWidget, int keystroke);
42
43typedef void (*OnChildrenChangedFn)(struct UIWidget* pWidget);
44
45struct WidgetDim* GetWidgetWidthDim(struct UIWidget* pWidget);
46struct WidgetDim* GetWidgetHeightDim(struct UIWidget* pWidget);
47
55
57{
58 float scaleX;
59 float scaleY;
60};
61
82
89
96
109
111{
113 float data;
114};
115
116
117
118#define LUA_CALLBACK_MAX_NAME_LEN 64
125
137
138typedef void (*WidgetMousePosCallbackFn)(struct UIWidget* pWidget, float x, float y);
139typedef void (*WidgetMouseBtnCallbackFn)(struct UIWidget* pWidget, float x, float y, int btn);
140typedef void (*WidgetFocusChangeCallbackFn)(struct UIWidget* pWidget);
141
156
157
163
169
170// todo: make somehow glue this to the input system or change the input system to fit this
171#define NUM_BUTTONS 3
172#define MAX_PROPERTY_NAME_LEN 32
173#define MAX_NUM_BINDINGS 16
174
183
185{
187 union
188 {
189 int i;
190 float flt;
191 char* str;
192 bool bl;
194 char name[MAX_PROPERTY_NAME_LEN + 1]; // attribute content
195 char boundPropertyName[MAX_PROPERTY_NAME_LEN + 1];// attribute name
196};
197
199{
200 float x;
201 float y;
203};
204
238
239
240void UI_Init();
241
242
243void UI_DestroyWidget(HWidget widget);
244
246
248
249size_t UI_CountWidgetChildrenPtr(struct UIWidget* pWidget);
250
251size_t UI_CountWidgetChildren(HWidget pWidget);
252
253struct UIWidget* UI_GetWidget(HWidget hWidget);
254
255struct UIWidget* UI_FirstChild(HWidget hWidget);
256
257void UI_AddChild(HWidget hParent, HWidget hChild);
258
259float UI_ResolveWidthDimPxls(struct UIWidget* pWidget, const struct WidgetDim* dim);
260
261float UI_ResolveHeightDimPxls(struct UIWidget* pWidget, const struct WidgetDim* dim);
262
263
268void UI_WidgetCommonInit(struct DataNode* pInNode, struct UIWidget* outWidget);
269
275void UI_DebugPrintCommonWidgetInfo(const struct UIWidget* inWidget, PrintfFn pPrintfFn);
276
277void* UI_Helper_OnOutputVerts(struct UIWidget* pWidget, VECTOR(WidgetVertex) pOutVerts);
278
279void UI_Helper_OnLayoutChildren(struct UIWidget* pWidget, struct UIWidget* pParent);
280
281void UI_GetWidgetSize(HWidget hWidget, float* pOutW, float* pOutH);
282
287void UI_GetWidgetTopLeft(HWidget hWidget, float* pOutLeft, float* pOutTop);
288
289void UI_GetWidgetPadding(HWidget hWidget, float* pOutPaddingTop, float* pOutPaddingBottom, float* pOutPaddingLeft, float* pOutPaddingRight);
290
296void UI_SendWidgetMouseEvent(struct UIWidget* pWidget, enum WidgetCallbackTypes type, struct WidgetMouseInfo* pMouseInfo);
297
301void UI_GetHitBox(GeomRect outRect, HWidget hWidget);
302
309bool UI_IsAttributeStringABindingExpression(const char* attributeValue);
310
321void UI_AddStringPropertyBinding(struct UIWidget* pWidget, char* inBoundPropertyName, char* inBindingExpression, char** pOutData, int viewmodelTableIndex);
322
323void UI_AddIntPropertyBinding(struct UIWidget* pWidget, char* inBoundPropertyName, char* inBindingExpression, int* pOutData, int viewmodelTableIndex);
324
325void UI_AddFloatPropertyBinding(struct UIWidget* pWidget, char* inBoundPropertyName, char* inBindingExpression, float* pOutData, int viewmodelTableIndex);
326
331char* UI_MakeBindingGetterFunctionName(const char* inBindingName);
332
333char* UI_MakeBindingSetterFunctionName(const char* inBindingName);
334
336
338
339#ifdef __cplusplus
340}
341#endif
342
343#endif
vec4 GeomRect
Definition Geometry.h:13
HGeneric HWidget
Definition HandleDefs.h:8
uint64_t u64
Definition IntTypes.h:15
#define VECTOR(a)
Definition WfGame.h:8
void(* WidgetMouseBtnCallbackFn)(struct UIWidget *pWidget, float x, float y, int btn)
Definition Widget.h:139
void UI_DestroyWidget(HWidget widget)
Definition Widget.c:117
void UI_WidgetCommonInit(struct DataNode *pInNode, struct UIWidget *outWidget)
Init common attributes that all widgets can have.
Definition Widget.c:558
void UI_GetWidgetSize(HWidget hWidget, float *pOutW, float *pOutH)
Definition Widget.c:702
WidgetCallbackTypes
Definition Widget.h:127
@ WC_OnMouseEnter
Definition Widget.h:128
@ WC_OnMouseDown
Definition Widget.h:131
@ WC_OnMouseUp
Definition Widget.h:132
@ WC_OnLeaveFocus
Definition Widget.h:134
@ WC_OnMouseLeave
Definition Widget.h:129
@ WC_NUM
Definition Widget.h:135
@ WC_OnMouseMove
Definition Widget.h:130
@ WC_OnGainFocus
Definition Widget.h:133
void UI_AddChild(HWidget hParent, HWidget hChild)
Definition Widget.c:79
void UI_AddIntPropertyBinding(struct UIWidget *pWidget, char *inBoundPropertyName, char *inBindingExpression, int *pOutData, int viewmodelTableIndex)
Definition Widget.c:821
void UI_GetHitBox(GeomRect outRect, HWidget hWidget)
Get the AABB of the widget, excluding padding.
Definition Widget.c:730
void *(* OutputWidgetVerticesFn)(struct UIWidget *pThisWidget, VECTOR(WidgetVertex) pOutVerts)
Definition Widget.h:35
int(* PrintfFn)(const char *restrict fmt,...)
Definition Widget.h:24
float UI_ResolveHeightDimPxls(struct UIWidget *pWidget, const struct WidgetDim *dim)
Definition Widget.c:372
size_t UI_CountWidgetChildrenPtr(struct UIWidget *pWidget)
Definition Widget.c:40
void UI_AddStringPropertyBinding(struct UIWidget *pWidget, char *inBoundPropertyName, char *inBindingExpression, char **pOutData, int viewmodelTableIndex)
Add a bound string property entry to the widget and initialise a value by calling the binding getter ...
Definition Widget.c:798
WidgetDockPoint
Definition Widget.h:98
@ WDP_MiddleRight
Definition Widget.h:102
@ WDP_BottomMiddle
Definition Widget.h:104
@ WDP_BottomLeft
Definition Widget.h:105
@ WDP_MiddleLeft
Definition Widget.h:106
@ WDP_Centre
Definition Widget.h:107
@ WDP_TopLeft
Definition Widget.h:99
@ WDP_TopMiddle
Definition Widget.h:100
@ WDP_TopRight
Definition Widget.h:101
@ WDP_BottomRight
Definition Widget.h:103
#define LUA_CALLBACK_MAX_NAME_LEN
Definition Widget.h:118
#define MAX_NUM_BINDINGS
Definition Widget.h:173
struct WidgetDim * GetWidgetHeightDim(struct UIWidget *pWidget)
Definition Widget.c:250
float UI_ResolveWidthDimPxls(struct UIWidget *pWidget, const struct WidgetDim *dim)
Definition Widget.c:328
void(* WidgetMousePosCallbackFn)(struct UIWidget *pWidget, float x, float y)
Definition Widget.h:138
void(* OnWidgetInitFn)(struct UIWidget *pWidget)
Definition Widget.h:36
void(* OnDestroyWidgetFn)(struct UIWidget *pWidget)
Definition Widget.h:34
void UI_GetWidgetTopLeft(HWidget hWidget, float *pOutLeft, float *pOutTop)
get top left BEFORE padding is applied (the raw top left)
Definition Widget.c:722
void(* OnChildrenChangedFn)(struct UIWidget *pWidget)
Definition Widget.h:43
void UI_SendWidgetMouseEvent(struct UIWidget *pWidget, enum WidgetCallbackTypes type, struct WidgetMouseInfo *pMouseInfo)
send a mouse event to the widget that will be handled either by either or both a lua function and a c...
Definition Widget.c:637
struct UIWidget * UI_GetWidget(HWidget hWidget)
Definition Widget.c:60
bool UI_IsAttributeStringABindingExpression(const char *attributeValue)
Definition Widget.c:746
void(* FocusedWidgetRecieveKeystrokeFn)(struct UIWidget *pWidget, int keystroke)
Definition Widget.h:41
void UI_Helper_OnLayoutChildren(struct UIWidget *pWidget, struct UIWidget *pParent)
Definition Widget.c:623
float(* GetUIWidgetDimensionFn)(struct UIWidget *pWidget, struct UIWidget *pParent)
Definition Widget.h:32
size_t UI_CountWidgetChildren(HWidget pWidget)
Definition Widget.c:53
void UI_DebugPrintCommonWidgetInfo(const struct UIWidget *inWidget, PrintfFn pPrintfFn)
print a text representation of the widget tree. Falls appart if a widget fails to implement its debug...
Definition Widget.c:596
#define MAX_PROPERTY_NAME_LEN
Definition Widget.h:172
WidgetHorizontalAlignment
Definition Widget.h:84
@ WHA_Middle
Definition Widget.h:86
@ WHA_Left
Definition Widget.h:85
@ WHA_Right
Definition Widget.h:87
void UI_GetWidgetPadding(HWidget hWidget, float *pOutPaddingTop, float *pOutPaddingBottom, float *pOutPaddingLeft, float *pOutPaddingRight)
Definition Widget.c:711
HWidget UI_NewBlankWidget()
Definition Widget.c:23
void(* LayoutChildrenFn)(struct UIWidget *pWidget, struct UIWidget *pParent)
Definition Widget.h:33
void UI_DefaultOnChildrenChanged(struct UIWidget *outWidget)
Definition Widget.c:546
void(* OnBoundPropertyChangedFn)(struct UIWidget *pThisWidget, struct WidgetPropertyBinding *pBinding)
Definition Widget.h:37
struct WidgetPropertyBinding * UI_FindBinding(struct UIWidget *pWidget, const char *bindingName)
Definition Widget.c:776
char * UI_MakeBindingGetterFunctionName(const char *inBindingName)
USER MUST FREE RETURNED PTR append Get_ to the start of the string.
Definition Widget.c:752
void * UI_Helper_OnOutputVerts(struct UIWidget *pWidget, VECTOR(WidgetVertex) pOutVerts)
Definition Widget.c:608
void(* WidgetFocusChangeCallbackFn)(struct UIWidget *pWidget)
Definition Widget.h:140
void UI_Init()
Definition Widget.c:105
void UI_AddFloatPropertyBinding(struct UIWidget *pWidget, char *inBoundPropertyName, char *inBindingExpression, float *pOutData, int viewmodelTableIndex)
Definition Widget.c:842
WidgetPropertyBindingType
Definition Widget.h:176
@ WBT_Int
Definition Widget.h:177
@ WBT_WidgetTree
Definition Widget.h:181
@ WBT_Float
Definition Widget.h:178
@ WBT_Bool
Definition Widget.h:180
@ WBT_String
Definition Widget.h:179
WidgetVerticalAlignment
Definition Widget.h:91
@ WVA_Middle
Definition Widget.h:93
@ WVA_Bottom
Definition Widget.h:94
@ WVA_Top
Definition Widget.h:92
struct UIWidget * UI_FirstChild(HWidget hWidget)
Definition Widget.c:69
struct WidgetDim * GetWidgetWidthDim(struct UIWidget *pWidget)
Definition Widget.c:249
char * UI_MakeBindingSetterFunctionName(const char *inBindingName)
Definition Widget.c:764
WidgetDimType
some are relative to their parent. In which case these should be relative to THEIR parent,...
Definition Widget.h:64
@ WD_Percentage
a percentage of parents dimension but as a decimal between 0 and 1
Definition Widget.h:80
@ WD_Auto
take as much space as it naturally takes
Definition Widget.h:66
@ WD_Stretch
stretch to fill all available space
Definition Widget.h:68
@ WD_StretchFraction
a fraction that's relative with other children. meaning this: width: 1* ---—| width: 2* --------—| | ...
Definition Widget.h:78
@ WD_Pixels
a literal value
Definition Widget.h:70
HWidget UI_GetScratchWiget()
Definition Widget.c:111
int cJSON_bool fmt
Definition cJSON.h:166
Definition Widget.h:159
struct CWidgetMouseCallback Callbacks[WC_NUM]
Definition Widget.h:160
this isn't some "hungarian notation" shit - the name refers to widget callbacks defined as C function...
Definition Widget.h:144
union CWidgetMouseCallback::@23 callback
WidgetFocusChangeCallbackFn focusChangeFn
Definition Widget.h:150
enum WidgetCallbackTypes type
Definition Widget.h:145
WidgetMousePosCallbackFn mousePosFn
Definition Widget.h:148
u64 bActive
A random value we can check is zero to determine if the callback is set.
Definition Widget.h:153
WidgetMouseBtnCallbackFn mouseBtnFn
Definition Widget.h:149
Definition DataNode.h:53
Definition Widget.h:120
char name[LUA_CALLBACK_MAX_NAME_LEN+1]
Definition Widget.h:121
size_t nameLen
Definition Widget.h:122
bool bActive
Definition Widget.h:123
Definition Widget.h:165
int viewmodelTable
Definition Widget.h:166
struct LuaWidgetCallback Callbacks[WC_NUM]
Definition Widget.h:167
Definition Widget.h:206
struct WidgetDim width
Definition Widget.h:228
struct WidgetPadding padding
Definition Widget.h:224
FocusedWidgetRecieveKeystrokeFn fnRecieveKeystroke
Definition Widget.h:219
struct LuaWidgetCallbacks scriptCallbacks
Definition Widget.h:225
struct WidgetPropertyBinding bindings[MAX_NUM_BINDINGS]
Definition Widget.h:227
WidgetDockPoint dockPoint
Definition Widget.h:223
struct WidgetDim height
Definition Widget.h:229
GetUIWidgetDimensionFn fnGetHeight
Definition Widget.h:213
LayoutChildrenFn fnLayoutChildren
Definition Widget.h:214
OutputWidgetVerticesFn fnOutputVertices
Definition Widget.h:216
bool bAcceptsFocus
Definition Widget.h:235
void * pImplementationData
Definition Widget.h:211
GetUIWidgetDimensionFn fnGetWidth
Definition Widget.h:212
HWidget hPrev
Definition Widget.h:208
HWidget hFirstChild
Definition Widget.h:210
HWidget hParent
Definition Widget.h:209
OnWidgetInitFn fnOnWidgetInit
Definition Widget.h:218
WidgetHorizontalAlignment horizontalAlignment
Definition Widget.h:233
bool bHasFocus
Definition Widget.h:236
WidgetVerticalAlignment verticalAlignment
Definition Widget.h:234
float offsetY
Definition Widget.h:232
size_t numBindings
Definition Widget.h:230
HWidget hNext
Definition Widget.h:207
OnChildrenChangedFn fnOnWidgetChildrenChangedFn
Definition Widget.h:220
float top
Definition Widget.h:221
OnBoundPropertyChangedFn fnOnBoundPropertyChanged
Definition Widget.h:217
struct CWidgetCallbacks cCallbacks
Definition Widget.h:226
float left
Definition Widget.h:222
float offsetX
Definition Widget.h:231
OnDestroyWidgetFn fnOnDestroy
Definition Widget.h:215
Definition DrawContext.h:34
Definition DrawContext.h:27
Definition Widget.h:111
float data
Definition Widget.h:113
enum WidgetDimType type
Definition Widget.h:112
Definition Widget.h:199
int button
Definition Widget.h:202
float x
Definition Widget.h:200
float y
Definition Widget.h:201
Definition Widget.h:49
float paddingTop
Definition Widget.h:50
float paddingLeft
Definition Widget.h:52
float paddingRight
Definition Widget.h:53
float paddingBottom
Definition Widget.h:51
Definition Widget.h:185
char boundPropertyName[MAX_PROPERTY_NAME_LEN+1]
Definition Widget.h:195
union WidgetPropertyBinding::@24 data
bool bl
Definition Widget.h:192
enum WidgetPropertyBindingType type
Definition Widget.h:186
float flt
Definition Widget.h:190
int i
Definition Widget.h:189
char name[MAX_PROPERTY_NAME_LEN+1]
Definition Widget.h:194
char * str
Definition Widget.h:191
Definition Widget.h:57
float scaleY
Definition Widget.h:59
float scaleX
Definition Widget.h:58