some changes

This commit is contained in:
Matthew 2025-12-15 08:30:56 +11:00
parent f3262c8fb6
commit 2ebbe3d911
2 changed files with 62 additions and 15 deletions

View File

@ -166,6 +166,33 @@ Cycle(EditorCtx* ctx, Inputs* inputs)
Push!("bg_col", true)(ui_ctx, col1); Push!("bg_col", true)(ui_ctx, col1);
UIItem* p1 = MakeItem("###p1", UIF.DrawBackground|UIF.Resizeable); UIItem* p1 = MakeItem("###p1", UIF.DrawBackground|UIF.Resizeable);
Push!("parent")(ui_ctx, p1);
Vec4[4] c0 = Vec4(Vec3(0.2), 1.0);
Vec4[4] c1 = Vec4(Vec3(0.4), 1.0);
Vec4[4] c2 = Vec4(Vec3(0.6), 1.0);
Vec4[4] c3 = Vec4(Vec3(0.8), 1.0);
Vec4[4] c4 = Vec4(1.0);
Push!("bg_col", true)(ui_ctx, c0);
Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.1));
MakeItem("###c0", UIF.DrawBackground);
Push!("bg_col", true)(ui_ctx, c1);
Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.13));
MakeItem("###c1", UIF.DrawBackground);
Push!("bg_col", true)(ui_ctx, c2);
Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.17));
MakeItem("###c2", UIF.DrawBackground);
Push!("bg_col", true)(ui_ctx, c3);
Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.25));
MakeItem("###c3", UIF.DrawBackground);
Push!("bg_col", true)(ui_ctx, c4);
Push!("size_info", true)(ui_ctx, MakeUISizeY(ST.Percentage, 0.35));
MakeItem("###c4", UIF.DrawBackground);
/* /*
UIPanel* root = ctx.base_panel; UIPanel* root = ctx.base_panel;

View File

@ -53,7 +53,7 @@ const u8[] FRAGMENT_BYTES = import("gui.frag.spv");
f32 g_corner_radius_default = 2.0; f32 g_corner_radius_default = 2.0;
f32 g_edge_softness_default = 0.1; f32 g_edge_softness_default = 0.1;
f32 g_border_thickness_default = 2.0; f32 g_border_thickness_default = 0.0;
Vec4[4] g_bg_col_default = BG_COL; Vec4[4] g_bg_col_default = BG_COL;
Vec4[4] g_bg_hl_col_default = BG_HL_COL; Vec4[4] g_bg_hl_col_default = BG_HL_COL;
Vec4[4] g_border_col_default = BORDER_COL; Vec4[4] g_border_col_default = BORDER_COL;
@ -128,11 +128,12 @@ alias UIS = UISignal;
enum UIEvent enum UIEvent
{ {
None = 0, None = 0,
Click = 1<<0, Click = 1<<0,
Drag = 1<<1, DragRelease = 1<<1,
DragStart = 1<<2, Drag = 1<<2,
Press = 1<<3, DragStart = 1<<3,
Press = 1<<4,
} }
alias UIE = UIEvent; alias UIE = UIEvent;
@ -268,7 +269,12 @@ mixin template UIItemParameters()
enum info = CtxMemberInfo!(i); enum info = CtxMemberInfo!(i);
static if(info.is_stack) static if(info.is_stack)
{ {
fields ~= typeof(UICtx.tupleof[i].top.value).stringof ~ " " ~ info.id ~ ";\n"; fields ~= typeof(UICtx.tupleof[i].top.value).stringof ~ " " ~ info.id;
static if(is(typeof(UICtx.tupleof[i]): f32))
{
fields ~= " = 0.0";
}
fields ~= ";\n";
} }
} }
} }
@ -598,6 +604,12 @@ Signal(UIItem* item)
taken = true; taken = true;
} }
if(ctx.drag_item == item && i.type == UIE.DragRelease)
{
ctx.drag_item = g_UI_NIL;
taken = true;
}
if(taken) if(taken)
{ {
DLLRemove(&ctx.events, i, g_UI_NIL_INPUT); DLLRemove(&ctx.events, i, g_UI_NIL_INPUT);
@ -637,6 +649,10 @@ BeginUI(Inputs* inputs)
{ {
PushUIEvent(ctx, UIInput(UIE.Click)); PushUIEvent(ctx, UIInput(UIE.Click));
} }
else if(!mouse_down)
{
PushUIEvent(ctx, UIInput(UIE.DragRelease));
}
dragging = false; dragging = false;
} break; } break;
case Input.MouseMotion: case Input.MouseMotion:
@ -805,7 +821,6 @@ EndUI()
// Violations // Violations
for(UIItem* item = ctx.root; !Nil(item); item = Recurse!(true)(item, g_UI_NIL)) for(UIItem* item = ctx.root; !Nil(item); item = Recurse!(true)(item, g_UI_NIL))
{ {
Logf("ccc %s", cast(char[])item.key.hash_text);
f32 size = item.size[axis]; // InnerSize!(axis)(item); f32 size = item.size[axis]; // InnerSize!(axis)(item);
if(axis == item.layout_axis) if(axis == item.layout_axis)
@ -816,7 +831,6 @@ EndUI()
children_size += c.size.v[axis]; children_size += c.size.v[axis];
} }
Logf("%s %s %s", cast(char[])item.key.hash_text, size, children_size);
if(children_size > size) if(children_size > size)
{ {
f32 excess = children_size - size; f32 excess = children_size - size;
@ -839,7 +853,6 @@ EndUI()
for(UIItem* c = item.last; !Nil(c); c = c.prev) for(UIItem* c = item.last; !Nil(c); c = c.prev)
{ {
f32 reduced = Min(excess, c.size[axis]); f32 reduced = Min(excess, c.size[axis]);
Logf("r %s", reduced);
excess -= reduced; excess -= reduced;
c.size.v[axis] -= reduced; c.size.v[axis] -= reduced;
@ -849,7 +862,6 @@ EndUI()
} }
} }
Logf("%s %s", excess, cast(char[])item.key.hash_text);
assert(excess < 0.0009); assert(excess < 0.0009);
} }
} }
@ -877,10 +889,6 @@ EndUI()
f32 end_pos = pos + item.size.v[axis]; f32 end_pos = pos + item.size.v[axis];
item.rect.p0.v[axis] = pos + padding; item.rect.p0.v[axis] = pos + padding;
if(axis == A2D.Y)
{
Logf("padding %s %s", pos, padding);
}
item.rect.p1.v[axis] = end_pos; item.rect.p1.v[axis] = end_pos;
assert(!isNaN(item.rect.p0.v[axis])); assert(!isNaN(item.rect.p0.v[axis]));
@ -929,6 +937,18 @@ EndUI()
FinishRendering(&rd); FinishRendering(&rd);
SubmitAndPresent(&rd); SubmitAndPresent(&rd);
} }
if(!Nil(ctx.drag_item))
{
for(UIInput* i = ctx.events.first; !CheckNil(g_UI_NIL_INPUT, i); i = i.next)
{
if(i.type == UIE.DragRelease)
{
ctx.drag_item = g_UI_NIL;
break;
}
}
}
} }
void void