2023-06-17 17:00:55 +00:00
|
|
|
/* date = April 29th 2023 8:22 pm */
|
|
|
|
|
|
|
|
#ifndef VN_UI_H
|
|
|
|
#define VN_UI_H
|
|
|
|
|
2023-06-27 14:14:28 +00:00
|
|
|
//- sixten: Keying
|
2023-06-17 17:00:55 +00:00
|
|
|
struct ui_key
|
|
|
|
{
|
|
|
|
u64 Value;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline b32 AreEqual(ui_key A, ui_key B)
|
|
|
|
{
|
|
|
|
b32 Result = (A.Value == B.Value);
|
|
|
|
return(Result);
|
|
|
|
}
|
|
|
|
|
2023-06-27 14:14:28 +00:00
|
|
|
//- sixten: Semantic sizing
|
2023-09-13 04:42:11 +00:00
|
|
|
enum ui_size_kind
|
2023-06-17 17:00:55 +00:00
|
|
|
{
|
2023-09-13 04:42:11 +00:00
|
|
|
UI_SizeKind_Pixels,
|
|
|
|
UI_SizeKind_TextContent,
|
|
|
|
UI_SizeKind_PercentOfParent,
|
|
|
|
UI_SizeKind_ChildrenSum,
|
2023-06-17 17:00:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ui_size
|
|
|
|
{
|
2023-09-13 04:42:11 +00:00
|
|
|
ui_size_kind Kind;
|
2023-06-17 17:00:55 +00:00
|
|
|
r32 Value;
|
|
|
|
r32 Strictness;
|
|
|
|
};
|
|
|
|
|
2023-09-13 04:42:11 +00:00
|
|
|
static ui_size UI_MakeSize(ui_size_kind Kind, r32 Value, r32 Strictness);
|
|
|
|
|
|
|
|
#define UI_Pixels(Value, Strictness) UI_MakeSize(UI_SizeKind_Pixels, Value, Strictness)
|
|
|
|
#define UI_Em(Value, Strictness) UI_MakeSize(UI_SizeKind_Pixels, (Value)*UI_TopFontSize(), Strictness)
|
|
|
|
#define UI_TextContent(Value, Strictness) UI_MakeSize(UI_SizeKind_TextContent, Value, Strictness)
|
|
|
|
#define UI_Percent(Value, Strictness) UI_MakeSize(UI_SizeKind_PercentOfParent, Value, Strictness)
|
|
|
|
#define UI_ChildrenSum(Value, Strictness) UI_MakeSize(UI_SizeKind_ChildrenSum, Value, Strictness)
|
2023-06-17 17:00:55 +00:00
|
|
|
|
2023-06-27 14:14:28 +00:00
|
|
|
//- sixten: UI core
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
UI_BoxFlag_Clickable = (1 << 0),
|
|
|
|
UI_BoxFlag_DrawText = (1 << 1),
|
|
|
|
UI_BoxFlag_DrawBorder = (1 << 2),
|
|
|
|
UI_BoxFlag_DrawBackground = (1 << 3),
|
|
|
|
UI_BoxFlag_DrawDropShadow = (1 << 4),
|
|
|
|
UI_BoxFlag_Clip = (1 << 5),
|
|
|
|
UI_BoxFlag_HotAnimation = (1 << 6),
|
|
|
|
UI_BoxFlag_ActiveAnimation = (1 << 7),
|
|
|
|
UI_BoxFlag_OverflowX = (1 << 8),
|
|
|
|
UI_BoxFlag_OverflowY = (1 << 9),
|
|
|
|
UI_BoxFlag_FloatingX = (1 << 10),
|
|
|
|
UI_BoxFlag_FloatingY = (1 << 11),
|
2023-07-19 15:09:41 +00:00
|
|
|
UI_BoxFlag_Scrollable = (1 << 12),
|
2023-07-24 13:50:57 +00:00
|
|
|
UI_BoxFlag_AnimatePosition = (1 << 13),
|
2023-06-27 14:14:28 +00:00
|
|
|
};
|
|
|
|
typedef u32 ui_box_flags;
|
|
|
|
|
2023-07-19 15:09:41 +00:00
|
|
|
#define UI_CUSTOM_DRAW_CALLBACK(name) void name(render_group *Group, glyph_atlas *Atlas, struct ui_box *Box, void *Data)
|
|
|
|
typedef UI_CUSTOM_DRAW_CALLBACK(ui_custom_draw_callback);
|
2023-06-17 17:00:55 +00:00
|
|
|
|
|
|
|
struct ui_box
|
|
|
|
{
|
2023-07-24 13:50:57 +00:00
|
|
|
// sixten: building
|
2023-06-17 17:00:55 +00:00
|
|
|
ui_box *First;
|
|
|
|
ui_box *Last;
|
|
|
|
ui_box *Next;
|
|
|
|
ui_box *Prev;
|
|
|
|
ui_box *Parent;
|
|
|
|
|
2023-07-24 13:50:57 +00:00
|
|
|
// sixten: hashing
|
2023-06-17 17:00:55 +00:00
|
|
|
ui_box *HashNext;
|
|
|
|
ui_box *HashPrev;
|
|
|
|
ui_key Key;
|
|
|
|
ui_key Seed;
|
|
|
|
u64 LastFrameTouched;
|
|
|
|
|
2023-07-24 13:50:57 +00:00
|
|
|
// sixten: per-frame data
|
2023-06-17 17:00:55 +00:00
|
|
|
ui_box_flags Flags;
|
|
|
|
string String;
|
|
|
|
ui_size SemanticSize[Axis2_Count];
|
|
|
|
v2 FixedP;
|
|
|
|
v4 TextColor;
|
|
|
|
v4 BackgroundColor;
|
|
|
|
v4 BorderColor;
|
|
|
|
r32 BorderThickness;
|
|
|
|
axis2 LayoutAxis;
|
|
|
|
r32 CornerRadius;
|
|
|
|
font_id Font;
|
|
|
|
r32 FontSize;
|
2023-06-27 14:14:28 +00:00
|
|
|
v2 Offset;
|
2023-08-22 03:19:51 +00:00
|
|
|
platform_cursor HoverCursor;
|
2023-07-19 15:09:41 +00:00
|
|
|
ui_custom_draw_callback *DrawCallback;
|
2023-06-17 17:00:55 +00:00
|
|
|
void *DrawCallbackData;
|
|
|
|
|
|
|
|
v2 ComputedRelativeP;
|
|
|
|
v2 ComputedDim;
|
|
|
|
|
2023-07-24 13:50:57 +00:00
|
|
|
// sixten: retained data
|
2023-06-17 17:00:55 +00:00
|
|
|
range2_r32 Rect;
|
|
|
|
r32 HotTransition;
|
|
|
|
r32 ActiveTransition;
|
2023-07-24 13:50:57 +00:00
|
|
|
v2 ApproachingRelativeP;
|
2023-06-17 17:00:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ui_box_bucket
|
|
|
|
{
|
|
|
|
ui_box *First;
|
|
|
|
ui_box *Last;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ui_signal
|
|
|
|
{
|
|
|
|
ui_box *Box;
|
|
|
|
v2 MouseP;
|
2023-12-07 15:50:57 +00:00
|
|
|
v2 dMouseP;
|
2023-06-17 17:00:55 +00:00
|
|
|
v2 DragDelta;
|
2023-07-19 15:09:41 +00:00
|
|
|
v2 Scroll;
|
2023-06-17 17:00:55 +00:00
|
|
|
b8 Clicked;
|
|
|
|
b8 Pressed;
|
|
|
|
b8 PressedRight;
|
|
|
|
b8 Released;
|
|
|
|
b8 Hovering;
|
|
|
|
b8 Dragging;
|
|
|
|
};
|
|
|
|
|
2023-07-19 15:09:41 +00:00
|
|
|
#include "generated/vn_ui.meta.h"
|
2023-06-17 17:00:55 +00:00
|
|
|
|
|
|
|
struct ui
|
|
|
|
{
|
2023-10-29 10:00:34 +00:00
|
|
|
arena *Arena;
|
|
|
|
arena *FrameArena;
|
2023-06-17 17:00:55 +00:00
|
|
|
ui_box *FirstFreeBox;
|
|
|
|
ui_box *LastFreeBox;
|
|
|
|
|
|
|
|
ui_box_bucket BoxBuckets[256];
|
|
|
|
|
|
|
|
ui_box *RootNode;
|
|
|
|
ui_box *TooltipNode;
|
|
|
|
ui_box *ContainerNode;
|
|
|
|
|
|
|
|
u64 CurrentFrame;
|
|
|
|
ui_key Hot;
|
|
|
|
ui_key Active;
|
|
|
|
|
2023-12-07 15:50:57 +00:00
|
|
|
r64 Time;
|
|
|
|
|
2023-06-17 17:00:55 +00:00
|
|
|
ui_key NextHot;
|
|
|
|
b32 NextHotSet;
|
|
|
|
|
|
|
|
u64 DragData[8];
|
|
|
|
v2 DragStartP;
|
|
|
|
|
|
|
|
ui_style_stacks Stacks;
|
2023-06-27 14:14:28 +00:00
|
|
|
|
|
|
|
platform_event_list *EventList;
|
2023-12-07 15:50:57 +00:00
|
|
|
v2 dMouseP;
|
2023-06-27 14:14:28 +00:00
|
|
|
v2 MouseP;
|
|
|
|
|
|
|
|
glyph_atlas *GlyphAtlas;
|
2023-06-17 17:00:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//- sixten: State management
|
|
|
|
inline void UI_SetState(ui *UI);
|
|
|
|
inline ui *UI_GetState(void);
|
2023-09-13 04:42:11 +00:00
|
|
|
inline ui_key UI_HotKey(void);
|
|
|
|
inline ui_key UI_ActiveKey(void);
|
2023-07-19 15:09:41 +00:00
|
|
|
inline platform_event_list *UI_EventList(void);
|
2023-10-29 10:00:34 +00:00
|
|
|
inline arena *UI_FrameArena(void);
|
2023-07-19 15:09:41 +00:00
|
|
|
inline v2 UI_MouseP(void);
|
|
|
|
inline glyph_atlas *UI_GlyphAtlas(void);
|
|
|
|
|
2023-06-17 17:00:55 +00:00
|
|
|
//- sixten: Drag helpers
|
|
|
|
inline void UI_SetDragStartP(v2 P);
|
|
|
|
inline void UI_UpdateDragStartP(void);
|
|
|
|
inline v2 UI_GetDragStartP(void);
|
|
|
|
inline void UI_StoreDragV2(v2 DragData);
|
|
|
|
inline v2 UI_GetDragV2(void);
|
|
|
|
inline void UI_StoreDragR32(r32 DragData);
|
|
|
|
inline r32 UI_GetDragR32(void);
|
|
|
|
inline void UI_StoreDragPayload(void *Data); // sixten(NOTE): Payload MUST be 64-bytes.
|
|
|
|
inline void UI_GetDragDataPayload(void *Data);
|
|
|
|
inline void UI_StoreDragPointer(void *Data);
|
|
|
|
inline void *UI_GetDragDataPointer(void);
|
|
|
|
|
2023-12-07 15:50:57 +00:00
|
|
|
//- sixten: Helpers
|
|
|
|
static r64 UI_Time(void);
|
|
|
|
|
2023-06-17 17:00:55 +00:00
|
|
|
//- sixten: Key functions
|
2023-06-27 14:14:28 +00:00
|
|
|
static ui_key UI_EmptyKey(void);
|
|
|
|
static ui_key UI_SeedKey(ui_key Key, ui_key Seed);
|
2023-09-13 04:42:11 +00:00
|
|
|
static ui_key UI_KeyFromString(string String);
|
|
|
|
static string UI_BoxStringFromKey(ui_key Key);
|
|
|
|
static ui_box *UI_BoxFromKey(ui *UI, ui_key Key);
|
2023-06-17 17:00:55 +00:00
|
|
|
|
|
|
|
//- sixten: Box creation
|
2023-06-27 14:14:28 +00:00
|
|
|
static ui_box *UI_MakeBox(ui_box_flags Flags, string String);
|
|
|
|
static ui_box *UI_MakeBoxF(ui_box_flags Flags, char *Format, ...);
|
2023-08-22 03:19:51 +00:00
|
|
|
static void UI_EquipBoxText(ui_box *Box, string String);
|
|
|
|
static void UI_EquipBoxCustomDrawCallback(ui_box *Box, ui_custom_draw_callback *DrawCallback, void *Data);
|
2023-06-27 14:14:28 +00:00
|
|
|
|
|
|
|
//- sixten: User interaction
|
|
|
|
static ui_signal UI_SignalFromBox(ui_box *Box);
|
2023-06-17 17:00:55 +00:00
|
|
|
|
|
|
|
//- sixten: Building and rendering
|
2023-07-19 15:09:41 +00:00
|
|
|
static void UI_Init(ui *UI);
|
2023-06-17 17:00:55 +00:00
|
|
|
static void UI_BeginBuild(ui *UI, v2 ScreenDim);
|
2023-06-27 14:14:28 +00:00
|
|
|
static void UI_EndBuild(void);
|
|
|
|
static void UI_RenderFrame(render_group *RenderGroup);
|
2023-12-07 15:50:57 +00:00
|
|
|
static void UI_NewFrame(ui *UI, platform_event_list *EventList, v2 MouseP, r32 dtForFrame, glyph_atlas *GlyphAtlas);
|
2023-06-17 17:00:55 +00:00
|
|
|
|
|
|
|
#endif //VN_UI_H
|