nested corner rounding
This commit is contained in:
parent
52d7ddb1f4
commit
7d6fcc8a42
@ -13,8 +13,8 @@ Enum(Axis)
|
|||||||
Axis_Y = 1,
|
Axis_Y = 1,
|
||||||
Axis_Z = 2,
|
Axis_Z = 2,
|
||||||
|
|
||||||
Axis_CountXY = 2,
|
Axis_CountXY = 2,
|
||||||
Axis_CountXYZ = 3,
|
Axis_CountXYZ = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@ -250,11 +250,11 @@ F_Run F_RunFromString(Arena *arena, F_Font *font, String str)
|
|||||||
for (CodepointIter it = InitCodepointIter(str); NextCodepoint(&it);)
|
for (CodepointIter it = InitCodepointIter(str); NextCodepoint(&it);)
|
||||||
{
|
{
|
||||||
u32 codepoint = it.codepoint;
|
u32 codepoint = it.codepoint;
|
||||||
if (codepoint < 0 || font->glyphs_count <= codepoint)
|
if (font->glyphs_count <= codepoint)
|
||||||
{
|
{
|
||||||
codepoint = '?';
|
codepoint = '?';
|
||||||
}
|
}
|
||||||
if (0 <= codepoint && codepoint < font->glyphs_count)
|
if (codepoint < font->glyphs_count)
|
||||||
{
|
{
|
||||||
u16 index = font->lookup[codepoint];
|
u16 index = font->lookup[codepoint];
|
||||||
F_Glyph glyph = font->glyphs[index];
|
F_Glyph glyph = font->glyphs[index];
|
||||||
|
|||||||
@ -874,7 +874,7 @@ GPU_Resource *GPU_AcquireResource(GPU_ResourceDesc desc)
|
|||||||
{
|
{
|
||||||
switch (desc.kind)
|
switch (desc.kind)
|
||||||
{
|
{
|
||||||
case GPU_ResourceKind_Sampler: break;
|
default: break;
|
||||||
|
|
||||||
/* Buffer */
|
/* Buffer */
|
||||||
case GPU_ResourceKind_Buffer:
|
case GPU_ResourceKind_Buffer:
|
||||||
@ -1249,6 +1249,7 @@ i64 GPU_EndCommandList(GPU_CommandList *gpu_cl)
|
|||||||
|
|
||||||
switch (cmd->kind)
|
switch (cmd->kind)
|
||||||
{
|
{
|
||||||
|
default: break;
|
||||||
case GPU_D12_CommandKind_TransitionToSrv:
|
case GPU_D12_CommandKind_TransitionToSrv:
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ DirectX12 libs
|
//~ DirectX12 libs
|
||||||
|
|
||||||
#include <d3d12.h>
|
#pragma warning(push, 0)
|
||||||
#include <dxgidebug.h>
|
# include <d3d12.h>
|
||||||
#include <dxgi1_6.h>
|
# include <dxgidebug.h>
|
||||||
|
# include <dxgi1_6.h>
|
||||||
|
#pragma warning(pop)
|
||||||
|
|
||||||
#pragma comment(lib, "d3d12")
|
#pragma comment(lib, "d3d12")
|
||||||
#pragma comment(lib, "dxgi")
|
#pragma comment(lib, "dxgi")
|
||||||
|
|||||||
@ -916,7 +916,7 @@ JobDef(Build, _, __)
|
|||||||
PushStringToList(arena, &cp.compiler_only_flags_msvc, Lit("-Z7"));
|
PushStringToList(arena, &cp.compiler_only_flags_msvc, Lit("-Z7"));
|
||||||
|
|
||||||
/* Enable warnings */
|
/* Enable warnings */
|
||||||
PushStringToList(arena, &cp.warnings_msvc, Lit("-W4"));
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-Wall"));
|
||||||
PushStringToList(arena, &cp.warnings_msvc, Lit("-WX"));
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-WX"));
|
||||||
// PushStringToList(arena, &cp.warnings_msvc, Lit("-we4013")); /* function undefined; assuming extern returning int */
|
// PushStringToList(arena, &cp.warnings_msvc, Lit("-we4013")); /* function undefined; assuming extern returning int */
|
||||||
|
|
||||||
@ -931,6 +931,12 @@ JobDef(Build, _, __)
|
|||||||
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4702")); /* unreachable code */
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4702")); /* unreachable code */
|
||||||
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4127")); /* conditional expression is constant */
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4127")); /* conditional expression is constant */
|
||||||
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4305")); /* 'initializing': truncation from 'double' to 'f32' */
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4305")); /* 'initializing': truncation from 'double' to 'f32' */
|
||||||
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4820")); /* bytes padding added after data member */
|
||||||
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4464")); /* relative include path contains '..' */
|
||||||
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4061")); /* enumerator is not explicitly handled by a case label */
|
||||||
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4242")); /* conversion from X to Y, possible loss of data */
|
||||||
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd4388")); /* signed/unsigned mismatch */
|
||||||
|
PushStringToList(arena, &cp.warnings_msvc, Lit("-wd5045")); /* Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified */
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Clang
|
//- Clang
|
||||||
|
|||||||
@ -348,8 +348,8 @@ String P_GetClipboardText(Arena *arena);
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ @hookdecl Timer hooks
|
//~ @hookdecl Timer hooks
|
||||||
|
|
||||||
Fence *P_GetTimerFence();
|
Fence *P_GetTimerFence(void);
|
||||||
i64 P_GetCurrentTimerPeriodNs();
|
i64 P_GetCurrentTimerPeriodNs(void);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ @hookdecl Sleep hooks
|
//~ @hookdecl Sleep hooks
|
||||||
|
|||||||
@ -980,13 +980,13 @@ String P_GetClipboardText(Arena *arena)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ @hookdef Timer hooks
|
//~ @hookdef Timer hooks
|
||||||
|
|
||||||
Fence *P_GetTimerFence()
|
Fence *P_GetTimerFence(void)
|
||||||
{
|
{
|
||||||
P_W32_SharedState *g = &P_W32_shared_state;
|
P_W32_SharedState *g = &P_W32_shared_state;
|
||||||
return &g->timer_fence;
|
return &g->timer_fence;
|
||||||
}
|
}
|
||||||
|
|
||||||
i64 P_GetCurrentTimerPeriodNs()
|
i64 P_GetCurrentTimerPeriodNs(void)
|
||||||
{
|
{
|
||||||
P_W32_SharedState *g = &P_W32_shared_state;
|
P_W32_SharedState *g = &P_W32_shared_state;
|
||||||
return Atomic64Fetch(&g->average_timer_period_ns.v);
|
return Atomic64Fetch(&g->average_timer_period_ns.v);
|
||||||
|
|||||||
53
src/pp/pp.c
53
src/pp/pp.c
@ -105,7 +105,7 @@ void PP_PushGameUiStyle(void)
|
|||||||
UI_Push(Font, ResourceKeyFromStore(&PP_Resources, Lit("font/fixedsys.ttf")));
|
UI_Push(Font, ResourceKeyFromStore(&PP_Resources, Lit("font/fixedsys.ttf")));
|
||||||
UI_Push(FontSize, 16);
|
UI_Push(FontSize, 16);
|
||||||
|
|
||||||
UI_Push(Rounding, 0);
|
UI_Push(Rounding, UI_RPIX(0));
|
||||||
|
|
||||||
UI_Push(Border, 1);
|
UI_Push(Border, 1);
|
||||||
// UI_Push(BackgroundColor, Rgba32F(0.3, 0.5, 0.3, 0.3));
|
// UI_Push(BackgroundColor, Rgba32F(0.3, 0.5, 0.3, 0.3));
|
||||||
@ -1953,9 +1953,9 @@ void PP_UpdateUser(void)
|
|||||||
UI_SetNext(BackgroundColor, Rgba32F(0.075, 0.075, 0.075, 0.99));
|
UI_SetNext(BackgroundColor, Rgba32F(0.075, 0.075, 0.075, 0.99));
|
||||||
UI_SetNext(BorderColor, Rgba32F(0.2, 0.2, 0.2, 1));
|
UI_SetNext(BorderColor, Rgba32F(0.2, 0.2, 0.2, 1));
|
||||||
UI_SetNext(Border, 2);
|
UI_SetNext(Border, 2);
|
||||||
UI_SetNext(Rounding, 0.1);
|
UI_SetNext(Rounding, UI_RPIX(10));
|
||||||
UI_SetNext(Parent, pp_root_box);
|
UI_SetNext(Parent, pp_root_box);
|
||||||
UI_SetNext(Flags, UI_BoxFlag_Floating | UI_BoxFlag_ClampFloatingX | UI_BoxFlag_ClampFloatingY);
|
UI_SetNext(Flags, UI_BoxFlag_Floating);
|
||||||
UI_SetNext(FloatingPos, g->lister_pos);
|
UI_SetNext(FloatingPos, g->lister_pos);
|
||||||
UI_SetNext(Width, UI_PIX(size.x, 0));
|
UI_SetNext(Width, UI_PIX(size.x, 0));
|
||||||
UI_SetNext(Height, UI_PIX(size.y, 0));
|
UI_SetNext(Height, UI_PIX(size.y, 0));
|
||||||
@ -1964,30 +1964,33 @@ void PP_UpdateUser(void)
|
|||||||
|
|
||||||
UI_PushCheckpoint();
|
UI_PushCheckpoint();
|
||||||
{
|
{
|
||||||
UI_SetNext(Parent, lister_box);
|
UI_Push(Parent, lister_box);
|
||||||
UI_SetNext(LayoutAxis, Axis_X);
|
// UI_BuildSpacer(UI_PIX(10, 0));
|
||||||
UI_SetNext(Width, UI_FILL(1, 0));
|
|
||||||
UI_SetNext(Height, UI_FNT(1, 0));
|
|
||||||
// UI_SetNext(BackgroundColor, 0);
|
|
||||||
// UI_SetNext(Border, 0);
|
|
||||||
UI_Box *title_bar = UI_BuildBox(Zstr);
|
|
||||||
{
|
{
|
||||||
UI_Push(Parent, title_bar);
|
UI_SetNext(LayoutAxis, Axis_X);
|
||||||
UI_Push(Width, UI_FILL(1, 0));
|
UI_SetNext(Width, UI_FILL(1, 0));
|
||||||
UI_Push(Padding, 0);
|
UI_SetNext(Height, UI_FNT(1, 0));
|
||||||
UI_Push(BackgroundColor, 0);
|
// UI_SetNext(BackgroundColor, 0);
|
||||||
UI_Push(Border, 0);
|
// UI_SetNext(Border, 0);
|
||||||
|
UI_Box *title_bar = UI_BuildBox(Zstr);
|
||||||
{
|
{
|
||||||
UI_Box *left_box = UI_BuildBox(Zstr);
|
UI_Push(Parent, title_bar);
|
||||||
}
|
UI_Push(Width, UI_FILL(1, 0));
|
||||||
{
|
UI_Push(Padding, 0);
|
||||||
UI_SetNext(Text, Lit("Title"));
|
UI_Push(BackgroundColor, 0);
|
||||||
UI_SetNext(Flags, UI_BoxFlag_DrawText);
|
UI_Push(Border, 0);
|
||||||
UI_SetNext(Width, UI_FIT(1));
|
{
|
||||||
UI_Box *title_box = UI_BuildBox(Zstr);
|
UI_Box *left_box = UI_BuildBox(Zstr);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
UI_Box *right_box = UI_BuildBox(Zstr);
|
UI_SetNext(Text, Lit("Title"));
|
||||||
|
UI_SetNext(Flags, UI_BoxFlag_DrawText);
|
||||||
|
UI_SetNext(Width, UI_FIT(1));
|
||||||
|
UI_Box *title_box = UI_BuildBox(Zstr);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
UI_Box *right_box = UI_BuildBox(Zstr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,7 +122,7 @@ UI_Box *PP_BuildDebugConsole(b32 minimized)
|
|||||||
UI_SetNext(Width, UI_FILL(1, 0));
|
UI_SetNext(Width, UI_FILL(1, 0));
|
||||||
UI_SetNext(Height, UI_FIT(1));
|
UI_SetNext(Height, UI_FIT(1));
|
||||||
UI_SetNext(BorderColor, Rgba32F(0.25, 0.25, 0.25, 1));
|
UI_SetNext(BorderColor, Rgba32F(0.25, 0.25, 0.25, 1));
|
||||||
UI_SetNext(Rounding, 0);
|
UI_SetNext(Rounding, UI_RPIX(0));
|
||||||
UI_SetNext(Border, 1);
|
UI_SetNext(Border, 1);
|
||||||
UI_Box *log_box = UI_BuildBox(Zstr);
|
UI_Box *log_box = UI_BuildBox(Zstr);
|
||||||
UI_Push(Parent, log_box);
|
UI_Push(Parent, log_box);
|
||||||
|
|||||||
150
src/ui/ui_core.c
150
src/ui/ui_core.c
@ -110,6 +110,7 @@ UI_StyleNode *UI_PushStyleNode(UI_Style desc)
|
|||||||
{
|
{
|
||||||
UI_SharedState *g = &UI_shared_state;
|
UI_SharedState *g = &UI_shared_state;
|
||||||
UI_StyleNode *n = g->style_tops[desc.kind];
|
UI_StyleNode *n = g->style_tops[desc.kind];
|
||||||
|
b32 cancel = 0;
|
||||||
if (!n->style.forced)
|
if (!n->style.forced)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -705,18 +706,14 @@ i64 UI_EndBuild(GPU_Resource *render_target, Xform ui_to_screen_xf)
|
|||||||
/* Solve floating violations */
|
/* Solve floating violations */
|
||||||
for (UI_Box *child = box->first; child; child = child->next)
|
for (UI_Box *child = box->first; child; child = child->next)
|
||||||
{
|
{
|
||||||
if (child->flags & UI_BoxFlag_Floating)
|
if ((child->flags & UI_BoxFlag_Floating) && !(child->flags & UI_BoxFlag_NoFloatingClamp))
|
||||||
{
|
{
|
||||||
if (((child->flags & UI_BoxFlag_ClampFloatingX) && axis == Axis_X) ||
|
f32 size = child->solved_dims[axis];
|
||||||
((child->flags & UI_BoxFlag_ClampFloatingY) && axis == Axis_Y))
|
if (size > box_size)
|
||||||
{
|
{
|
||||||
f32 size = child->solved_dims[axis];
|
f32 strictness = child->pref_size[axis].strictness;
|
||||||
if (size > box_size)
|
f32 flex = size * (1.0 - strictness);
|
||||||
{
|
child->solved_dims[axis] = MaxF32(size - flex, box_size);
|
||||||
f32 strictness = child->pref_size[axis].strictness;
|
|
||||||
f32 flex = size * (1.0 - strictness);
|
|
||||||
child->solved_dims[axis] = MaxF32(size - flex, box_size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -728,38 +725,91 @@ i64 UI_EndBuild(GPU_Resource *render_target, Xform ui_to_screen_xf)
|
|||||||
{
|
{
|
||||||
UI_Box *box = boxes_pre[pre_index];
|
UI_Box *box = boxes_pre[pre_index];
|
||||||
UI_Box *parent = box->parent;
|
UI_Box *parent = box->parent;
|
||||||
Vec2 dims = VEC2(box->solved_dims[0], box->solved_dims[1]);
|
|
||||||
Vec2 pos = ZI;
|
/* Position */
|
||||||
if (box->flags & UI_BoxFlag_Floating)
|
|
||||||
{
|
{
|
||||||
/* Calculate floating box pos */
|
Vec2 dims = VEC2(box->solved_dims[0], box->solved_dims[1]);
|
||||||
Vec2 offset = box->floating_pos;
|
Vec2 final_pos = ZI;
|
||||||
pos = AddVec2(parent->p0, offset);
|
|
||||||
if (box->flags & UI_BoxFlag_ClampFloatingX)
|
/* Floating box position */
|
||||||
|
if (box->flags & UI_BoxFlag_Floating)
|
||||||
{
|
{
|
||||||
f32 overshoot = MaxF32(0, (pos.x + dims.x) - parent->p1.x);
|
Vec2 offset = box->floating_pos;
|
||||||
pos.x = MaxF32(parent->p0.x, pos.x - overshoot);
|
final_pos = AddVec2(parent->p0, offset);
|
||||||
|
if (!(box->flags & UI_BoxFlag_NoFloatingClamp))
|
||||||
|
{
|
||||||
|
{
|
||||||
|
f32 overshoot = MaxF32(0, (final_pos.x + dims.x) - parent->p1.x);
|
||||||
|
final_pos.x = MaxF32(parent->p0.x, final_pos.x - overshoot);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
f32 overshoot = MaxF32((final_pos.y + dims.y) - parent->p1.y, 0);
|
||||||
|
final_pos.y = MaxF32(parent->p0.y, final_pos.y - overshoot);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (box->flags & UI_BoxFlag_ClampFloatingY)
|
/* Non-floating box position */
|
||||||
{
|
else if (parent)
|
||||||
f32 overshoot = MaxF32((pos.y + dims.y) - parent->p1.y, 0);
|
|
||||||
pos.y = MaxF32(parent->p0.y, pos.y - overshoot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Calculate non-floating box pos */
|
|
||||||
if (parent)
|
|
||||||
{
|
{
|
||||||
b32 is_layout_x = parent->layout_axis == Axis_X;
|
b32 is_layout_x = parent->layout_axis == Axis_X;
|
||||||
f32 layout_cursor = parent->layout_cursor;
|
f32 layout_cursor = parent->layout_cursor;
|
||||||
Vec2 offset = VEC2(layout_cursor * is_layout_x, layout_cursor * !is_layout_x);
|
Vec2 offset = VEC2(layout_cursor * is_layout_x, layout_cursor * !is_layout_x);
|
||||||
parent->layout_cursor += dims.x * is_layout_x + dims.y * !is_layout_x;
|
parent->layout_cursor += dims.x * is_layout_x + dims.y * !is_layout_x;
|
||||||
pos = AddVec2(parent->p0, offset);
|
final_pos = AddVec2(parent->p0, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Submit position */
|
||||||
|
box->p0 = final_pos;
|
||||||
|
box->p1 = AddVec2(final_pos, dims);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Rounding */
|
||||||
|
{
|
||||||
|
UI_Round rounding = box->rounding;
|
||||||
|
Vec2 half_dims = MulVec2(SubVec2(box->p1, box->p0), 0.5);
|
||||||
|
f32 min_half_dims = MinF32(half_dims.x, half_dims.y);
|
||||||
|
f32 final_rounding_tl = 0;
|
||||||
|
f32 final_rounding_tr = 0;
|
||||||
|
f32 final_rounding_br = 0;
|
||||||
|
f32 final_rounding_bl = 0;
|
||||||
|
|
||||||
|
switch(rounding.kind)
|
||||||
|
{
|
||||||
|
default: break;
|
||||||
|
case UI_RoundKind_Pixel:
|
||||||
|
{
|
||||||
|
final_rounding_tl = rounding.v;
|
||||||
|
final_rounding_tr = final_rounding_tl;
|
||||||
|
final_rounding_br = final_rounding_tl;
|
||||||
|
final_rounding_bl = final_rounding_tl;
|
||||||
|
} break;
|
||||||
|
case UI_RoundKind_Fill:
|
||||||
|
{
|
||||||
|
final_rounding_tl = rounding.v * min_half_dims;
|
||||||
|
final_rounding_tr = final_rounding_tl;
|
||||||
|
final_rounding_br = final_rounding_tl;
|
||||||
|
final_rounding_bl = final_rounding_tl;
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parent && !((box->flags & UI_BoxFlag_Floating) && (box->flags & UI_BoxFlag_NoFloatingClamp)))
|
||||||
|
{
|
||||||
|
Vec2 vtl = SubVec2(VEC2(parent->p0.x, parent->p0.y), VEC2(box->p0.x, box->p0.y));
|
||||||
|
Vec2 vtr = SubVec2(VEC2(parent->p1.x, parent->p0.y), VEC2(box->p1.x, box->p0.y));
|
||||||
|
Vec2 vbr = SubVec2(VEC2(parent->p1.x, parent->p1.y), VEC2(box->p1.x, box->p1.y));
|
||||||
|
Vec2 vbl = SubVec2(VEC2(parent->p0.x, parent->p1.y), VEC2(box->p0.x, box->p1.y));
|
||||||
|
final_rounding_tl = MaxF32(final_rounding_tl, parent->rounding_tl - Vec2Len(vtl));
|
||||||
|
final_rounding_tr = MaxF32(final_rounding_tr, parent->rounding_tr - Vec2Len(vtr));
|
||||||
|
final_rounding_br = MaxF32(final_rounding_br, parent->rounding_br - Vec2Len(vbr));
|
||||||
|
final_rounding_bl = MaxF32(final_rounding_bl, parent->rounding_bl - Vec2Len(vbl));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Submit rounding */
|
||||||
|
box->rounding_tl = final_rounding_tl;
|
||||||
|
box->rounding_tr = final_rounding_tr;
|
||||||
|
box->rounding_br = final_rounding_br;
|
||||||
|
box->rounding_bl = final_rounding_bl;
|
||||||
}
|
}
|
||||||
box->p0 = pos;
|
|
||||||
box->p1 = AddVec2(pos, dims);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
@ -797,7 +847,41 @@ i64 UI_EndBuild(GPU_Resource *render_target, Xform ui_to_screen_xf)
|
|||||||
rect->border_srgb = box->border_color;
|
rect->border_srgb = box->border_color;
|
||||||
rect->tint_srgb = box->tint;
|
rect->tint_srgb = box->tint;
|
||||||
rect->border = box->border;
|
rect->border = box->border;
|
||||||
rect->rounding = box->rounding;
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Rounding */
|
||||||
|
rect->tl_rounding = box->rounding_tl;
|
||||||
|
rect->tr_rounding = box->rounding_tr;
|
||||||
|
rect->br_rounding = box->rounding_br;
|
||||||
|
rect->bl_rounding = box->rounding_bl;
|
||||||
|
// {
|
||||||
|
// UI_Rounding rounding = box->rounding;
|
||||||
|
// f32 final_rounding = 0;
|
||||||
|
// {
|
||||||
|
// Vec2 half_dims = MulVec2(SubVec2(box->p1, box->p0), 0.5);
|
||||||
|
// f32 min_half_dims = MinF32(half_dims.x, half_dims.y);
|
||||||
|
// switch(rounding.kind)
|
||||||
|
// {
|
||||||
|
// default: break;
|
||||||
|
// case UI_RoundKind_Pixel:
|
||||||
|
// {
|
||||||
|
// final_rounding = rounding.v;
|
||||||
|
// } break;
|
||||||
|
// case UI_RoundKind_Fit:
|
||||||
|
// {
|
||||||
|
// final_rounding = rounding.v * min_half_dims;
|
||||||
|
// } break;
|
||||||
|
// }
|
||||||
|
// final_rounding = MinF32(final_rounding, min_half_dims);
|
||||||
|
// }
|
||||||
|
// rect->tl_rounding = final_rounding;
|
||||||
|
// rect->tr_rounding = final_rounding;
|
||||||
|
// rect->br_rounding = final_rounding;
|
||||||
|
// rect->bl_rounding = final_rounding;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/* Texture */
|
||||||
if (box->background_texture != 0)
|
if (box->background_texture != 0)
|
||||||
{
|
{
|
||||||
rect->tex = GPU_Texture2DRidFromResource(box->background_texture);
|
rect->tex = GPU_Texture2DRidFromResource(box->background_texture);
|
||||||
|
|||||||
@ -14,9 +14,9 @@ Struct(UI_Key)
|
|||||||
|
|
||||||
Enum(UI_SizeKind)
|
Enum(UI_SizeKind)
|
||||||
{
|
{
|
||||||
UI_SizeKind_Fit,
|
UI_SizeKind_Fit, /* Size to contents */
|
||||||
UI_SizeKind_Fill,
|
UI_SizeKind_Fill, /* Size as percent of parent size */
|
||||||
UI_SizeKind_Pixel,
|
UI_SizeKind_Pixel, /* Exact size */
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(UI_Size)
|
Struct(UI_Size)
|
||||||
@ -26,6 +26,21 @@ Struct(UI_Size)
|
|||||||
f32 strictness;
|
f32 strictness;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//~ Rounding types
|
||||||
|
|
||||||
|
Enum(UI_RoundKind)
|
||||||
|
{
|
||||||
|
UI_RoundKind_Pixel, /* Exact radius */
|
||||||
|
UI_RoundKind_Fill, /* Radius as percent of size */
|
||||||
|
};
|
||||||
|
|
||||||
|
Struct(UI_Round)
|
||||||
|
{
|
||||||
|
UI_RoundKind kind;
|
||||||
|
f32 v;
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Box flag types
|
//~ Box flag types
|
||||||
|
|
||||||
@ -35,8 +50,7 @@ Enum(UI_BoxFlag)
|
|||||||
UI_BoxFlag_DrawText = (1 << 0),
|
UI_BoxFlag_DrawText = (1 << 0),
|
||||||
UI_BoxFlag_NoTextTruncation = (1 << 1),
|
UI_BoxFlag_NoTextTruncation = (1 << 1),
|
||||||
UI_BoxFlag_Floating = (1 << 2),
|
UI_BoxFlag_Floating = (1 << 2),
|
||||||
UI_BoxFlag_ClampFloatingX = (1 << 3),
|
UI_BoxFlag_NoFloatingClamp = (1 << 3),
|
||||||
UI_BoxFlag_ClampFloatingY = (1 << 4),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -58,7 +72,7 @@ Enum(UI_BoxFlag)
|
|||||||
x(FontSize, u32) \
|
x(FontSize, u32) \
|
||||||
x(Text, String) \
|
x(Text, String) \
|
||||||
x(Padding, f32) \
|
x(Padding, f32) \
|
||||||
x(Rounding, f32) \
|
x(Rounding, UI_Round) \
|
||||||
x(FloatingPos, Vec2) \
|
x(FloatingPos, Vec2) \
|
||||||
/* ------------------------------------------- */
|
/* ------------------------------------------- */
|
||||||
|
|
||||||
@ -152,18 +166,18 @@ Struct(UI_Box)
|
|||||||
Vec2 background_texture_uv1;
|
Vec2 background_texture_uv1;
|
||||||
|
|
||||||
UI_Size pref_size[Axis_CountXY];
|
UI_Size pref_size[Axis_CountXY];
|
||||||
|
UI_Round rounding;
|
||||||
u32 background_color;
|
u32 background_color;
|
||||||
u32 border_color;
|
u32 border_color;
|
||||||
u32 text_color;
|
u32 text_color;
|
||||||
u32 tint;
|
u32 tint;
|
||||||
f32 border;
|
f32 border;
|
||||||
f32 padding;
|
|
||||||
f32 rounding;
|
|
||||||
Vec2 floating_pos;
|
Vec2 floating_pos;
|
||||||
String text;
|
String text;
|
||||||
Axis layout_axis;
|
Axis layout_axis;
|
||||||
ResourceKey font_resource;
|
ResourceKey font_resource;
|
||||||
f32 font_size;
|
f32 font_size;
|
||||||
|
f32 padding;
|
||||||
|
|
||||||
//- Pre-layout data
|
//- Pre-layout data
|
||||||
u64 pre_index;
|
u64 pre_index;
|
||||||
@ -178,6 +192,10 @@ Struct(UI_Box)
|
|||||||
//- Post-layout data
|
//- Post-layout data
|
||||||
Vec2 p0;
|
Vec2 p0;
|
||||||
Vec2 p1;
|
Vec2 p1;
|
||||||
|
f32 rounding_tl;
|
||||||
|
f32 rounding_tr;
|
||||||
|
f32 rounding_br;
|
||||||
|
f32 rounding_bl;
|
||||||
};
|
};
|
||||||
|
|
||||||
Struct(UI_BoxBin)
|
Struct(UI_BoxBin)
|
||||||
@ -253,18 +271,18 @@ void UI_PopCheckpoint(void);
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Style helpers
|
//~ Style helpers
|
||||||
|
|
||||||
UI_StyleNode *UI_PushStyleNode(UI_Style desc);
|
UI_StyleNode *UI_PushStyleNode(UI_Style desc);
|
||||||
UI_Style UI_PopStyleNode(UI_StyleKind kind);
|
UI_Style UI_PopStyleNode(UI_StyleKind kind);
|
||||||
UI_StyleNode *UI_PeekTopStyleNode(UI_StyleKind kind);
|
UI_StyleNode *UI_PeekTopStyleNode(UI_StyleKind kind);
|
||||||
UI_Style UI_StyleFromTopNode(UI_StyleKind kind, b32 use);
|
UI_Style UI_StyleFromTopNode(UI_StyleKind kind, b32 use);
|
||||||
|
|
||||||
#define UI_SetNext(name, v) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = v, .pop_when_used = 1 })
|
#define UI_SetNext(name, ...) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = __VA_ARGS__, .pop_when_used = 1 })
|
||||||
#define UI_Push(name, v) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = v })
|
#define UI_Push(name, ...) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = __VA_ARGS__ })
|
||||||
#define UI_ForceNext(name, v) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = v, .pop_when_used = 1, .forced = 1 })
|
#define UI_ForceNext(name, ...) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = __VA_ARGS__, .pop_when_used = 1, .forced = 1 })
|
||||||
#define UI_ForcePush(name, v) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = v, .forced = 1 })
|
#define UI_ForcePush(name, ...) UI_PushStyleNode((UI_Style) { .kind = UI_StyleKind_##name, .name = __VA_ARGS__, .forced = 1 })
|
||||||
#define UI_Pop(name, v) UI_PopStyleNode(UI_StyleKind_##name).name
|
#define UI_Pop(name) UI_PopStyleNode(UI_StyleKind_##name).name
|
||||||
#define UI_UseTop(name) UI_StyleFromTopNode(UI_StyleKind_##name, 1).name
|
#define UI_UseTop(name) UI_StyleFromTopNode(UI_StyleKind_##name, 1).name
|
||||||
#define UI_PeekTop(name) UI_StyleFromTopNode(UI_StyleKind_##name, 0).name
|
#define UI_PeekTop(name) UI_StyleFromTopNode(UI_StyleKind_##name, 0).name
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Size helpers
|
//~ Size helpers
|
||||||
@ -276,6 +294,14 @@ UI_Style UI_StyleFromTopNode(UI_StyleKind kind, b32 use);
|
|||||||
#define UI_FILL(_v, _s) UI_SIZE(UI_SizeKind_Fill, (_v), (_s))
|
#define UI_FILL(_v, _s) UI_SIZE(UI_SizeKind_Fill, (_v), (_s))
|
||||||
#define UI_FNT(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (f32)UI_PeekTop(FontSize) * (_v), (_s))
|
#define UI_FNT(_v, _s) UI_SIZE(UI_SizeKind_Pixel, (f32)UI_PeekTop(FontSize) * (_v), (_s))
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//~ Rounding helpers
|
||||||
|
|
||||||
|
#define UI_ROUND(_kind, _v) (UI_Round) { .kind = (_kind), .v = (_v)}
|
||||||
|
|
||||||
|
#define UI_RPIX(_v) UI_ROUND(UI_RoundKind_Pixel, (_v))
|
||||||
|
#define UI_RFILL(_v) UI_ROUND(UI_RoundKind_Fill, (_v))
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
//~ Box
|
//~ Box
|
||||||
|
|
||||||
|
|||||||
@ -71,50 +71,34 @@ UI_RectPS_Output PSDef(UI_RectPS, UI_RectPS_Input input)
|
|||||||
result = input.background_lin;
|
result = input.background_lin;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2 size = Vec2(p1.x - p0.x, p1.y - p0.y);
|
|
||||||
Vec2 half_size = size * 0.5;
|
|
||||||
|
|
||||||
/* Calculate distance to edge (negative means out of bounds) */
|
/* Calculate distance to edge (negative means out of bounds) */
|
||||||
f32 edge_dist;
|
f32 edge_dist = min(min(p.x - p0.x, p1.x - p.x), min(p.y - p0.y, p1.y - p.y));
|
||||||
{
|
{
|
||||||
/* TODO: Read per-corner rounding here */
|
f32 tl_radius = rect.tl_rounding;
|
||||||
f32 radius = min(half_size.x, half_size.y) * rect.rounding;
|
f32 tr_radius = rect.tr_rounding;
|
||||||
Vec2 tl = Vec2(p0.x + radius, p0.y + radius);
|
f32 br_radius = rect.br_rounding;
|
||||||
Vec2 tr = Vec2(p1.x - radius, p0.y + radius);
|
f32 bl_radius = rect.bl_rounding;
|
||||||
Vec2 br = Vec2(p1.x - radius, p1.y - radius);
|
Vec2 tl = Vec2(p0.x + tl_radius, p0.y + tl_radius);
|
||||||
Vec2 bl = Vec2(p0.x + radius, p1.y - radius);
|
Vec2 tr = Vec2(p1.x - tr_radius, p0.y + tr_radius);
|
||||||
|
Vec2 br = Vec2(p1.x - br_radius, p1.y - br_radius);
|
||||||
if (p.x < tl.x && p.y < tl.y)
|
Vec2 bl = Vec2(p0.x + bl_radius, p1.y - bl_radius);
|
||||||
{
|
if (p.x < tl.x && p.y < tl.y) edge_dist = min(edge_dist, tl_radius - length(tl - p));
|
||||||
edge_dist = radius - length(tl - p);
|
if (p.x > tr.x && p.y < tr.y) edge_dist = min(edge_dist, tr_radius - length(tr - p));
|
||||||
}
|
if (p.x > br.x && p.y > br.y) edge_dist = min(edge_dist, br_radius - length(br - p));
|
||||||
else if (p.x > tr.x && p.y < tr.y)
|
if (p.x < bl.x && p.y > bl.y) edge_dist = min(edge_dist, bl_radius - length(bl - p));
|
||||||
{
|
|
||||||
edge_dist = radius - length(tr - p);
|
|
||||||
}
|
|
||||||
else if (p.x > br.x && p.y > br.y)
|
|
||||||
{
|
|
||||||
edge_dist = radius - length(br - p);
|
|
||||||
}
|
|
||||||
else if (p.x < bl.x && p.y > bl.y)
|
|
||||||
{
|
|
||||||
edge_dist = radius - length(bl - p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
edge_dist = min(min(p.x - p0.x, p1.x - p.x), min(p.y - p0.y, p1.y - p.y));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Border */
|
/* Border */
|
||||||
|
if (edge_dist < rect.border)
|
||||||
|
{
|
||||||
|
result = input.border_lin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Out of bounds */
|
||||||
if (edge_dist < 0)
|
if (edge_dist < 0)
|
||||||
{
|
{
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
else if (edge_dist < rect.border)
|
|
||||||
{
|
|
||||||
result = input.border_lin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Tint */
|
/* Tint */
|
||||||
result *= input.tint_lin;
|
result *= input.tint_lin;
|
||||||
|
|||||||
@ -34,7 +34,11 @@ Struct(UI_RectInstance)
|
|||||||
Vec2 tex_uv0;
|
Vec2 tex_uv0;
|
||||||
Vec2 tex_uv1;
|
Vec2 tex_uv1;
|
||||||
Texture2DRid tex;
|
Texture2DRid tex;
|
||||||
f32 rounding;
|
|
||||||
|
f32 tl_rounding;
|
||||||
|
f32 tr_rounding;
|
||||||
|
f32 br_rounding;
|
||||||
|
f32 bl_rounding;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@ -521,6 +521,8 @@ void WND_EndFrame(WND_Frame frame)
|
|||||||
WND_Cmd cmd = n->cmd;
|
WND_Cmd cmd = n->cmd;
|
||||||
switch(cmd.kind)
|
switch(cmd.kind)
|
||||||
{
|
{
|
||||||
|
default: break;
|
||||||
|
|
||||||
//- Minimize
|
//- Minimize
|
||||||
case WND_CmdKind_SetMinimized:
|
case WND_CmdKind_SetMinimized:
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user