vn/code/vn_ui.md

47 lines
2.8 KiB
Markdown
Raw Permalink Normal View History

2023-07-19 15:09:41 +00:00
@table(Name, Type, BoxName)
UIStyleStacks:
{
2023-08-22 03:19:51 +00:00
{ Parent `ui_box *` `Parent` }
{ Width `ui_size` `SemanticSize[Axis2_X]` }
{ Height `ui_size` `SemanticSize[Axis2_Y]` }
{ FixedX `r32` `FixedP.E[Axis2_X]` }
{ FixedY `r32` `FixedP.E[Axis2_Y]` }
2024-01-20 11:18:57 +00:00
{ TextColor `v4_r32` `TextColor` }
{ BackgroundColor `v4_r32` `BackgroundColor` }
{ BorderColor `v4_r32` `BorderColor` }
2023-08-22 03:19:51 +00:00
{ BorderThickness `r32` `BorderThickness` }
{ LayoutAxis `axis2` `LayoutAxis` }
2024-01-20 11:18:57 +00:00
{ CornerRadii `v4_r32` `CornerRadii` }
2023-08-22 03:19:51 +00:00
{ Font `font_id` `Font` }
{ FontSize `r32` `FontSize` }
{ OffsetX `r32` `Offset.x` }
{ OffsetY `r32` `Offset.y` }
{ HoverCursor `platform_cursor` `HoverCursor` }
2023-07-19 15:09:41 +00:00
}
@table_gen
{
`struct ui_style_stacks`;
`{`;
@expand(UIStyleStacks s) `$(s.Type) $(s.Name)Stack[64]; s32 $(s.Name)StackUsed; b32 AutoPop$(s.Name);`;
`};`;
}
@c @table_gen
{
@expand(UIStyleStacks s) `inline void UI_Push$(s.Name)($(s.Type) Element) $(=>50) { ui *UI = UI_GetState(); Assert(UI->Stacks.$(s.Name)StackUsed $(=>125) + 1 < ArrayCount(UI->Stacks.$(s.Name)Stack)); $(=>180) UI->Stacks.$(s.Name)Stack[UI->Stacks.$(s.Name)StackUsed++] $(=>260) = Element; }`;
@expand(UIStyleStacks s) `inline void UI_Pop$(s.Name)(void) $(=>50) { ui *UI = UI_GetState(); Assert(UI->Stacks.$(s.Name)StackUsed $(=>125) > 0); $(=>180) --UI->Stacks.$(s.Name)StackUsed; $(=>271) }`;
@expand(UIStyleStacks s) `inline void UI_SetNext$(s.Name)($(s.Type) Element) { ui *UI = UI_GetState(); UI_Push$(s.Name)(Element); UI->Stacks.AutoPop$(s.Name) = true; }`;
@expand(UIStyleStacks s) `inline $(s.Type) UI_First$(s.Name)(void) { ui *UI = UI_GetState(); return(UI->Stacks.$(s.Name)Stack[0]); }`;
@expand(UIStyleStacks s) `inline $(s.Type) UI_Top$(s.Name)(void) { ui *UI = UI_GetState(); return(UI->Stacks.$(s.Name)Stack[UI->Stacks.$(s.Name)StackUsed - 1]); }`;
@expand(UIStyleStacks s) `#define UI_$(s.Name)(Element) DeferLoop(UI_Push$(s.Name)(Element), UI_Pop$(s.Name)())`
}
@c @table_gen
{
`static void UI_ApplyStyles(ui_box *Box)`;
`{`;
`ui *UI = UI_GetState();`;
@expand(UIStyleStacks s) `Assert(UI->Stacks.$(s.Name)StackUsed > 0); $(=>50) Box->$(s.BoxName) $(=>75) = UI->Stacks.$(s.Name)Stack[UI->Stacks.$(s.Name)StackUsed - 1]; $(=>160) if(UI->Stacks.AutoPop$(s.Name)) $(=>200) { UI_Pop$(s.Name)(); $(=>230) UI->Stacks.AutoPop$(s.Name) = false; $(=>260) }`
`}`;
}