Layout push/pop pairing is now checked for and asserted on

This commit is contained in:
PS 2021-01-16 18:55:31 -08:00
parent 35a3793015
commit 3c1110adfd
8 changed files with 53 additions and 17 deletions

View File

@ -108,6 +108,9 @@ Editor_Update(app_state* State, context* Context, input_queue InputQueue)
State->Interface.HotWidget = {};
}
Assert(State->Interface.PerFrameMemory &&
(u64)State->Interface.PerFrameMemory != 0x5);
PanelSystem_UpdateLayout(&State->PanelSystem, State->WindowBounds);
Editor_HandleInput(State, State->WindowBounds, InputQueue, Context->Mouse, *Context);
}
@ -334,7 +337,7 @@ Editor_Render(app_state* State, context* Context, render_command_buffer* RenderB
}
}
ui_PopLayout(&State->Interface);
ui_PopLayout(&State->Interface, MakeString("Editor Layout"));
#endif
// Draw the Interface

View File

@ -600,7 +600,7 @@ DrawAnimationPatternList(rect2 PanelBounds, ui_interface* Interface, u32 Selecte
AddAnimationBlockAtCurrentTime(PatternHandle, SelectedAnimationLayerHandle, AnimationSystem);
}
}
ui_PopLayout(Interface);
ui_PopLayout(Interface, MakeString("AnimClips Layout"));
}
internal void
@ -630,7 +630,7 @@ PlayBar_Render(animation_timeline_state* TimelineState, rect2 Bounds, panel* Pan
}
}
ui_EndRow(&State->Interface);
ui_PopLayout(&State->Interface);
ui_PopLayout(&State->Interface, MakeString("PlayBar Layout"));
}
internal void
@ -881,7 +881,7 @@ AnimInfoView_Render(animation_timeline_state* TimelineState, rect2 Bounds, panel
ui_EndLabeledDropdown(Interface);
}
ui_PopLayout(Interface);
ui_PopLayout(Interface, MakeString("AnimInfo Layout"));
}
internal void

View File

@ -43,6 +43,8 @@ AssemblyDebug_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* Ren
ui_interface* Interface = &State->Interface;
ui_PushLayout(Interface, PanelBounds, LayoutDirection_TopDown, MakeString("Assembly Debug Layout"));
InterfaceAssert(Interface->PerFrameMemory);
gs_string OverrideStr = MakeString(OverrideTypeStrings[State->AssemblyDebugState.Override]);
if (ui_BeginLabeledDropdown(Interface, MakeString("Override"), OverrideStr))
{
@ -54,6 +56,8 @@ AssemblyDebug_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* Ren
}
}
}
ui_EndLabeledDropdown(Interface);
InterfaceAssert(Interface->PerFrameMemory);
if (State->AssemblyDebugState.Override == ADS_Override_TagWhite ||
State->AssemblyDebugState.Override == ADS_Override_TagStripWhite)
@ -63,7 +67,6 @@ AssemblyDebug_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* Ren
if (State->AssemblyDebugState.Override == ADS_Override_TagStripWhite)
{
ui_EndLabeledDropdown(Interface);
State->AssemblyDebugState.TargetAssembly = ui_LabeledTextEntryU64(Interface, MakeString("Assembly"), State->AssemblyDebugState.TargetAssembly);
State->AssemblyDebugState.TargetStrip = ui_LabeledTextEntryU64(Interface, MakeString("Strip"), State->AssemblyDebugState.TargetStrip);
@ -80,11 +83,18 @@ AssemblyDebug_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* Ren
}
else
{
ui_EndLabeledDropdown(Interface);
InterfaceAssert(Interface->PerFrameMemory);
State->AssemblyDebugState.TargetAssembly = ui_LabeledTextEntryU64(Interface, MakeString("Assembly"), State->AssemblyDebugState.TargetAssembly);
InterfaceAssert(Interface->PerFrameMemory);
State->AssemblyDebugState.TargetStrip = ui_LabeledTextEntryU64(Interface, MakeString("Strip"), State->AssemblyDebugState.TargetStrip);
InterfaceAssert(Interface->PerFrameMemory);
}
ui_PopLayout(Interface, MakeString("Assembly Debug Layout"));
}
#define FOLDHAUS_PANEL_ASSEMBLY_DEBUG_H

View File

@ -121,7 +121,7 @@ FileView_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* RenderBu
}
}
ui_PopLayout(&State->Interface);
ui_PopLayout(&State->Interface, MakeString("FileView Layout"));
}

View File

@ -66,7 +66,7 @@ HierarchyView_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* Ren
ui_EndRow(&State->Interface);
}
ui_EndList(&State->Interface);
ui_PopLayout(&State->Interface);
ui_PopLayout(&State->Interface, MakeString("Hierarchy Layout"));
}

View File

@ -254,7 +254,7 @@ ProfilerView_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* Rend
RenderProfiler_ListVisualization(&State->Interface, Layout, VisibleFrame, Memory);
}
ui_PopLayout(&State->Interface);
ui_PopLayout(&State->Interface, MakeString("Profiler Layout"));
}

View File

@ -5,6 +5,8 @@
//
#ifndef INTERFACE_H
#define InterfaceAssert(IMemPtr) Assert(IMemPtr && (u64)IMemPtr != 0x5 && (u64)IMemPtr != 0xC)
enum gs_string_alignment
{
Align_Left,
@ -342,6 +344,10 @@ struct ui_widget_retained_state
v2 ChildrenDrawOffset;
gs_string EditString;
// For dropdowns and rows to be able to error check not closing
// a layout you open
u32 MaxChildren;
};
struct ui_interface
@ -392,6 +398,7 @@ ui_InterfaceReset(ui_interface* Interface)
Interface->DrawOrderHead = 0;
Interface->DrawOrderRoot = 0;
ClearArena(Interface->PerFrameMemory);
InterfaceAssert(Interface->PerFrameMemory);
for (u32 i = 0; i < Interface->RetainedStateCount; i++)
{
@ -521,6 +528,7 @@ ui_GetOrCreateRetainedState(ui_interface* Interface, ui_widget* Widget)
internal ui_widget*
ui_CreateWidget(ui_interface* Interface, gs_string String)
{
InterfaceAssert(Interface->PerFrameMemory);
Assert(Interface->WidgetsCount < Interface->WidgetsCountMax);
u64 Index = Interface->WidgetsCount++;
ui_widget* Result = Interface->Widgets + Index;
@ -546,6 +554,7 @@ ui_CreateWidget(ui_interface* Interface, gs_string String)
Result->Id.ZIndex = ZIndex;
Result->String = PushStringCopy(Interface->PerFrameMemory, String.ConstString);
InterfaceAssert(Interface->PerFrameMemory);
Result->Alignment = Align_Left;
Result->Next = 0;
Result->ChildrenRoot = 0;
@ -656,6 +665,7 @@ internal void
ui_WidgetCreateColumns(ui_widget* Widget, u32 ColumnsCount, ui_interface* Interface)
{
Widget->Columns = PushArray(Interface->PerFrameMemory, ui_column, ColumnsCount);
InterfaceAssert(Interface->PerFrameMemory);
Widget->ColumnsCount = ColumnsCount;
Widget->ColumnsFilled = 0;
}
@ -799,11 +809,17 @@ ui_ExpandToFitChildren(ui_widget* Parent)
}
static void
ui_PopLayout(ui_interface* Interface)
ui_PopLayout(ui_interface* Interface, gs_string LayoutName)
{
Assert(Interface->ActiveLayout != 0);
ui_widget* Layout = Interface->ActiveLayout;
// NOTE(pjs): If this isn't true then a layout was opened without being closed
// Go check for ui_PushLayout, ui_BeginDropdown, ui_BeginRow, etc that don't have
// a corresponding ui_Pop/ui_End*
Assert(StringsEqual(Layout->String, LayoutName));
ui_ExpandToFitChildren(Layout);
Interface->ActiveLayout = Interface->ActiveLayout->Parent;
@ -916,7 +932,7 @@ ui_BeginRow(ui_interface* Interface, u32 ColumnsMax, ui_column_spec* ColumnRules
static void
ui_EndRow(ui_interface* Interface)
{
ui_PopLayout(Interface);
ui_PopLayout(Interface, MakeString("Row"));
}
static rect2
@ -1297,7 +1313,7 @@ ui_EvaluateDropdown(ui_interface* Interface, ui_widget* Widget, ui_eval_result E
};
}
ui_widget* Layout = ui_PushOverlayLayout(Interface, MenuBounds, Direction, MakeString("WidgetLayout"));
ui_widget* Layout = ui_PushOverlayLayout(Interface, MenuBounds, Direction, MakeString("DropdownLayout"));
Layout->Margin.y = 0;
Layout->WidgetReference = Widget->Id;
ui_WidgetClearFlag(Layout, UIWidgetFlag_DrawOutline);
@ -1341,7 +1357,7 @@ ui_EndDropdown(ui_interface* Interface)
{
if (State->Value)
{
ui_PopLayout(Interface);
ui_PopLayout(Interface, MakeString("DropdownLayout"));
}
}
}
@ -1378,6 +1394,7 @@ ui_CreateRangeSliderWidget(ui_interface* Interface, gs_string Text, r32 Value)
ui_WidgetSetFlag(Widget, UIWidgetFlag_DrawHorizontalFill);
ui_WidgetSetFlag(Widget, UIWidgetFlag_DrawOutline);
Widget->String = PushStringF(Interface->PerFrameMemory, 128, "%f", Value);
InterfaceAssert(Interface->PerFrameMemory);
return Widget;
}
@ -1492,8 +1509,7 @@ internal void
ui_EndList(ui_interface* Interface)
{
// Pop the Viewport Layout
ui_PopLayout(Interface);
// TODO(pjs): Ensure that the active layout is the row layout we started in begin list
ui_PopLayout(Interface, MakeString("Contents"));
// Pop the actual list layout
ui_EndRow(Interface);
}
@ -1502,14 +1518,14 @@ internal void
ui_BeginMousePopup(ui_interface* Interface, rect2 Bounds, ui_layout_direction FillDir, gs_string Text)
{
rect2 FollowMouseBounds = Rect2Translate(Bounds, Interface->Mouse.Pos);
ui_widget* Layout = ui_PushOverlayLayout(Interface, FollowMouseBounds, FillDir, Text);
ui_widget* Layout = ui_PushOverlayLayout(Interface, FollowMouseBounds, FillDir, MakeString("MousePopup"));
ui_WidgetSetFlag(Layout, UIWidgetFlag_DrawBackground);
}
internal void
ui_EndMousePopup(ui_interface* Interface)
{
ui_PopLayout(Interface);
ui_PopLayout(Interface, MakeString("MousePopup"));
}
//
@ -1577,6 +1593,8 @@ ui_InterfaceCreate(context Context, interface_config Style, gs_memory_arena* Per
Result.Widgets = PushArray(Permanent, ui_widget, Result.WidgetsCountMax);
Result.PerFrameMemory = PushStruct(Permanent, gs_memory_arena);
*Result.PerFrameMemory = CreateMemoryArena(Context.ThreadContext.Allocator);
InterfaceAssert(Result.PerFrameMemory);
Result.Permanent = Permanent;
return Result;

View File

@ -20,6 +20,7 @@ InterfaceTest_Render(app_state* State, context* Context, render_command_buffer*
gs_string A = MakeString("TestRender Layout");
#if 0
ui_PushLayout(&State->Interface, A);
{
#if 1
@ -87,14 +88,18 @@ InterfaceTest_Render(app_state* State, context* Context, render_command_buffer*
ui_PushOverlayLayout(&State->Interface, rect2{25, 25, 400, 200}, LayoutDirection_TopDown, MakeString("t"));
{
ui_Label(&State->Interface, PushStringF(State->Interface.PerFrameMemory, 256, "Mouse Pos - %f %f", State->Interface.Mouse.Pos.x, State->Interface.Mouse.Pos.y));
Assert(State->Interface.PerFrameMemory->CursorList);
ui_Label(&State->Interface, PushStringF(State->Interface.PerFrameMemory, 256, "Hot - %lld | Active - %lld",
State->Interface.HotWidget.Id, State->Interface.ActiveWidget.Id));
Assert(State->Interface.PerFrameMemory->CursorList);
ui_Label(&State->Interface, PushStringF(State->Interface.PerFrameMemory, 256, "Last Active - %lld",
State->Interface.LastActiveWidget.Id));
Assert(State->Interface.PerFrameMemory->CursorList);
}
ui_PopLayout(&State->Interface);
}
ui_PopLayout(&State->Interface);
#endif
}