diff --git a/assets/gui.frag.spv b/assets/gui.frag.spv index 7e9ac86..8da6167 100644 Binary files a/assets/gui.frag.spv and b/assets/gui.frag.spv differ diff --git a/src/editor/editor.d b/src/editor/editor.d index b651eb4..fe02df6 100644 --- a/src/editor/editor.d +++ b/src/editor/editor.d @@ -188,11 +188,21 @@ Cycle(Editor* ed, Inputs* inputs) */ u32 count = 0; + static bool init = false; + static Timer timer; 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) { count += 1; - Logf("%s", ev.value.key); switch(ev.value.key) { 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; 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) { buf.sformat("##%s", i); - Logf("%r %s %s %f", buf, i, box_count, x_pct); - WindowItem(cast(u8[])buf, x_pct, 1.0, Vec4(Vec3(x_pct * i), 1.0)); + DrawPanel(cast(u8[])buf, Vec4(Vec3(x_pct * i), 1.0), child); + child = child.next; } BeginFrame(&ed.rd); diff --git a/src/editor/ui.d b/src/editor/ui.d index 65dbb5e..db89413 100644 --- a/src/editor/ui.d +++ b/src/editor/ui.d @@ -164,6 +164,8 @@ struct UIItem Rect rect; f32 text_scale; Axis2D layout_axis; + f32 hot_t; + f32 active_t; } struct UIKey diff --git a/src/editor/widgets.d b/src/editor/widgets.d index 17397fa..e5ea738 100644 --- a/src/editor/widgets.d +++ b/src/editor/widgets.d @@ -2,9 +2,25 @@ import dlib; 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* @@ -25,10 +41,13 @@ RootItem() } UIItem* -WindowItem(u8[] str, f32 x_pct, f32 y_pct, Vec4 col) +DrawPanel(u8[] str, Vec4 col, UIPanel* panel) { 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.AxisY)(UISize(SK.PercentOfParent, y_pct)); SetProp!(CtxP.BGColor)(col); diff --git a/src/shaders/gui.frag.glsl b/src/shaders/gui.frag.glsl index 0154884..20399b1 100644 --- a/src/shaders/gui.frag.glsl +++ b/src/shaders/gui.frag.glsl @@ -78,7 +78,7 @@ void main() //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; FragColor = out_color;