Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
feat: radial animation
1644yeeaaea17dd444
diff --git a/src/Filee.App/Controls/DonutMenu.Flip.cs b/src/Filee.App/Controls/DonutMenu.Flip.csindex 691d3083..c3cf4294 100644--- a/src/Filee.App/Controls/DonutMenu.Flip.cs+++ b/src/Filee.App/Controls/DonutMenu.Flip.cs@@ -142,7 +142,10 @@ public sealed partial class DonutMenuvar u = Progress(oldFace, index);if (oldFace ? u >= 0.5 : u < 0.5)return 0;- return Math.Max(Math.Abs(Math.Cos(Math.PI * u)), 0.01);+ // Ease each half to zero velocity at the edge: no minimum-width stripe or+ // abrupt change of direction as the old face hands over to the new one.+ var half = oldFace ? 1 - 2 * u : 2 * u - 1;+ return half * half * (3 - 2 * half);}internal Matrix SliceFlipTransform(bool oldFace, int index)@@ -153,7 +156,7 @@ public sealed partial class DonutMenuvar mid = oldFace ? _oldFace![index].Mid : IsEditMode ? _mid[index].Value : DonutGeometry.MidAngle(index, Count);var center = Center;return Matrix.CreateTranslation(-center.X, -center.Y) * Matrix.CreateRotation(-mid) *- Matrix.CreateScale(Math.Max(width, 0.01), 1) * Matrix.CreateRotation(mid) *+ Matrix.CreateScale(width, 1) * Matrix.CreateRotation(mid) *Matrix.CreateTranslation(center.X, center.Y);}@@ -291,6 +294,7 @@ public sealed partial class DonutMenureturn true;}CaptureOldFace();+ _openClock = double.MaxValue; // The captured outgoing pose owns any unfinished opening.BeginWave(incomingOnly: false);var pointed = _lastExternalAt is { } drag && HitTest(drag).Kind is DonutHitKind.Segment or DonutHitKind.SubSegment? drag : !_keyboardHold && _lastPointer is { } pointer &&@@ -334,11 +338,20 @@ public sealed partial class DonutMenu{if (_flipClock < 0)return false;- _flipClock += dt;- if (_flipClock < FlipDuration)- return true;- EndFlip();- return IsFlipping; // a queued flip started+ // Consume the remainder on a queued turn instead of losing a frame at the seam.+ // A single queued turn is the maximum; extra key presses toggle its parity.+ for (var turn = 0; turn < 2 && IsFlipping; turn++)+ {+ var remaining = FlipDuration - _flipClock;+ if (dt < remaining)+ {+ _flipClock += dt;+ return true;+ }+ dt -= remaining;+ EndFlip();+ }+ return IsFlipping;}/// <summary>Ends a running wave on the new face: animations off or frames stalled.</summary>diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.csindex 04b6ff6f..1153710b 100644--- a/src/Filee.App/Controls/DonutMenu.cs+++ b/src/Filee.App/Controls/DonutMenu.cs@@ -92,8 +92,9 @@ public sealed partial class DonutMenu : Control/// <summary>Gap between slices in pixels (keeps the donut "full" while separating slices).</summary>private const double GapPixels = 3;private const double PopOut = 7;- private const double OpenDuration = 0.42;- private const double OpenStagger = 0.028;+ private const double OpenDuration = 0.30;+ private const double OpenStagger = 0.012;+ private double[] _closeFrom = [];private const double DragStartDistance = 5;// Pencil (Material "edit") path in a 24×24 box.@@ -229,6 +230,7 @@ public sealed partial class DonutMenu : Controlreturn;}Array.Fill(_open, 0);+ _lastFrame = null;_openClock = 0;StartAnimation();}@@ -243,6 +245,7 @@ public sealed partial class DonutMenu : Controldone();return;}+ _closeFrom = (double[])_open.Clone();_closing = true;_closeCallback = done;_openClock = 0;@@ -711,9 +714,10 @@ public sealed partial class DonutMenu : Controlif (loop != _loop)return; // a loop that was given up on as stalled, replaced by a newer one_lastTick = Environment.TickCount64;- var dt = _lastFrame is { } last ? Math.Clamp((time - last).TotalSeconds, 0, 0.05) : 1 / 60.0;+ var elapsed = _lastFrame is { } last ? Math.Max(0, (time - last).TotalSeconds) : 0;+ var dt = Math.Min(elapsed, 0.05);_lastFrame = time;- var active = Advance(dt);+ var active = Advance(dt, elapsed);InvalidateVisual();if (active && TopLevel.GetTopLevel(this) is { } top)@@ -726,7 +730,7 @@ public sealed partial class DonutMenu : Control/// Advances every animation by <paramref name="dt"/> seconds. Returns true while more frames are needed./// Internal so tests can step time deterministically./// </summary>- internal bool Advance(double dt)+ internal bool Advance(double dt, double? elapsed = null){var active = false;@@ -762,16 +766,20 @@ public sealed partial class DonutMenu : Control_shownExpanded = -1;active |= StepProgress(dt);active |= StepLayout(dt);- active |= StepFlip(dt);+ active |= StepFlip(elapsed ?? dt);if (_openClock < double.MaxValue){- _openClock += dt;+ _openClock += elapsed ?? dt;var done = true;for (var i = 0; i < _open.Length; i++){- var t = Math.Clamp((_openClock - i * (_closing ? 0.01 : OpenStagger)) / (_closing ? 0.16 : OpenDuration), 0, 1);- _open[i] = _closing ? 1 - EaseInCubic(t) : EaseOutBack(t);+ // Keep the wave brief even with many slices; a late frame must not stretch its duration.+ var delay = _closing ? 0 : Math.Min(i * OpenStagger, 0.072);+ var t = Math.Clamp((_openClock - delay) / (_closing ? 0.14 : OpenDuration), 0, 1);+ _open[i] = _closing+ ? (i < _closeFrom.Length ? _closeFrom[i] : 1) * (1 - EaseInCubic(t))+ : EaseOutBack(t);done &= t >= 1;}if (done)@@ -800,7 +808,7 @@ public sealed partial class DonutMenu : Controlprivate static double EaseOutBack(double t){- const double c1 = 1.55;+ const double c1 = 0.8;const double c3 = c1 + 1;return 1 + c3 * Math.Pow(t - 1, 3) + c1 * Math.Pow(t - 1, 2);}@@ -871,8 +879,8 @@ public sealed partial class DonutMenu : Controlvar offset = DonutGeometry.PointAt(new Point(0, 0), hover * PopOut, mid);// Open animation: scale up from the centre with a small twist.- var scale = 0.55 + 0.45 * open;- var rotate = (1 - Math.Min(open, 1)) * -0.35;+ var scale = 0.78 + 0.22 * open;+ var rotate = (1 - Math.Min(open, 1)) * -0.12;var transform =Matrix.CreateTranslation(-center.X, -center.Y) *Matrix.CreateRotation(rotate) *@@ -904,8 +912,8 @@ public sealed partial class DonutMenu : Controlif (SliceFlipWidth(true, i) == 0 || slice.Open <= 0.001)continue;var offset = DonutGeometry.PointAt(new Point(0, 0), slice.Hover * PopOut, slice.Mid);- var scale = 0.55 + 0.45 * slice.Open;- var rotate = (1 - Math.Min(slice.Open, 1)) * -0.35;+ var scale = 0.78 + 0.22 * slice.Open;+ var rotate = (1 - Math.Min(slice.Open, 1)) * -0.12;var transform = Matrix.CreateTranslation(-center.X, -center.Y) * Matrix.CreateRotation(rotate) *Matrix.CreateScale(scale * (1 + slice.Hover * 0.025), scale * (1 + slice.Hover * 0.025)) *Matrix.CreateTranslation(center.X + offset.X, center.Y + offset.Y) *@@ -956,11 +964,11 @@ public sealed partial class DonutMenu : Controlcontext.DrawEllipse(WithOpacity(DangerBrush, 0.18), null, center, radius, radius);var maxWidth = radius * 1.6;- var title = MakeText(CenterTitle ?? "", bold, 14, Foreground, maxWidth, maxLines: 2);- var subtitle = MakeText(CenterSubtitle ?? "", regular, 11.5, cancelHot ? DangerBrush : SecondaryForeground, maxWidth, maxLines: 2);+ var title = CachedText(CenterTitle ?? "", bold, 14, Foreground, maxWidth, maxLines: 2);+ var subtitle = CachedText(CenterSubtitle ?? "", regular, 11.5, cancelHot ? DangerBrush : SecondaryForeground, maxWidth, maxLines: 2);// "⟳ Tab back": small, under the rest, a little narrower (the hub is round), with room for its icons.var hintIcons = FlipArrowSize + (CenterHintWheel ? MouseWidth + MouseGap : 0) + IconGap;- var hint = string.IsNullOrEmpty(CenterHint) ? null : MakeText(CenterHint, regular, 10.5, SecondaryForeground, maxWidth * 0.85 - hintIcons);+ var hint = string.IsNullOrEmpty(CenterHint) ? null : CachedText(CenterHint, regular, 10.5, SecondaryForeground, maxWidth * 0.85 - hintIcons);var total = title.Height + (string.IsNullOrEmpty(CenterSubtitle) ? 0 : subtitle.Height + 2) + (hint is null ? 0 : hint.Height + 5);var y = center.Y - total / 2;DrawCentered(context, title, center.X, y);@@ -1046,12 +1054,13 @@ public sealed partial class DonutMenu : Controlvar foreground = hot ? OnAccentBrush : item.IsEnabled ? Foreground : SecondaryForeground;var width = Math.Clamp(maxWidth, 30, 120);var text = KeepKoreanWords(item.Label);- var label = MakeText(text, bold, LabelSize(text, bold, width), foreground, width, maxLines: 2);+ var label = CachedText(text, bold, LabelSize(text, bold, width), foreground, width, maxLines: 2);var showCaption = !string.IsNullOrEmpty(item.Caption) &&!string.Equals(item.Caption, item.Label, StringComparison.OrdinalIgnoreCase) &&label.Height + 14 < maxHeight;var caption = showCaption- ? MakeCaption(item.Caption!, regular, hot ? OnAccentBrush : SecondaryForeground, width, label.Height, maxHeight)+ ? CachedText(item.Caption!, regular, 10.5, hot ? OnAccentBrush : SecondaryForeground, width,+ maxLines: label.Height + 28 < maxHeight ? 2 : 1): null;var total = label.Height + (caption?.Height ?? 0);@@ -1148,6 +1157,18 @@ public sealed partial class DonutMenu : Controlprivate Pen? BorderPen() => SliceBorderBrush is null ? null : new Pen(SliceBorderBrush, 1);+ // Text shaping is much more expensive than the slice transforms. Keep layouts across frames,+ // with all layout/paint inputs in the key so language, theme and hover changes remain correct.+ private readonly Dictionary<(string Text, Typeface Typeface, double Size, IBrush? Brush, double Width, int Lines, string Culture), FormattedText> _textLayouts = new();++ private FormattedText CachedText(string text, Typeface typeface, double size, IBrush? brush, double maxWidth, int maxLines = 1)+ {+ var key = (text, typeface, size, brush, maxWidth, maxLines, CultureInfo.CurrentUICulture.Name);+ if (_textLayouts.TryGetValue(key, out var layout)) return layout;+ if (_textLayouts.Count >= 512) _textLayouts.Clear();+ return _textLayouts[key] = MakeText(text, typeface, size, brush, maxWidth, maxLines);+ }+private static FormattedText MakeText(string text, Typeface typeface, double size, IBrush? brush, double maxWidth, int maxLines = 1) =>new(text, CultureInfo.CurrentUICulture, TextDirection, typeface, size, brush){diff --git a/src/Filee.App/Services/RadialController.cs b/src/Filee.App/Services/RadialController.csindex 05ca6259..e593a8d0 100644--- a/src/Filee.App/Services/RadialController.cs+++ b/src/Filee.App/Services/RadialController.cs@@ -137,9 +137,10 @@ public sealed class RadialController(viewModel.Load(files, clickMode: true);viewModel.FitToThisDonut();window.DonutControl.AllowContextEdit = true;+ // Set the initial pose before showing the reused window, avoiding a fully-open flash.+ window.DonutControl.PlayOpenAnimation();PlaceAndShow(window, x, y, activate: true);WatchFlipKey();- window.DonutControl.PlayOpenAnimation();}/// <summary>The mouse button of the drag gesture was released somewhere.</summary>diff --git a/tests/Filee.App.Tests/DonutAnimationTests.cs b/tests/Filee.App.Tests/DonutAnimationTests.csnew file mode 100644index 00000000..aadea83a--- /dev/null+++ b/tests/Filee.App.Tests/DonutAnimationTests.cs@@ -0,0 +1,103 @@+using System.Reflection;+using Avalonia.Headless.XUnit;+using Filee.App.Controls;+using Filee.App.Services;++namespace Filee.App.Tests;++[Collection("Motion")]+public class DonutAnimationTests+{+ private static double[] Open(DonutMenu donut) => (double[])typeof(DonutMenu)+ .GetField("_open", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(donut)!;+ private static DonutMenu Menu() => new()+ {+ Items = Enumerable.Range(0, 20)+ .Select(i => new DonutItem { Id = i.ToString(), Label = "PNG" }).ToList()+ };++ [AvaloniaTheory]+ [InlineData(60)]+ [InlineData(120)]+ [InlineData(144)]+ public void Opening_finishes_within_400ms_even_with_many_slices(int hz)+ {+ TestServices.EnsureInitialized("en");+ var previous = Motion.Enabled;+ try+ {+ Motion.Set(true);+ var donut = Menu(); donut.PlayOpenAnimation();+ for (var i = 0; i < Math.Ceiling(hz * 0.4); i++) donut.Advance(1.0 / hz);+ Assert.All(Open(donut), value => Assert.Equal(1, value, 6));+ }+ finally { Motion.Set(previous); }+ }++ [AvaloniaFact]+ public void Closing_mid_open_preserves_the_current_pose_and_completes_once()+ {+ TestServices.EnsureInitialized("en");+ var previous = Motion.Enabled;+ try+ {+ Motion.Set(true);+ var donut = Menu(); donut.PlayOpenAnimation(); donut.Advance(0.08);+ var before = Open(donut).ToArray(); var calls = 0;+ donut.PlayCloseAnimation(() => calls++); donut.Advance(0);+ Assert.Equal(before, Open(donut));+ donut.Advance(0.15); donut.Advance(0.15);+ Assert.All(Open(donut), value => Assert.Equal(0, value));+ Assert.Equal(1, calls);+ donut.PlayOpenAnimation(); donut.Advance(0.05, 0.4);+ Assert.All(Open(donut), value => Assert.Equal(1, value));+ }+ finally { Motion.Set(previous); }+ }+ [AvaloniaFact]+ public void Text_layout_cache_reuses_identical_input_and_tracks_paint_and_size()+ {+ TestServices.EnsureInitialized("en");+ var donut = Menu();+ var method = typeof(DonutMenu).GetMethod("CachedText", BindingFlags.Instance | BindingFlags.NonPublic)!;+ object Text(string text, Avalonia.Media.IBrush brush, double width = 80) => method.Invoke(donut,+ [text, new Avalonia.Media.Typeface("Arial"), 13.0, brush, width, 2])!;+ var white = Avalonia.Media.Brushes.White;+ Assert.Same(Text("PNG", white), Text("PNG", white));+ Assert.NotSame(Text("PNG", white), Text("PNG", Avalonia.Media.Brushes.Black));+ Assert.NotSame(Text("PNG", white), Text("PNG", white, 90));+ for (var i = 0; i < 600; i++) Text("Label " + i, white);+ var cache = (System.Collections.IDictionary)typeof(DonutMenu)+ .GetField("_textLayouts", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(donut)!;+ Assert.InRange(cache.Count, 1, 512);+ }++ [AvaloniaFact]+ public void Flip_during_opening_does_not_restart_opening_on_the_new_face()+ {+ TestServices.EnsureInitialized("en"); var previous = Motion.Enabled;+ try+ {+ Motion.Set(true); var donut = Menu(); donut.CanFlip = true;+ donut.FaceSwapping += (_, _) => donut.Items = Menu().Items;+ donut.PlayOpenAnimation(); donut.Advance(0.04); donut.Flip(); donut.Advance(0.01);+ Assert.All(Open(donut), value => Assert.Equal(1, value));+ }+ finally { Motion.Set(previous); }+ }++ [AvaloniaFact]+ public void Late_frame_completes_both_queued_turns_without_stretching_time()+ {+ TestServices.EnsureInitialized("en"); var previous = Motion.Enabled;+ try+ {+ Motion.Set(true); var donut = Menu(); donut.CanFlip = true; var turns = 0;+ donut.FaceSwapping += (_, _) => { turns++; donut.Items = Menu().Items; };+ donut.Flip(); donut.Flip(); donut.Advance(0.05, DonutMenu.FlipDuration * 2 + 0.001);+ Assert.False(donut.IsFlipping); Assert.Equal(2, turns);+ }+ finally { Motion.Set(previous); }+ }++}