From 8d923a5e3c612800859d1e811874ecdc63fc79f1 Mon Sep 17 00:00:00 2001 From: PS Date: Sun, 15 Nov 2020 20:03:35 -0800 Subject: [PATCH] Fixed problem with bounds checking on parent widgets, when they weren't expanding to fit children until they themselves were committed --- src/app/editor/foldhaus_editor.cpp | 11 ++++- .../editor/panels/foldhaus_panel_hierarchy.h | 44 ------------------- src/app/interface.h | 14 ++++-- 3 files changed, 20 insertions(+), 49 deletions(-) diff --git a/src/app/editor/foldhaus_editor.cpp b/src/app/editor/foldhaus_editor.cpp index 067b4e6..9d3b1a6 100644 --- a/src/app/editor/foldhaus_editor.cpp +++ b/src/app/editor/foldhaus_editor.cpp @@ -247,7 +247,7 @@ TestRender(app_state* State, context* Context, render_command_buffer* RenderBuff 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")); @@ -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("C")); //TestSlider_Value = ui_RangeSlider(&State->Interface, MakeString("TestSlider"), TestSlider_Value, TestSlider_Min, TestSlider_Max); -#elif 0 +#elif 1 ui_PushLayout(&State->Interface, MakeString("Outer")); { 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_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 ui_BeginList(&State->Interface, MakeString("Test List"), 10); { diff --git a/src/app/editor/panels/foldhaus_panel_hierarchy.h b/src/app/editor/panels/foldhaus_panel_hierarchy.h index 4a2277a..d2f9804 100644 --- a/src/app/editor/panels/foldhaus_panel_hierarchy.h +++ b/src/app/editor/panels/foldhaus_panel_hierarchy.h @@ -66,50 +66,6 @@ HierarchyView_Render(panel* Panel, rect2 PanelBounds, render_command_buffer* Ren ui_EndRow(&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); } diff --git a/src/app/interface.h b/src/app/interface.h index 3cd2772..6f90a18 100644 --- a/src/app/interface.h +++ b/src/app/interface.h @@ -534,11 +534,19 @@ ui_CommitBounds(ui_widget* Parent, rect2 Bounds) case LayoutDirection_BottomUp: { Parent->RowYAt = Bounds.Max.y; + if (ui_WidgetIsFlagSet(*Parent, UIWidgetFlag_ExpandsToFitChildren)) + { + Parent->Bounds.Max.y = Parent->RowYAt; + } }break; case LayoutDirection_TopDown: { Parent->RowYAt = Bounds.Min.y - Parent->RowHeight; + if (ui_WidgetIsFlagSet(*Parent, UIWidgetFlag_ExpandsToFitChildren)) + { + Parent->Bounds.Min.y = Bounds.Min.y; + } }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_widget* Result = ui_CreateWidget(Interface, Name); - ui_WidgetSetFlag(Result, UIWidgetFlag_DrawOutline); + //ui_WidgetSetFlag(Result, UIWidgetFlag_DrawOutline); Result->Bounds = Bounds; 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; - r32 SpaceAbove = ParentLayout.Bounds.Max.y - Widget->Bounds.Max.y; - r32 SpaceBelow = Widget->Bounds.Min.y - ParentLayout.Bounds.Min.y; + r32 SpaceAbove = Interface->WindowBounds.Max.y - Widget->Bounds.Max.y; + r32 SpaceBelow = Widget->Bounds.Min.y - Interface->WindowBounds.Min.y; ui_layout_direction Direction = LayoutDirection_TopDown; rect2 MenuBounds = {};