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 groups: the donut's see-through seams don't fold an open ring
SeoJCalive9fb48b9ab87f
diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.csindex f1ad7a50..56883da4 100644--- a/src/Filee.App/Controls/DonutMenu.cs+++ b/src/Filee.App/Controls/DonutMenu.cs@@ -737,7 +737,7 @@ public sealed partial class DonutMenu : ControlOnProgressPointerMoved(new Point(double.MaxValue / 4, 0));return;}- if (_press is null)+ if (_press is null && !LeftThroughSeam(e.GetPosition(this))){CollapseGroup();SetHover(-1);@@ -1152,16 +1152,32 @@ public sealed partial class DonutMenu : Controlprivate static readonly IBrush HitBackdrop = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0));/// <summary>- /// <see cref="HitBackdrop"/> over just the fan of <paramref name="group"/>: elsewhere around the donut clicks and- /// drags still go through to the windows below, as without groups.+ /// <see cref="HitBackdrop"/> over the donut and the fan of <paramref name="group"/>. The donut has see-through seams+ /// (between the hole and the slices, between slices): the pointer crossing one on its way to the ring would leave+ /// the window there too. Around the donut, outside the fan, clicks and drags still go through to the windows+ /// below, as without groups./// </summary>private void DrawHitBackdrop(DrawingContext context, Point center, int group, int count){var reach = SubRadii.Outer + BackdropMargin;var span = Math.Min(2 * Math.PI, SubSpanOf(count) * count + 2 * BackdropMargin / reach);+ context.DrawEllipse(HitBackdrop, null, center, OuterRadius + PopOut, OuterRadius + PopOut);context.DrawGeometry(HitBackdrop, null, CreateWedge(center, OuterRadius, reach, DonutGeometry.MidAngle(group, Count), span));}+ /// <summary>+ /// True when the pointer "left" at <paramref name="p"/>, still on the donut or the fan of the group that is open or+ /// about to open: a see-through pixel let it through there (Windows and macOS do that), it didn't really leave.+ /// </summary>+ internal bool LeftThroughSeam(Point p)+ {+ var group = _expanded >= 0 ? _expanded : _pendingGroup;+ if (group < 0 || IsEditMode)+ return false;+ var distance = Distance(p, Center);+ return distance <= OuterRadius + PopOut || distance <= SubRadii.Outer + BackdropMargin && InFan(p, group);+ }+/// <summary>The ring an open group fans out, growing out of its slice.</summary>private void DrawSubRing(DrawingContext context, Point center, Typeface bold, Typeface regular){diff --git a/tests/Filee.App.Tests/DonutGroupTests.cs b/tests/Filee.App.Tests/DonutGroupTests.csindex 3f3c7f1b..778d7255 100644--- a/tests/Filee.App.Tests/DonutGroupTests.cs+++ b/tests/Filee.App.Tests/DonutGroupTests.cs@@ -47,6 +47,17 @@ public class DonutGroupTests/// <summary>The middle of the group's ring slice <paramref name="sub"/>.</summary>private static Point OnRing(DonutMenu donut, int sub) => donut.SubSliceCenter(Group, sub);+ /// <summary>Lets a frame render: the pointer then hits what is drawn, as on screen.</summary>+ private static void Drawn()+ {+ for (var i = 0; i < 3; i++)+ {+ Dispatcher.UIThread.RunJobs();+ AvaloniaHeadlessPlatform.ForceRenderTimerTick();+ }+ Dispatcher.UIThread.RunJobs();+ }+private static bool IsOpen(DonutMenu donut) => donut.HitTest(OnRing(donut, 1)).Kind == DonutHitKind.SubSegment;[AvaloniaFact]@@ -127,6 +138,9 @@ public class DonutGroupTestsvar past = OnGroup(donut, donut.OuterRadius + 7 + DonutMenu.SubRingSpace - 6);Assert.Equal(DonutHitKind.Outside, donut.HitTest(past).Kind);+ // As in the app: the open ring is on screen, and the mouse gets past it by crossing it, not by jumping.+ Drawn();+ window.MouseMove(OnGroup(donut, donut.OuterRadius + 30));window.MouseDown(past, MouseButton.Left);window.MouseUp(past, MouseButton.Left);Assert.False(IsOpen(donut));@@ -409,6 +423,49 @@ public class DonutGroupTestswindow.Close();}+ /// <summary>Alpha of the donut's pixel at <paramref name="p"/>, drawn on its own (as on its see-through window).</summary>+ private static byte AlphaAt(DonutMenu donut, Point p)+ {+ Dispatcher.UIThread.RunJobs();+ var size = new PixelSize((int)donut.Bounds.Width, (int)donut.Bounds.Height);+ using var bitmap = new Avalonia.Media.Imaging.RenderTargetBitmap(size);+ bitmap.Render(donut);+ var pixel = new byte[4];+ var handle = System.Runtime.InteropServices.GCHandle.Alloc(pixel, System.Runtime.InteropServices.GCHandleType.Pinned);+ try+ {+ bitmap.CopyPixels(new PixelRect((int)p.X, (int)p.Y, 1, 1), handle.AddrOfPinnedObject(), 4, 4);+ }+ finally+ {+ handle.Free();+ }+ return pixel[3];+ }++ [AvaloniaFact]+ public void An_open_ring_keeps_the_pointer_on_the_window_across_the_donuts_see_through_seams()+ {+ var (donut, window) = Open();+ var c = Center(donut);+ // The see-through ring between the hole and the slices, on the way from the hole to the group.+ var seam = OnGroup(donut, donut.OuterRadius * donut.HoleRatio - 3);+ Assert.Equal(0, AlphaAt(donut, seam)); // closed: clicks there go through, as without groups++ donut.HandleKey(Key.Right);+ donut.HandleKey(Key.Right);+ donut.HandleKey(Key.Right);+ donut.HandleKey(Key.Enter);+ Assert.True(AlphaAt(donut, seam) > 0); // open: the pointer stays on the window there+ Assert.Equal(0, AlphaAt(donut, DonutGeometry.PointAt(c, donut.OuterRadius + 40, DonutGeometry.MidAngle(0, 4)))); // not around the donut++ // Where Windows or macOS still report the pointer leaving inside the donut or the ring, it didn't leave.+ Assert.True(donut.LeftThroughSeam(seam));+ Assert.True(donut.LeftThroughSeam(OnRing(donut, 0)));+ Assert.False(donut.LeftThroughSeam(new Point(0, 0)));+ window.Close();+ }+[AvaloniaFact]public void With_animations_off_a_group_opens_at_once(){