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
Donut: a lost animation frame no longer keeps the slice under a dragged file dark
KnifeLemon4bcf45155938
diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.csindex 88ad36d4..5417530a 100644--- a/src/Filee.App/Controls/DonutMenu.cs+++ b/src/Filee.App/Controls/DonutMenu.cs@@ -221,6 +221,9 @@ public sealed partial class DonutMenu : ControlStartAnimation();}+ /// <summary>How far slice <paramref name="index"/> is drawn lit up right now (0 to 1), for the drag log.</summary>+ public double LitAmount(int index) => index >= 0 && index < _hover.Length ? _hover[index].Value : 0;+/// <summary>Edit mode: the slice being dragged is drawn faded.</summary>public void SetDimmedIndex(int index){@@ -485,28 +488,46 @@ public sealed partial class DonutMenu : Control}}+ /// <summary>+ /// A frame loop that got no frame for this long is treated as stopped: a frame request can be lost (the window+ /// hidden in between, for one), and every later animation would wait for it, so the slice under a dragged file+ /// would never light up.+ /// </summary>+ internal const long StalledLoopMs = 250;++ private int _loop; // the current frame loop; frames of an older one are ignored+ private long _lastTick; // Environment.TickCount64 of the last frame or frame request+private void StartAnimation(){InvalidateVisual();- if (_animating)+ if (_animating && Environment.TickCount64 - _lastTick < StalledLoopMs)return;var top = TopLevel.GetTopLevel(this);if (top is null)+ {+ _animating = false;return;+ }_animating = true;_lastFrame = null;- top.RequestAnimationFrame(OnFrame);+ _lastTick = Environment.TickCount64;+ var loop = ++_loop;+ top.RequestAnimationFrame(time => OnFrame(time, loop));}- private void OnFrame(TimeSpan time)+ private void OnFrame(TimeSpan time, int loop){+ if (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;_lastFrame = time;var active = Advance(dt);InvalidateVisual();if (active && TopLevel.GetTopLevel(this) is { } top)- top.RequestAnimationFrame(OnFrame);+ top.RequestAnimationFrame(next => OnFrame(next, loop));else_animating = false;}diff --git a/src/Filee.App/Services/RadialController.cs b/src/Filee.App/Services/RadialController.csindex cc4e7519..8a51c98e 100644--- a/src/Filee.App/Services/RadialController.cs+++ b/src/Filee.App/Services/RadialController.cs@@ -136,6 +136,11 @@ public sealed class RadialController(elseClose();};+ // One line per drag, to tell "the drag never reached the donut" from "it did but nothing lit up" when someone+ // reports a donut that doesn't react.+ window.DragSummary += (events, hit, lit) =>+ log.LogInformation("Drag over the donut: {Events} move event(s), ended on {Kind} {Index}, drawn lit {Lit:0.00}",+ events, hit.Kind, hit.Index, lit);window.EscapePressed += () => Close();window.Deactivated += (_, _) =>{diff --git a/src/Filee.App/Views/RadialWindow.axaml.cs b/src/Filee.App/Views/RadialWindow.axaml.csindex f9f4ed8f..869ff92b 100644--- a/src/Filee.App/Views/RadialWindow.axaml.cs+++ b/src/Filee.App/Views/RadialWindow.axaml.cs@@ -31,6 +31,15 @@ public partial class RadialWindow : Windowpublic event Action? DragLeft;+ /// <summary>+ /// After a drag ends (drop or leave): how many drag-over events came in, where the last one was and how far that+ /// slice was drawn lit up (0 to 1).+ /// </summary>+ public event Action<int, DonutHit, double>? DragSummary;++ private int _dragOverEvents;+ private DonutHit _lastDragHit;+private void OnDragEnter(object? sender, DragEventArgs e){var files = LocalFiles(e);@@ -39,6 +48,7 @@ public partial class RadialWindow : Windowe.DragEffects = DragDropEffects.None;return;}+ _dragOverEvents = 0;FilesEntered?.Invoke(files);OnDragOver(sender, e);}@@ -46,6 +56,8 @@ public partial class RadialWindow : Windowprivate void OnDragOver(object? sender, DragEventArgs e){var hit = Donut.HitTest(e.GetPosition(Donut));+ _dragOverEvents++;+ _lastDragHit = hit;var files = e.DataTransfer.Contains(DataFormat.File);Donut.SetExternalHighlight(hit.Kind == DonutHitKind.Segment ? hit.Index : -1, hit.Kind == DonutHitKind.Center);@@ -56,6 +68,7 @@ public partial class RadialWindow : Windowprivate void OnDragLeave(object? sender, DragEventArgs e){+ DragSummary?.Invoke(_dragOverEvents, _lastDragHit, Donut.LitAmount(_lastDragHit.Index));Donut.SetExternalHighlight(-1);DragLeft?.Invoke();}@@ -63,6 +76,7 @@ public partial class RadialWindow : Windowprivate void OnDrop(object? sender, DragEventArgs e){var hit = Donut.HitTest(e.GetPosition(Donut));+ DragSummary?.Invoke(_dragOverEvents, hit, Donut.LitAmount(hit.Index));Donut.SetExternalHighlight(-1);e.DragEffects = hit.Kind == DonutHitKind.Segment ? DragDropEffects.Copy : DragDropEffects.None;Dropped?.Invoke(hit, LocalFiles(e));diff --git a/tests/Filee.App.Tests/DonutHighlightTests.cs b/tests/Filee.App.Tests/DonutHighlightTests.csnew file mode 100644index 00000000..bff8df25--- /dev/null+++ b/tests/Filee.App.Tests/DonutHighlightTests.cs@@ -0,0 +1,43 @@+// The slice under a dragged file lights up even after a frame of the donut's animation loop got lost.++using System.Reflection;+using Avalonia.Controls;+using Avalonia.Headless;+using Avalonia.Headless.XUnit;+using Avalonia.Threading;+using Filee.App.Controls;++namespace Filee.App.Tests;++public class DonutHighlightTests+{+ [AvaloniaFact]+ public void A_lost_animation_frame_does_not_keep_the_slice_dark()+ {+ TestServices.EnsureInitialized("ko");+ var donut = new DonutMenu+ {+ Items = new[] { "PNG", "JPG", "WEBP", "PDF" }.Select(l => new DonutItem { Id = l, Label = l }).ToList(),+ };+ var window = new Window { Content = donut, SizeToContent = SizeToContent.WidthAndHeight };+ window.Show();+ Dispatcher.UIThread.RunJobs();++ // As after a frame request that never came back: the loop still counts as running, its last frame long ago.+ Set(donut, "_animating", true);+ Set(donut, "_lastTick", Environment.TickCount64 - DonutMenu.StalledLoopMs * 4);++ donut.SetExternalHighlight(2);+ for (var i = 0; i < 90 && donut.LitAmount(2) < 0.9; i++)+ {+ AvaloniaHeadlessPlatform.ForceRenderTimerTick();+ Dispatcher.UIThread.RunJobs();+ }++ Assert.True(donut.LitAmount(2) > 0.9, $"lit {donut.LitAmount(2):0.00}");+ window.Close();+ }++ private static void Set(DonutMenu donut, string field, object value) =>+ typeof(DonutMenu).GetField(field, BindingFlags.Instance | BindingFlags.NonPublic)!.SetValue(donut, value);+}