diff --git a/src/pp/pp.c b/src/pp/pp.c index 19be0489..3c46702f 100644 --- a/src/pp/pp.c +++ b/src/pp/pp.c @@ -1956,48 +1956,54 @@ void PP_UpdateUser(void) { UI_PushCP(pp_root_box); { - Vec2 size = VEC2(400, 500); + Vec2 window_dims = VEC2(400, 500); + u32 window_background_color = 0xfa1a1d1e; + u32 window_border_color = 0xff343a3b; UI_Report rep = UI_ReportFromKey(g->lister_key); if (rep.flags & UI_ReportFlag_Active) { g->lister_pos = SubVec2(g->ui_cursor, rep.activation_offset); } - - UI_Push(BackgroundColor, 0xfa1a1d1e); - UI_Push(BorderColor, 0xff343a3b); + UI_Push(BackgroundColor, window_background_color); + UI_Push(BorderColor, window_border_color); UI_Push(Border, 1); - UI_SetNext(Rounding, UI_RPIX(15)); - - UI_Push(Width, UI_PIX(size.x, 0)); - UI_Push(Height, UI_PIX(size.y, 0)); - + UI_Push(Rounding, UI_RPIX(15)); + UI_Push(Width, UI_PIX(window_dims.x, 0)); + UI_Push(Height, UI_PIX(window_dims.y, 0)); UI_Push(LayoutAxis, Axis_Y); UI_Push(FloatingPos, g->lister_pos); UI_SetNext(Flags, UI_BoxFlag_Floating); - // UI_SetNext(Rounding, UI_RFILL(1)); UI_Box *lister_box = UI_BuildBox(Lit("lister")); - UI_Box *lister_pad = lister_box; - UI_PushCP(lister_pad); + UI_PushCP(lister_box); { + /* Title bar */ UI_Push(BackgroundColor, 0); + UI_Push(BorderColor, 0); + UI_Push(Rounding, UI_RPIX(0)); UI_Push(LayoutAxis, Axis_X); UI_Push(Width, UI_FILL(1, 0)); UI_Push(Height, UI_FNT(2, 0)); + UI_Box *title_bar = UI_BuildBox(Zstr); + + UI_Push(BorderColor, window_border_color); { - UI_Box *title_bar = UI_BuildBox(Zstr); - UI_PushCP(title_bar); + UI_BuildDivider(UI_PIX(1, 0)); + } + UI_Pop(BorderColor); + + UI_PushCP(title_bar); + { + UI_Push(Width, UI_FILL(1, 0)); + UI_Push(Padding, 0); + UI_Box *left_box = UI_BuildBox(Zstr); + UI_Box *center_box = UI_BuildBox(Zstr); + UI_Box *right_box = UI_BuildBox(Zstr); + + /* Centered title bar */ + UI_PushCP(center_box); { - UI_Push(Width, UI_FILL(1, 0)); - UI_Push(Padding, 0); - UI_Push(BackgroundColor, 0); - UI_Push(Border, 0); - - UI_Box *left_box = UI_BuildBox(Zstr); - UI_Box *center_box = UI_BuildBox(Zstr); - UI_Box *right_box = UI_BuildBox(Zstr); - - UI_PushCP(center_box); + /* Title label */ { UI_SetNext(Width, UI_FIT(1)); UI_SetNext(Text, Lit("Titleeee")); @@ -2005,10 +2011,10 @@ void PP_UpdateUser(void) UI_SetNext(Padding, UI_PADALL(UI_FILL(1, 0))); UI_Box *title_box = UI_BuildBox(Zstr); } - UI_PopCP(); } UI_PopCP(); } + UI_PopCP(); } UI_PopCP(); g->lister_key = lister_box->key; diff --git a/src/ui/ui_common.c b/src/ui/ui_common.c index a207effc..fc576379 100644 --- a/src/ui/ui_common.c +++ b/src/ui/ui_common.c @@ -32,23 +32,55 @@ UI_Box *UI_BuildSpacer(UI_Size size) { UI_Box *box = 0; - UI_Size old_width = UI_PeekTop(Width); - UI_Size old_height = UI_PeekTop(Height); - UI_Box *old_parent = UI_PeekTop(Parent); + UI_Box *old_parent = UI_UseTop(Parent); + UI_Size old_width = UI_UseTop(Width); + UI_Size old_height = UI_UseTop(Height); UI_PushStack(); { - UI_SetNext(Tint, 0); - UI_SetNext(Parent, old_parent); + UI_Push(Tint, 0); + UI_Push(Parent, old_parent); if (old_parent->layout_axis == Axis_X) { - UI_SetNext(Width, size); - UI_SetNext(Height, old_height); + UI_Push(Width, size); + UI_Push(Height, old_height); } else { - UI_SetNext(Width, old_width); - UI_SetNext(Height, size); + UI_Push(Width, old_width); + UI_Push(Height, size); + } + box = UI_BuildBox(Zstr); + } + UI_PopStack(); + return box; +} + +UI_Box *UI_BuildDivider(UI_Size size) +{ + UI_Box *box = 0; + + UI_Box *old_parent = UI_UseTop(Parent); + UI_Size old_width = UI_UseTop(Width); + UI_Size old_height = UI_UseTop(Height); + u32 old_tint = UI_UseTop(Tint); + f32 old_border = UI_UseTop(Border); + u32 old_border_color = UI_UseTop(BorderColor); + + UI_PushStack(); + { + UI_Push(Parent, old_parent); + UI_Push(Tint, old_tint); + UI_Push(BackgroundColor, old_border_color); + if (old_parent->layout_axis == Axis_X) + { + UI_Push(Width, size); + UI_Push(Height, old_height); + } + else + { + UI_Push(Width, old_width); + UI_Push(Height, size); } box = UI_BuildBox(Zstr); } diff --git a/src/ui/ui_common.h b/src/ui/ui_common.h index ccb37579..7e909d93 100644 --- a/src/ui/ui_common.h +++ b/src/ui/ui_common.h @@ -9,3 +9,4 @@ UI_Box *UI_BuildLabelF_(char *fmt_cstr, ...); //~ Spacing helpers UI_Box *UI_BuildSpacer(UI_Size size); +UI_Box *UI_BuildDivider(UI_Size size); diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index d0967bc6..bbb5b5f4 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -149,14 +149,15 @@ void UI_PushStack(void) n->style.kind = kind; stack->style_tops[kind] = n; } - stack->style_tops[UI_StyleKind_Parent]->style.Parent = g->root_box; - stack->style_tops[UI_StyleKind_Width]->style.Width = UI_FILL(1, 0); - stack->style_tops[UI_StyleKind_Height]->style.Height = UI_FILL(1, 0); - stack->style_tops[UI_StyleKind_Font]->style.Font = UI_GetDefaultFontResource(); - stack->style_tops[UI_StyleKind_FontSize]->style.FontSize = 16.0f; - stack->style_tops[UI_StyleKind_Tint]->style.Tint = 0xFFFFFFFF; - stack->style_tops[UI_StyleKind_Tag]->style.Tag.name = Lit("root"); - stack->style_tops[UI_StyleKind_Tag]->style.Tag.hash = HashFnv64(Fnv64Basis, stack->style_tops[UI_StyleKind_Tag]->style.Tag.name); + stack->style_tops[UI_StyleKind_Parent]->style.Parent = g->root_box; + stack->style_tops[UI_StyleKind_Width]->style.Width = UI_FILL(1, 0); + stack->style_tops[UI_StyleKind_Height]->style.Height = UI_FILL(1, 0); + stack->style_tops[UI_StyleKind_Font]->style.Font = UI_GetDefaultFontResource(); + stack->style_tops[UI_StyleKind_FontSize]->style.FontSize = 16.0f; + stack->style_tops[UI_StyleKind_Tint]->style.Tint = 0xFFFFFFFF; + stack->style_tops[UI_StyleKind_Tag]->style.Tag.name = Lit("root"); + stack->style_tops[UI_StyleKind_Tag]->style.Tag.hash = HashFnv64(Fnv64Basis, stack->style_tops[UI_StyleKind_Tag]->style.Tag.name); + stack->style_tops[UI_StyleKind_DebugColor]->style.DebugColor = Rgba32F(1, 0, 1, 0.5); } stack->next = g->top_stack; @@ -487,6 +488,7 @@ UI_Box *UI_BuildBox(String seed) box->layout_axis = UI_UseTop(LayoutAxis); box->background_color = UI_UseTop(BackgroundColor); box->border_color = UI_UseTop(BorderColor); + box->debug_color = UI_UseTop(DebugColor); box->tint = UI_UseTop(Tint); box->border = UI_UseTop(Border); box->font_resource = UI_UseTop(Font); @@ -1132,6 +1134,7 @@ i64 UI_EndFrame(UI_Frame frame) rect->tex_uv1 = VEC2(1, 1); rect->background_srgb = box->background_color; rect->border_srgb = box->border_color; + rect->debug_srgb = box->debug_color; rect->tint_srgb = box->tint; rect->border = box->border; @@ -1249,6 +1252,7 @@ i64 UI_EndFrame(UI_Frame frame) rect->p0 = AddVec2(baseline, VEC2(rr.pos, 0)); rect->p0 = AddVec2(rect->p0, rr.offset); rect->p1 = AddVec2(rect->p0, glyph_size); + rect->debug_srgb = box->debug_color; rect->tint_srgb = box->tint; rect->tex_uv0 = MulVec2Vec2(atlas_p0, inv_font_image_size); rect->tex_uv1 = MulVec2Vec2(atlas_p1, inv_font_image_size); @@ -1310,7 +1314,7 @@ i64 UI_EndFrame(UI_Frame frame) sig.viewport_size = RoundVec2ToVec2I32(render_viewport.size); sig.sampler = GPU_SamplerStateRidFromResource(GPU_GetCommonPointSampler()); sig.rects = GPU_StructuredBufferRidFromResource(draw_rects_buffer); - sig.debug_srgb = Rgba32F(1, 0, 1, 0.5); + sig.debug_enabled = 1; GPU_Rasterize(cl, &sig, UI_RectVS, UI_RectPS, diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index eb9b0a75..a644df74 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -96,6 +96,7 @@ Enum(UI_BoxFlag) x(Size, UI_Size) \ x(BackgroundColor, u32) \ x(BorderColor, u32) \ + x(DebugColor, u32) \ x(Tint, u32) \ x(Border, f32) \ x(FloatingPos, Vec2) \ @@ -217,6 +218,7 @@ Struct(UI_Box) UI_Round rounding; u32 background_color; u32 border_color; + u32 debug_color; u32 text_color; u32 tint; f32 border; diff --git a/src/ui/ui_draw.gpu b/src/ui/ui_draw.gpu index 2ed133c5..e14e81a5 100644 --- a/src/ui/ui_draw.gpu +++ b/src/ui/ui_draw.gpu @@ -129,8 +129,14 @@ UI_RectPS_Output PSDef(UI_RectPS, UI_RectPS_Input input) Vec4 final_color = lerp(background_color, border_color, border_blend); final_color *= input.tint_lin; + /* Debug color */ + if (sig.debug_enabled) + { + final_color = LinearFromSrgbU32(rect.debug_srgb); + } + UI_RectPS_Output output; - output.sv_target0 = sig.debug_srgb != 0 ? LinearFromSrgbU32(sig.debug_srgb) : final_color; + output.sv_target0 = final_color; return output; } diff --git a/src/ui/ui_draw.h b/src/ui/ui_draw.h index 4267fe06..b1b90efc 100644 --- a/src/ui/ui_draw.h +++ b/src/ui/ui_draw.h @@ -8,7 +8,7 @@ Struct(UI_RectSig) StructuredBufferRid rects; /* 01 consts */ SamplerStateRid sampler; /* 01 consts */ /* ----------------------------------------------------- */ - u32 debug_srgb; /* 01 consts */ + b32 debug_enabled; /* 01 consts */ u32 _pad0; /* 01 consts (padding) */ u32 _pad1; /* 01 consts (padding) */ u32 _pad2; /* 01 consts (padding) */ @@ -30,6 +30,7 @@ Struct(UI_RectInstance) u32 tint_srgb; u32 background_srgb; u32 border_srgb; + u32 debug_srgb; f32 border; Vec2 tex_uv0; Vec2 tex_uv1;