test panels/animations, fix colorspace in shader

This commit is contained in:
Matthew 2025-09-03 06:00:45 +10:00
parent 2c2e0c705d
commit 849404f78a
5 changed files with 129 additions and 7 deletions

Binary file not shown.

View File

@ -188,11 +188,21 @@ Cycle(Editor* ed, Inputs* inputs)
*/ */
u32 count = 0; u32 count = 0;
static bool init = false;
static Timer timer;
static u32 box_count = 1; static u32 box_count = 1;
if (!init)
{
timer = CreateTimer();
init = true;
}
u32 prev_box_count = box_count;
f32 delta = DeltaTime(&timer);
for(auto ev = inputs.list.first; ev != null; ev = ev.next) for(auto ev = inputs.list.first; ev != null; ev = ev.next)
{ {
count += 1; count += 1;
Logf("%s", ev.value.key);
switch(ev.value.key) switch(ev.value.key)
{ {
case KBI.One: box_count = 1; break; case KBI.One: box_count = 1; break;
@ -208,13 +218,104 @@ Cycle(Editor* ed, Inputs* inputs)
} }
} }
static UIPanel* panel = null;
if (panel == null)
{
panel = Alloc!(UIPanel);
panel.split_axis = A2D.X;
panel.percent = 1.0;
panel.first = panel.last = Alloc!(UIPanel);
panel.first.percent = 1.0;
UIPanel* child = panel.first;
foreach(i; 0 .. 8)
{
UIPanel* p = Alloc!(UIPanel);
child.next = p;
panel.last = p;
child = p;
}
}
char[128] buf = 0; char[128] buf = 0;
f32 x_pct = 1.0/box_count; f32 x_pct = 1.0/box_count;
if (box_count > prev_box_count)
{
u32 added = box_count - prev_box_count;
f32 insert_size = 0.0;
UIPanel* child = panel.first;
foreach(i; 0 .. prev_box_count)
{
child.anim.start = child.percent;
child.anim.end = x_pct;
child.anim.time_start = 0.2;
child.anim.time_remaining = 0.2;
child = child.next;
}
foreach(i; 0 .. box_count-prev_box_count)
{
child.anim.start = insert_size;
child.anim.end = x_pct;
child.anim.time_start = 0.2;
child.anim.time_remaining = 0.2;
child.percent = insert_size;
child = child.next;
}
}
else if (box_count < prev_box_count)
{
UIPanel* child = panel.first;
foreach(i; 0 .. box_count)
{
child.anim.start = child.percent;
child.anim.end = x_pct;
child.anim.time_start = 0.2;
child.anim.time_remaining = 0.2;
child = child.next;
}
}
else
{
UIPanel* child = panel.first;
foreach(i; 0 .. box_count)
{
if (child.anim.time_remaining == 0.0) break;
f32 r = child.anim.time_remaining;
r -= delta;
if (r < 0.0)
{
r = 0.0;
}
f32 t = Remap(r, 0.0, child.anim.time_start, 1.0, 0.0);
child.percent = Mix(child.anim.start, child.anim.end, t);
child.anim.time_remaining = r;
if (r == 0.0)
{
child.anim.start = child.anim.end = child.anim.time_start = 0.0;
}
child = child.next;
}
}
UIPanel* child = panel.first;
foreach(i; 0 .. box_count) foreach(i; 0 .. box_count)
{ {
buf.sformat("##%s", i); buf.sformat("##%s", i);
Logf("%r %s %s %f", buf, i, box_count, x_pct); DrawPanel(cast(u8[])buf, Vec4(Vec3(x_pct * i), 1.0), child);
WindowItem(cast(u8[])buf, x_pct, 1.0, Vec4(Vec3(x_pct * i), 1.0)); child = child.next;
} }
BeginFrame(&ed.rd); BeginFrame(&ed.rd);

View File

@ -164,6 +164,8 @@ struct UIItem
Rect rect; Rect rect;
f32 text_scale; f32 text_scale;
Axis2D layout_axis; Axis2D layout_axis;
f32 hot_t;
f32 active_t;
} }
struct UIKey struct UIKey

View File

@ -2,9 +2,25 @@ import dlib;
import ui; import ui;
struct Window struct WidgetAnimation
{ {
f32 start;
f32 end;
f32 time_start;
f32 time_remaining;
}
struct UIPanel
{
Axis2D split_axis;
f32 percent;
UIPanel* first;
UIPanel* last;
UIPanel* next;
u32 count;
WidgetAnimation anim;
} }
UIItem* UIItem*
@ -25,10 +41,13 @@ RootItem()
} }
UIItem* UIItem*
WindowItem(u8[] str, f32 x_pct, f32 y_pct, Vec4 col) DrawPanel(u8[] str, Vec4 col, UIPanel* panel)
{ {
UIKey key = MakeKey(str); UIKey key = MakeKey(str);
f32 x_pct = panel.split_axis == A2D.X ? panel.percent : 1.0;
f32 y_pct = panel.split_axis == A2D.Y ? panel.percent : 1.0;
SetProp!(CtxP.AxisX)(UISize(SK.PercentOfParent, x_pct)); SetProp!(CtxP.AxisX)(UISize(SK.PercentOfParent, x_pct));
SetProp!(CtxP.AxisY)(UISize(SK.PercentOfParent, y_pct)); SetProp!(CtxP.AxisY)(UISize(SK.PercentOfParent, y_pct));
SetProp!(CtxP.BGColor)(col); SetProp!(CtxP.BGColor)(col);

View File

@ -78,7 +78,7 @@ void main()
//tex_color = pow(tex_color, gamma); //tex_color = pow(tex_color, gamma);
} }
vec4 color = FD.color; vec4 color = ToLinear(FD.color);
vec4 out_color = color * tex_color * sdf_factor * border_factor; vec4 out_color = color * tex_color * sdf_factor * border_factor;
FragColor = out_color; FragColor = out_color;