Stardew Engine
Loading...
Searching...
No Matches
Widget.h File Reference
#include "ObjectPool.h"
#include "HandleDefs.h"
#include <stdbool.h>
#include "DynArray.h"
#include "Geometry.h"
Include dependency graph for Widget.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  WidgetPadding
 
struct  WidgetScale
 
struct  WidgetDim
 
struct  LuaWidgetCallback
 
struct  CWidgetMouseCallback
 this isn't some "hungarian notation" shit - the name refers to widget callbacks defined as C functions! More...
 
struct  CWidgetCallbacks
 
struct  LuaWidgetCallbacks
 
struct  WidgetPropertyBinding
 
struct  WidgetMouseInfo
 
struct  UIWidget
 

Macros

#define LUA_CALLBACK_MAX_NAME_LEN   64
 
#define NUM_BUTTONS   3
 
#define MAX_PROPERTY_NAME_LEN   32
 
#define MAX_NUM_BINDINGS   16
 

Typedefs

typedef int(* PrintfFn) (const char *restrict fmt,...)
 
typedef struct Vert2DColourTexture WidgetVertex
 
typedef struct Vert2DColourTextureQuad WidgetQuad
 
typedef float(* GetUIWidgetDimensionFn) (struct UIWidget *pWidget, struct UIWidget *pParent)
 
typedef void(* LayoutChildrenFn) (struct UIWidget *pWidget, struct UIWidget *pParent)
 
typedef void(* OnDestroyWidgetFn) (struct UIWidget *pWidget)
 
typedef void *(* OutputWidgetVerticesFn) (struct UIWidget *pThisWidget, VECTOR(WidgetVertex) pOutVerts)
 
typedef void(* OnWidgetInitFn) (struct UIWidget *pWidget)
 
typedef void(* OnBoundPropertyChangedFn) (struct UIWidget *pThisWidget, struct WidgetPropertyBinding *pBinding)
 
typedef struct WidgetDim *(* WidgetDimGetterFn) (struct UIWidget *pWidget)
 
typedef void(* FocusedWidgetRecieveKeystrokeFn) (struct UIWidget *pWidget, int keystroke)
 
typedef void(* OnChildrenChangedFn) (struct UIWidget *pWidget)
 
typedef enum WidgetHorizontalAlignment WidgetHorizontalAlignment
 
typedef enum WidgetVerticalAlignment WidgetVerticalAlignment
 
typedef enum WidgetDockPoint WidgetDockPoint
 
typedef void(* WidgetMousePosCallbackFn) (struct UIWidget *pWidget, float x, float y)
 
typedef void(* WidgetMouseBtnCallbackFn) (struct UIWidget *pWidget, float x, float y, int btn)
 
typedef void(* WidgetFocusChangeCallbackFn) (struct UIWidget *pWidget)
 

Enumerations

enum  WidgetDimType {
  WD_Auto , WD_Stretch , WD_Pixels , WD_StretchFraction ,
  WD_Percentage
}
 some are relative to their parent. In which case these should be relative to THEIR parent, fixed, or the top level window. More...
 
enum  WidgetHorizontalAlignment { WHA_Left , WHA_Middle , WHA_Right }
 
enum  WidgetVerticalAlignment { WVA_Top , WVA_Middle , WVA_Bottom }
 
enum  WidgetDockPoint {
  WDP_TopLeft , WDP_TopMiddle , WDP_TopRight , WDP_MiddleRight ,
  WDP_BottomRight , WDP_BottomMiddle , WDP_BottomLeft , WDP_MiddleLeft ,
  WDP_Centre
}
 
enum  WidgetCallbackTypes {
  WC_OnMouseEnter , WC_OnMouseLeave , WC_OnMouseMove , WC_OnMouseDown ,
  WC_OnMouseUp , WC_OnGainFocus , WC_OnLeaveFocus , WC_NUM
}
 
enum  WidgetPropertyBindingType {
  WBT_Int , WBT_Float , WBT_String , WBT_Bool ,
  WBT_WidgetTree
}
 

Functions

struct WidgetDimGetWidgetWidthDim (struct UIWidget *pWidget)
 
struct WidgetDimGetWidgetHeightDim (struct UIWidget *pWidget)
 
void UI_Init ()
 
void UI_DestroyWidget (HWidget widget)
 
HWidget UI_GetScratchWiget ()
 
HWidget UI_NewBlankWidget ()
 
size_t UI_CountWidgetChildrenPtr (struct UIWidget *pWidget)
 
size_t UI_CountWidgetChildren (HWidget pWidget)
 
struct UIWidgetUI_GetWidget (HWidget hWidget)
 
struct UIWidgetUI_FirstChild (HWidget hWidget)
 
void UI_AddChild (HWidget hParent, HWidget hChild)
 
float UI_ResolveWidthDimPxls (struct UIWidget *pWidget, const struct WidgetDim *dim)
 
float UI_ResolveHeightDimPxls (struct UIWidget *pWidget, const struct WidgetDim *dim)
 
void UI_WidgetCommonInit (struct DataNode *pInNode, struct UIWidget *outWidget)
 Init common attributes that all widgets can have.
 
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 print hook correctly. Shit. DON'T USE
 
void * UI_Helper_OnOutputVerts (struct UIWidget *pWidget, VECTOR(WidgetVertex) pOutVerts)
 
void UI_Helper_OnLayoutChildren (struct UIWidget *pWidget, struct UIWidget *pParent)
 
void UI_GetWidgetSize (HWidget hWidget, float *pOutW, float *pOutH)
 
void UI_GetWidgetTopLeft (HWidget hWidget, float *pOutLeft, float *pOutTop)
 get top left BEFORE padding is applied (the raw top left)
 
void UI_GetWidgetPadding (HWidget hWidget, float *pOutPaddingTop, float *pOutPaddingBottom, float *pOutPaddingLeft, float *pOutPaddingRight)
 
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 function. If both the C function is called first
 
void UI_GetHitBox (GeomRect outRect, HWidget hWidget)
 Get the AABB of the widget, excluding padding.
 
bool UI_IsAttributeStringABindingExpression (const char *attributeValue)
 
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 function.
 
void UI_AddIntPropertyBinding (struct UIWidget *pWidget, char *inBoundPropertyName, char *inBindingExpression, int *pOutData, int viewmodelTableIndex)
 
void UI_AddFloatPropertyBinding (struct UIWidget *pWidget, char *inBoundPropertyName, char *inBindingExpression, float *pOutData, int viewmodelTableIndex)
 
char * UI_MakeBindingGetterFunctionName (const char *inBindingName)
 USER MUST FREE RETURNED PTR append Get_ to the start of the string.
 
char * UI_MakeBindingSetterFunctionName (const char *inBindingName)
 
struct WidgetPropertyBindingUI_FindBinding (struct UIWidget *pWidget, const char *bindingName)
 
void UI_DefaultOnChildrenChanged (struct UIWidget *outWidget)
 

Macro Definition Documentation

◆ LUA_CALLBACK_MAX_NAME_LEN

#define LUA_CALLBACK_MAX_NAME_LEN   64

◆ MAX_NUM_BINDINGS

#define MAX_NUM_BINDINGS   16

◆ MAX_PROPERTY_NAME_LEN

#define MAX_PROPERTY_NAME_LEN   32

◆ NUM_BUTTONS

#define NUM_BUTTONS   3

Typedef Documentation

◆ FocusedWidgetRecieveKeystrokeFn

typedef void(* FocusedWidgetRecieveKeystrokeFn) (struct UIWidget *pWidget, int keystroke)

◆ GetUIWidgetDimensionFn

typedef float(* GetUIWidgetDimensionFn) (struct UIWidget *pWidget, struct UIWidget *pParent)

◆ LayoutChildrenFn

typedef void(* LayoutChildrenFn) (struct UIWidget *pWidget, struct UIWidget *pParent)

◆ OnBoundPropertyChangedFn

typedef void(* OnBoundPropertyChangedFn) (struct UIWidget *pThisWidget, struct WidgetPropertyBinding *pBinding)

◆ OnChildrenChangedFn

typedef void(* OnChildrenChangedFn) (struct UIWidget *pWidget)

◆ OnDestroyWidgetFn

typedef void(* OnDestroyWidgetFn) (struct UIWidget *pWidget)

◆ OnWidgetInitFn

typedef void(* OnWidgetInitFn) (struct UIWidget *pWidget)

◆ OutputWidgetVerticesFn

typedef void *(* OutputWidgetVerticesFn) (struct UIWidget *pThisWidget, VECTOR(WidgetVertex) pOutVerts)

◆ PrintfFn

typedef int(* PrintfFn) (const char *restrict fmt,...)

◆ WidgetDimGetterFn

typedef struct WidgetDim *(* WidgetDimGetterFn) (struct UIWidget *pWidget)

◆ WidgetDockPoint

◆ WidgetFocusChangeCallbackFn

typedef void(* WidgetFocusChangeCallbackFn) (struct UIWidget *pWidget)

◆ WidgetHorizontalAlignment

◆ WidgetMouseBtnCallbackFn

typedef void(* WidgetMouseBtnCallbackFn) (struct UIWidget *pWidget, float x, float y, int btn)

◆ WidgetMousePosCallbackFn

typedef void(* WidgetMousePosCallbackFn) (struct UIWidget *pWidget, float x, float y)

◆ WidgetQuad

◆ WidgetVertex

◆ WidgetVerticalAlignment

Enumeration Type Documentation

◆ WidgetCallbackTypes

Enumerator
WC_OnMouseEnter 
WC_OnMouseLeave 
WC_OnMouseMove 
WC_OnMouseDown 
WC_OnMouseUp 
WC_OnGainFocus 
WC_OnLeaveFocus 
WC_NUM 

◆ WidgetDimType

some are relative to their parent. In which case these should be relative to THEIR parent, fixed, or the top level window.

Enumerator
WD_Auto 

take as much space as it naturally takes

WD_Stretch 

stretch to fill all available space

WD_Pixels 

a literal value

WD_StretchFraction 

a fraction that's relative with other children. meaning this: width: 1* ---—| width: 2* --------—| | a | b | ui element a is twice the width of ui element b, and together they take up the entirety of their parents width

WD_Percentage 

a percentage of parents dimension but as a decimal between 0 and 1

◆ WidgetDockPoint

Enumerator
WDP_TopLeft 
WDP_TopMiddle 
WDP_TopRight 
WDP_MiddleRight 
WDP_BottomRight 
WDP_BottomMiddle 
WDP_BottomLeft 
WDP_MiddleLeft 
WDP_Centre 

◆ WidgetHorizontalAlignment

Enumerator
WHA_Left 
WHA_Middle 
WHA_Right 

◆ WidgetPropertyBindingType

Enumerator
WBT_Int 
WBT_Float 
WBT_String 
WBT_Bool 
WBT_WidgetTree 

◆ WidgetVerticalAlignment

Enumerator
WVA_Top 
WVA_Middle 
WVA_Bottom 

Function Documentation

◆ GetWidgetHeightDim()

struct WidgetDim * GetWidgetHeightDim ( struct UIWidget pWidget)

◆ GetWidgetWidthDim()

struct WidgetDim * GetWidgetWidthDim ( struct UIWidget pWidget)

◆ UI_AddChild()

void UI_AddChild ( HWidget  hParent,
HWidget  hChild 
)

◆ UI_AddFloatPropertyBinding()

void UI_AddFloatPropertyBinding ( struct UIWidget pWidget,
char *  inBoundPropertyName,
char *  inBindingExpression,
float *  pOutData,
int  viewmodelTableIndex 
)

◆ UI_AddIntPropertyBinding()

void UI_AddIntPropertyBinding ( struct UIWidget pWidget,
char *  inBoundPropertyName,
char *  inBindingExpression,
int *  pOutData,
int  viewmodelTableIndex 
)

◆ UI_AddStringPropertyBinding()

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 function.

Parameters
pWidgettheWidget to add the property binding. When the value changes the property of the widget will change when OnPropertyChanged is called. 2 way bindings will also be introduced for sliders, text entry fields, ect
inBoundPropertyNamebound property name - as it appears in the viewmodel lua table
inBindingExpressionthe incoming binding expression, i.e. {spritename}
pOutDatathe value returned from calling the lua string getter - allocates a string setting the pointer. user must deallocate
viewmodelTableIndexthe index in the lua registry that contains the lua table containing the function to call

◆ UI_CountWidgetChildren()

size_t UI_CountWidgetChildren ( HWidget  pWidget)

◆ UI_CountWidgetChildrenPtr()

size_t UI_CountWidgetChildrenPtr ( struct UIWidget pWidget)

◆ UI_DebugPrintCommonWidgetInfo()

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 print hook correctly. Shit. DON'T USE

Parameters
inWidget
pPrintfFn

◆ UI_DefaultOnChildrenChanged()

void UI_DefaultOnChildrenChanged ( struct UIWidget outWidget)

◆ UI_DestroyWidget()

void UI_DestroyWidget ( HWidget  widget)

◆ UI_FindBinding()

struct WidgetPropertyBinding * UI_FindBinding ( struct UIWidget pWidget,
const char *  bindingName 
)

◆ UI_FirstChild()

struct UIWidget * UI_FirstChild ( HWidget  hWidget)

◆ UI_GetHitBox()

void UI_GetHitBox ( GeomRect  outRect,
HWidget  hWidget 
)

Get the AABB of the widget, excluding padding.

Parameters
outRect
hWidget

◆ UI_GetScratchWiget()

HWidget UI_GetScratchWiget ( )

◆ UI_GetWidget()

struct UIWidget * UI_GetWidget ( HWidget  hWidget)

◆ UI_GetWidgetPadding()

void UI_GetWidgetPadding ( HWidget  hWidget,
float *  pOutPaddingTop,
float *  pOutPaddingBottom,
float *  pOutPaddingLeft,
float *  pOutPaddingRight 
)

◆ UI_GetWidgetSize()

void UI_GetWidgetSize ( HWidget  hWidget,
float *  pOutW,
float *  pOutH 
)

◆ UI_GetWidgetTopLeft()

void UI_GetWidgetTopLeft ( HWidget  hWidget,
float *  pOutLeft,
float *  pOutTop 
)

get top left BEFORE padding is applied (the raw top left)

Parameters
hWidget
pOutLeft
pOutTop

◆ UI_Helper_OnLayoutChildren()

void UI_Helper_OnLayoutChildren ( struct UIWidget pWidget,
struct UIWidget pParent 
)

◆ UI_Helper_OnOutputVerts()

void * UI_Helper_OnOutputVerts ( struct UIWidget pWidget,
VECTOR(WidgetVertex pOutVerts 
)

◆ UI_Init()

void UI_Init ( )

◆ UI_IsAttributeStringABindingExpression()

bool UI_IsAttributeStringABindingExpression ( const char *  attributeValue)
Parameters
attributeValue
Returns
is the value of an xml attribute property an absolute value (return false) or is it deferrred to a getter on the lua viewmodel (return true). Special syntax for this is to surround the name of a view model property with "{" and "}"

◆ UI_MakeBindingGetterFunctionName()

char * UI_MakeBindingGetterFunctionName ( const char *  inBindingName)

USER MUST FREE RETURNED PTR append Get_ to the start of the string.

Parameters
inBindingName
Returns

◆ UI_MakeBindingSetterFunctionName()

char * UI_MakeBindingSetterFunctionName ( const char *  inBindingName)

◆ UI_NewBlankWidget()

HWidget UI_NewBlankWidget ( )

◆ UI_ResolveHeightDimPxls()

float UI_ResolveHeightDimPxls ( struct UIWidget pWidget,
const struct WidgetDim dim 
)

◆ UI_ResolveWidthDimPxls()

float UI_ResolveWidthDimPxls ( struct UIWidget pWidget,
const struct WidgetDim dim 
)

◆ UI_SendWidgetMouseEvent()

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 function. If both the C function is called first

Parameters
pWidget
<br>
pMouseInfodata about the event

◆ UI_WidgetCommonInit()

void UI_WidgetCommonInit ( struct DataNode pInNode,
struct UIWidget outWidget 
)

Init common attributes that all widgets can have.

  • "the base class constructor"
    Parameters
    pInNode
    outWidget