Fixed problem with bounds checking on parent widgets, when they weren't expanding to fit children until they themselves were committed

This commit is contained in:
PS 2020-11-15 20:03:35 -08:00
parent 0b6b3c6367
commit 8d923a5e3c
3 changed files with 20 additions and 49 deletions

View File

@ -247,7 +247,7 @@ TestRender(app_state* State, context* Context, render_command_buffer* RenderBuff
ui_PushLayout(&State->Interface, A); ui_PushLayout(&State->Interface, A);
{ {
#if 1 #if 0
ui_Label(&State->Interface, MakeString("Spacer")); ui_Label(&State->Interface, MakeString("Spacer"));
ui_Label(&State->Interface, MakeString("Spacer")); ui_Label(&State->Interface, MakeString("Spacer"));
ui_Label(&State->Interface, MakeString("Spacer")); ui_Label(&State->Interface, MakeString("Spacer"));
@ -270,7 +270,7 @@ TestRender(app_state* State, context* Context, render_command_buffer* RenderBuff
//ui_Button(&State->Interface, MakeString("B")); //ui_Button(&State->Interface, MakeString("B"));
//ui_Button(&State->Interface, MakeString("C")); //ui_Button(&State->Interface, MakeString("C"));
//TestSlider_Value = ui_RangeSlider(&State->Interface, MakeString("TestSlider"), TestSlider_Value, TestSlider_Min, TestSlider_Max); //TestSlider_Value = ui_RangeSlider(&State->Interface, MakeString("TestSlider"), TestSlider_Value, TestSlider_Min, TestSlider_Max);
#elif 0 #elif 1
ui_PushLayout(&State->Interface, MakeString("Outer")); ui_PushLayout(&State->Interface, MakeString("Outer"));
{ {
for (u32 i = 0; i < 3; i++) for (u32 i = 0; i < 3; i++)
@ -316,6 +316,13 @@ TestRender(app_state* State, context* Context, render_command_buffer* RenderBuff
} }
} }
ui_PopLayout(&State->Interface); ui_PopLayout(&State->Interface);
ui_PushOverlayLayout(&State->Interface, rect2{25, 25, 200, 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));
}
ui_PopLayout(&State->Interface);
#else #else
ui_BeginList(&State->Interface, MakeString("Test List"), 10); ui_BeginList(&State->Interface, MakeString("Test List"), 10);
{ {

View File

@ -66,50 +66,6 @@ HierarchyView_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* Ren
ui_EndRow(&State->Interface); ui_EndRow(&State->Interface);
} }
ui_EndList(&State->Interface); ui_EndList(&State->Interface);
// TODO(pjs): Come back to this after the layout stuff is handled.
// Ideally it handles the visuals of the hierarchy itself.
#if 0
gs_string TempString = PushString(State->Transient, 256);
u32 LineCount = (u32)(Rect2Height(PanelBounds) / Layout->RowHeight) + 1;
u32 AssembliesToDraw = Min(LineCount, State->Assemblies.Count);
rect2* LineBounds = PushArray(State->Transient, rect2, LineCount);
// Fill in alternating color rows for the backgrounds
for (u32 Line = 0; Line < LineCount; Line++)
{
v4 ListItemBGColor = ui_GetListItemBGColor(State->Interface.Style, Line);
ui_FillRect(&State->Interface, LineBounds[Line], ListItemBGColor);
}
for (u32 AssemblyIndex = 0; AssemblyIndex < AssembliesToDraw; AssemblyIndex++)
{
assembly Assembly = State->Assemblies.Values[AssemblyIndex];
PrintF(&TempString, "%S", Assembly.Name);
ui_StartRow(&State->Interface, 2);
{
ui_DrawString(&State->Interface, TempString);
if (ui_LayoutListButton(&State->Interface, MakeString("X"), AssemblyIndex))
{
UnloadAssembly(AssemblyIndex, State, Context);
}
}
ui_EndRow(&State->Interface);
}
if (AssembliesToDraw < LineCount)
{
// NOTE(Peter): Add assembly button
PrintF(&TempString, "+ Add Assembly");
if (ui_Button(&State->Interface, TempString))
{
panel* FileBrowser = PanelSystem_PushPanel(&State->PanelSystem, PanelType_FileView, State, Context);
Panel_PushModalOverride(Panel, FileBrowser, LoadAssemblyCallback);
}
}
#endif
ui_PopLayout(&State->Interface); ui_PopLayout(&State->Interface);
} }

View File

@ -534,11 +534,19 @@ ui_CommitBounds(ui_widget* Parent, rect2 Bounds)
case LayoutDirection_BottomUp: case LayoutDirection_BottomUp:
{ {
Parent->RowYAt = Bounds.Max.y; Parent->RowYAt = Bounds.Max.y;
if (ui_WidgetIsFlagSet(*Parent, UIWidgetFlag_ExpandsToFitChildren))
{
Parent->Bounds.Max.y = Parent->RowYAt;
}
}break; }break;
case LayoutDirection_TopDown: case LayoutDirection_TopDown:
{ {
Parent->RowYAt = Bounds.Min.y - Parent->RowHeight; Parent->RowYAt = Bounds.Min.y - Parent->RowHeight;
if (ui_WidgetIsFlagSet(*Parent, UIWidgetFlag_ExpandsToFitChildren))
{
Parent->Bounds.Min.y = Bounds.Min.y;
}
}break; }break;
} }
} }
@ -589,7 +597,7 @@ internal ui_widget*
ui_CreateLayoutWidget(ui_interface* Interface, rect2 Bounds, gs_string Name, ui_layout_direction FillDir = LayoutDirection_Inherit) ui_CreateLayoutWidget(ui_interface* Interface, rect2 Bounds, gs_string Name, ui_layout_direction FillDir = LayoutDirection_Inherit)
{ {
ui_widget* Result = ui_CreateWidget(Interface, Name); ui_widget* Result = ui_CreateWidget(Interface, Name);
ui_WidgetSetFlag(Result, UIWidgetFlag_DrawOutline); //ui_WidgetSetFlag(Result, UIWidgetFlag_DrawOutline);
Result->Bounds = Bounds; Result->Bounds = Bounds;
Result->Margin = Interface->Style.Margin; Result->Margin = Interface->Style.Margin;
@ -1021,8 +1029,8 @@ ui_EvaluateDropdown(ui_interface* Interface, ui_widget* Widget, ui_eval_result E
{ {
ui_widget ParentLayout = *Interface->ActiveLayout; ui_widget ParentLayout = *Interface->ActiveLayout;
r32 SpaceAbove = ParentLayout.Bounds.Max.y - Widget->Bounds.Max.y; r32 SpaceAbove = Interface->WindowBounds.Max.y - Widget->Bounds.Max.y;
r32 SpaceBelow = Widget->Bounds.Min.y - ParentLayout.Bounds.Min.y; r32 SpaceBelow = Widget->Bounds.Min.y - Interface->WindowBounds.Min.y;
ui_layout_direction Direction = LayoutDirection_TopDown; ui_layout_direction Direction = LayoutDirection_TopDown;
rect2 MenuBounds = {}; rect2 MenuBounds = {};