Pulled more old ui code out and replaced it with the layout based ui
This commit is contained in:
parent
cb98100a94
commit
5922a4bf27
|
@ -291,6 +291,17 @@ ui_ReserveTextLineBounds(ui_interface Interface, string Text, ui_layout* Layout)
|
|||
return Bounds;
|
||||
}
|
||||
|
||||
static rect
|
||||
ui_ReserveElementBounds(ui_layout* Layout)
|
||||
{
|
||||
rect Bounds = {0};
|
||||
if (!ui_TryReserveElementBounds(Layout, &Bounds))
|
||||
{
|
||||
InvalidCodePath;
|
||||
}
|
||||
return Bounds;
|
||||
}
|
||||
|
||||
//
|
||||
// Drawing Functions
|
||||
//
|
||||
|
@ -335,6 +346,19 @@ ui_DrawString(ui_interface* Interface, string String, rect Bounds, v4 Color, str
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ui_LayoutDrawString(ui_interface* Interface, ui_layout* Layout, string String, v4 Color, string_alignment Alignment = Align_Left)
|
||||
{
|
||||
rect Bounds = {0};
|
||||
if (!ui_TryReserveElementBounds(Layout, &Bounds))
|
||||
{
|
||||
// TODO(NAME): Not invalid, just haven't implemented yet.
|
||||
// This is the case where Layout is in row mode without a fixed number of elements
|
||||
InvalidCodePath;
|
||||
}
|
||||
ui_DrawString(Interface, String, Bounds, Color, Alignment);
|
||||
}
|
||||
|
||||
static void
|
||||
ui_TextBox(ui_interface* Interface, rect Bounds, string Text, v4 BGColor, v4 TextColor)
|
||||
{
|
||||
|
@ -370,18 +394,30 @@ ui_Button(ui_interface* Interface, string Text, rect Bounds)
|
|||
}
|
||||
|
||||
static b32
|
||||
ui_LayoutButton(ui_interface* Interface, string Text, ui_layout* Layout)
|
||||
ui_LayoutButton(ui_interface* Interface, ui_layout* Layout, string Text, v4 BGColor, v4 HoverColor, v4 SelectColor)
|
||||
{
|
||||
rect ButtonBounds = {0};
|
||||
if (!ui_TryReserveElementBounds(Layout, &ButtonBounds))
|
||||
{
|
||||
ButtonBounds = ui_ReserveTextLineBounds(*Interface, Text, Layout);
|
||||
}
|
||||
return ui_Button(Interface, Text, ButtonBounds, BGColor, HoverColor, SelectColor);
|
||||
}
|
||||
|
||||
static b32
|
||||
ui_LayoutButton(ui_interface* Interface, ui_layout* Layout, string Text)
|
||||
{
|
||||
v4 BGColor = Interface->Style.ButtonColor_Inactive;
|
||||
v4 HoverColor = Interface->Style.ButtonColor_Active;
|
||||
v4 SelectedColor = Interface->Style.ButtonColor_Selected;
|
||||
return ui_Button(Interface, Text, ButtonBounds, BGColor, HoverColor, SelectedColor);
|
||||
return ui_LayoutButton(Interface, Layout, Text, BGColor, HoverColor, SelectedColor);
|
||||
}
|
||||
|
||||
inline v4
|
||||
ui_GetListItemBGColor(interface_config Style, u32 ElementIndex)
|
||||
{
|
||||
v4 Result = Style.ListBGColors[ElementIndex % LIST_BG_COLORS_COUNT];
|
||||
return Result;
|
||||
}
|
||||
|
||||
static b32
|
||||
|
@ -396,7 +432,7 @@ ui_LayoutListEntry(ui_interface* Interface, ui_layout* Layout, string Text, u32
|
|||
// Punting this till I have a use case
|
||||
InvalidCodePath;
|
||||
}
|
||||
v4 BGColor = Interface->Style.ListBGColors[Index % LIST_BG_COLORS_COUNT];
|
||||
v4 BGColor = ui_GetListItemBGColor(Interface->Style, Index);
|
||||
v4 HoverColor = Interface->Style.ListBGHover;
|
||||
v4 SelectedColor = Interface->Style.ListBGSelected;
|
||||
return ui_Button(Interface, Text, Bounds, BGColor, HoverColor, SelectedColor);
|
||||
|
@ -406,52 +442,6 @@ ui_LayoutListEntry(ui_interface* Interface, ui_layout* Layout, string Text, u32
|
|||
// OLD
|
||||
//
|
||||
|
||||
struct slider_result
|
||||
{
|
||||
r32 Percent;
|
||||
r32 Advance;
|
||||
};
|
||||
|
||||
internal slider_result
|
||||
EvaluateSlider (render_command_buffer* RenderBuffer, v2 Min, v2 Max, string Label, r32 Percent, interface_config Config, mouse_state Mouse)
|
||||
{
|
||||
slider_result Result = {};
|
||||
|
||||
v4 BGColor = Config.ButtonColor_Inactive;
|
||||
v4 FillColor = Config.ButtonColor_Selected;
|
||||
|
||||
r32 DisplayPercent = Percent;
|
||||
|
||||
if (PointIsInRange(Mouse.Pos, Min, Max))
|
||||
{
|
||||
BGColor = Config.ButtonColor_Active;
|
||||
}
|
||||
|
||||
if (MouseButtonTransitionedDown(Mouse.LeftButtonState))
|
||||
{
|
||||
if (PointIsInRange(Mouse.DownPos, Min, Max))
|
||||
{
|
||||
r32 TempFillPercent = (Mouse.Pos.y - Min.y) / (Max.y - Min.y);
|
||||
|
||||
DisplayPercent = GSClamp(0.0f, TempFillPercent, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
r32 FillHeight = ((Max.y - Min.y) - 4) * DisplayPercent;
|
||||
|
||||
PushRenderQuad2D(RenderBuffer, Min, Max, BGColor);
|
||||
PushRenderQuad2D(RenderBuffer, Min + v2{2, 2}, v2{Max.x - 2, Min.y + 2 + FillHeight}, FillColor);
|
||||
|
||||
// TODO(Peter): display the actual value of the slider
|
||||
|
||||
DrawString(RenderBuffer, Label, Config.Font, Min, Config.TextColor);
|
||||
|
||||
Result.Percent = DisplayPercent;
|
||||
Result.Advance = (Max.y - Min.y) + Config.Margin.y;
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
enum selection_state
|
||||
{
|
||||
Selection_None,
|
||||
|
|
|
@ -589,15 +589,15 @@ AnimationTimeline_Render(panel Panel, rect PanelBounds, render_command_buffer* R
|
|||
ui_layout TitleBarLayout = ui_CreateLayout(*Interface, TitleBarBounds);
|
||||
ui_StartRow(&TitleBarLayout, 3);
|
||||
{
|
||||
if (ui_LayoutButton(Interface, MakeStringLiteral("Pause"), &TitleBarLayout))
|
||||
if (ui_LayoutButton(Interface, &TitleBarLayout, MakeStringLiteral("Pause")))
|
||||
{
|
||||
State->AnimationSystem.TimelineShouldAdvance = true;
|
||||
}
|
||||
if (ui_LayoutButton(Interface, MakeStringLiteral("Play"), &TitleBarLayout))
|
||||
if (ui_LayoutButton(Interface, &TitleBarLayout, MakeStringLiteral("Play")))
|
||||
{
|
||||
State->AnimationSystem.TimelineShouldAdvance = false;
|
||||
}
|
||||
if (ui_LayoutButton(Interface, MakeStringLiteral("Stop"), &TitleBarLayout))
|
||||
if (ui_LayoutButton(Interface, &TitleBarLayout, MakeStringLiteral("Stop")))
|
||||
{
|
||||
State->AnimationSystem.TimelineShouldAdvance = false;
|
||||
State->AnimationSystem.CurrentFrame = 0;
|
||||
|
|
|
@ -29,71 +29,56 @@ GSMetaTag(panel_type_hierarchy);
|
|||
internal void
|
||||
HierarchyView_Render(panel Panel, rect PanelBounds, render_command_buffer* RenderBuffer, app_state* State, context Context, mouse_state Mouse)
|
||||
{
|
||||
r32 PanelWidth = PanelBounds.Max.x - PanelBounds.Min.x;
|
||||
r32 PanelHeight = PanelBounds.Max.y - PanelBounds.Min.y;
|
||||
ui_layout Layout = ui_CreateLayout(State->Interface_, PanelBounds);
|
||||
v4 ListItemHover = State->Interface_.Style.ListBGHover;
|
||||
v4 ListItemSelected = State->Interface_.Style.ListBGSelected;
|
||||
|
||||
v4 LineBGColors[] = {
|
||||
{ .16f, .16f, .16f, 1.f },
|
||||
{ .18f, .18f, .18f, 1.f },
|
||||
};
|
||||
|
||||
// TODO(Peter): use the new ui system
|
||||
interface_list List = {};
|
||||
List.LineBGColors = LineBGColors;
|
||||
List.LineBGColorsCount = sizeof(LineBGColors) / sizeof(LineBGColors[0]);
|
||||
List.LineBGHoverColor = v4{ .22f, .22f, .22f, 1.f };
|
||||
List.ListBounds = PanelBounds;
|
||||
List.ListElementDimensions = v2{
|
||||
Width(PanelBounds),
|
||||
(r32)(State->Interface.Font->PixelHeight + 8),
|
||||
};
|
||||
|
||||
v2 TextOffset = v2{10, 4};
|
||||
string TempString = MakeString(PushArray(&State->Transient, char, 256), 0, 256);
|
||||
|
||||
u32 LineCount = (u32)(PanelHeight / List.ListElementDimensions.y) + 1;
|
||||
for (u32 i = 0; i < LineCount; i++)
|
||||
u32 LineCount = (u32)(Height(PanelBounds) / Layout.RowHeight) + 1;
|
||||
u32 LinesDrawn = 0;
|
||||
u32 AssembliesToDraw = GSMin(LineCount, State->ActiveAssemblyIndecies.Used);
|
||||
for (; LinesDrawn < AssembliesToDraw; LinesDrawn++)
|
||||
{
|
||||
rect ElementBounds = DrawListElementBackground(&List, Mouse, RenderBuffer);
|
||||
rect Bounds = ui_ReserveElementBounds(&Layout);
|
||||
v4 ListItemBGColor = ui_GetListItemBGColor(State->Interface_.Style, LinesDrawn);
|
||||
ui_FillRect(&State->Interface_, Bounds, ListItemBGColor);
|
||||
gs_list_handle AssemblyHandle = *State->ActiveAssemblyIndecies.GetElementAtIndex(LinesDrawn);
|
||||
assembly Assembly = *State->AssemblyList.GetElementWithHandle(AssemblyHandle);
|
||||
PrintF(&TempString, "%S", Assembly.Name);
|
||||
|
||||
if (i < State->ActiveAssemblyIndecies.Used)
|
||||
ui_layout ItemLayout = ui_CreateLayout(State->Interface_, Bounds);
|
||||
ui_StartRow(&ItemLayout, 2);
|
||||
{
|
||||
gs_list_handle AssemblyHandle = *State->ActiveAssemblyIndecies.GetElementAtIndex(i);
|
||||
assembly Assembly = *State->AssemblyList.GetElementWithHandle(AssemblyHandle);
|
||||
PrintF(&TempString, "%S", Assembly.Name);
|
||||
|
||||
DrawString(RenderBuffer, TempString, State->Interface.Font, ElementBounds.Min + TextOffset, WhiteV4);
|
||||
|
||||
PrintF(&TempString, "X");
|
||||
|
||||
v2 XLowerRight = v2{ElementBounds.Max.x - 25, ElementBounds.Min.y + TextOffset.y};
|
||||
v2 XLowerLeft = DrawString(RenderBuffer, TempString, State->Interface.Font, XLowerRight, WhiteV4, Align_Right);
|
||||
|
||||
if (MouseButtonTransitionedUp(Mouse.LeftButtonState)
|
||||
&& PointIsInRange(Mouse.Pos, XLowerLeft, ElementBounds.Max))
|
||||
ui_LayoutDrawString(&State->Interface_, &ItemLayout, TempString, State->Interface_.Style.TextColor);
|
||||
if (ui_LayoutButton(&State->Interface_, &ItemLayout, MakeStringLiteral("X"), ListItemBGColor, ListItemHover, ListItemSelected))
|
||||
{
|
||||
UnloadAssembly(AssemblyHandle.Index, State, Context);
|
||||
}
|
||||
}
|
||||
else if (i == State->ActiveAssemblyIndecies.Used)
|
||||
{
|
||||
PrintF(&TempString, "+ Add Assembly");
|
||||
v2 TextMinX = ElementBounds.Min + TextOffset;
|
||||
DrawString(RenderBuffer, TempString, State->Interface.Font, TextMinX, WhiteV4);
|
||||
ui_EndRow(&ItemLayout);
|
||||
}
|
||||
|
||||
if (MouseButtonTransitionedUp(Mouse.LeftButtonState)
|
||||
&& PointIsInRange(Mouse.Pos, ElementBounds.Min, ElementBounds.Max))
|
||||
if (LinesDrawn < LineCount)
|
||||
{
|
||||
v4 ListItemBGColor = ui_GetListItemBGColor(State->Interface_.Style, LinesDrawn++);
|
||||
PrintF(&TempString, "+ Add Assembly");
|
||||
if (ui_LayoutButton(&State->Interface_, &Layout, TempString, ListItemBGColor, ListItemHover, ListItemSelected))
|
||||
{
|
||||
char FilePath[256];
|
||||
b32 Success = Context.PlatformGetFilePath(FilePath, 256, "Foldhaus Files\0*.fold\0\0");
|
||||
if (Success)
|
||||
{
|
||||
char FilePath[256];
|
||||
b32 Success = Context.PlatformGetFilePath(FilePath, 256, "Foldhaus Files\0*.fold\0\0");
|
||||
if (Success)
|
||||
{
|
||||
LoadAssembly(State, Context, FilePath);
|
||||
}
|
||||
LoadAssembly(State, Context, FilePath);
|
||||
}
|
||||
}
|
||||
|
||||
List.ListElementsCount++;
|
||||
for (; LinesDrawn < LineCount; LinesDrawn++)
|
||||
{
|
||||
rect Bounds = ui_ReserveElementBounds(&Layout);
|
||||
ListItemBGColor = ui_GetListItemBGColor(State->Interface_.Style, LinesDrawn);
|
||||
ui_FillRect(&State->Interface_, Bounds, ListItemBGColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue