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: a click or drop on a neighbour's outer half converts with it
KnifeLemonf4c7dd400d6e
diff --git a/src/Filee.App/Controls/DonutMenu.Groups.cs b/src/Filee.App/Controls/DonutMenu.Groups.csindex 0f1c65cf..3c69cc2d 100644--- a/src/Filee.App/Controls/DonutMenu.Groups.cs+++ b/src/Filee.App/Controls/DonutMenu.Groups.cs@@ -74,6 +74,13 @@ public sealed partial class DonutMenucount, SubSpanOf(count)) >= 0;}+ /// <summary>+ /// True when <paramref name="p"/> is on the outer half of another slice, in the direction of the open ring: the+ /// pointer crosses there on its way to the ring's outer slices.+ /// </summary>+ private bool OnWayToRing(Point p) =>+ _expanded >= 0 && Distance(p, Center) > (InnerRadius + OuterRadius) / 2 && InFan(p, _expanded);+/// <summary>Width of each slice of a ring of <paramref name="count"/>.</summary>private double SubSpanOf(int count) =>DonutGeometry.SubSpan(DonutGeometry.Span(Count), count, (SubRadii.Inner + SubRadii.Outer) / 2);@@ -103,6 +110,11 @@ public sealed partial class DonutMenucase DonutHitKind.Segment when hit.Index == _expanded:_ringFromKeys = false; // the mouse reached it: from here on it leadsbreak;+ case DonutHitKind.Segment when at is { } across && OnWayToRing(across):+ // A neighbour's outer half under the open ring, crossed on the way to its outer slices: that neighbour is+ // what a click or a drop here converts with, but the ring stays open.+ ClearPending();+ break;case DonutHitKind.Segment when hit.Index >= 0 && hit.Index < Count && Items![hit.Index].CanExpand:_expanded = -1;var distance = at is { } p ? Distance(p, Center) : 0;diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.csindex 7c0c36dc..2929cb38 100644--- a/src/Filee.App/Controls/DonutMenu.cs+++ b/src/Filee.App/Controls/DonutMenu.cs@@ -365,13 +365,11 @@ public sealed partial class DonutMenu : Controlvar sub = DonutGeometry.SubIndexAt(Center, p, inner, outer, parentMid, children.Count, subSpan);if (sub >= 0)return new DonutHit(DonutHitKind.SubSegment, _expanded, sub);- // On the way out to the ring the pointer crosses the gap before it, and for the ring's outer slices the- // neighbours' outer edge: there it still belongs to the group, or the ring would fold away (or switch, and- // the hint and the drag cursor flicker) just before it is reached.- var distance = Distance(p, Center);- var crossing = hit.Kind == DonutHitKind.Outside ||- hit.Kind == DonutHitKind.Segment && hit.Index != _expanded && distance > (InnerRadius + OuterRadius) / 2;- if (crossing && distance < inner && InFan(p, _expanded))+ // On the way out to the ring the pointer crosses the gap before it: there it still belongs to the group, or+ // the ring would fold away (or the hint and the drag cursor flicker) just before it is reached. A neighbour's+ // outer half stays that neighbour, so a click or a drop there converts with it; TrackGroups keeps the ring+ // open over it (OnWayToRing).+ if (hit.Kind == DonutHitKind.Outside && Distance(p, Center) < inner && InFan(p, _expanded))return new DonutHit(DonutHitKind.Segment, _expanded);}return hit;diff --git a/tests/Filee.App.Tests/DonutGroupTests.cs b/tests/Filee.App.Tests/DonutGroupTests.csindex 83b35e4f..d0189f77 100644--- a/tests/Filee.App.Tests/DonutGroupTests.cs+++ b/tests/Filee.App.Tests/DonutGroupTests.cs@@ -220,6 +220,71 @@ public class DonutGroupTestswindow.Close();}+ /// <summary>+ /// <paramref name="count"/> slices with a group of six at <see cref="Group"/>, and a point on the outer half of the+ /// next slice, in the direction of the group's ring (crossed on the way to its outer slices).+ /// </summary>+ private static (DonutMenu Donut, Window Window, Point Neighbour) OpenCrowded(int count)+ {+ var items = Enumerable.Range(0, count)+ .Select(i => i == Group ? GroupOf([.. Enumerable.Range(0, Preset.MaxSubPresets).Select(k => Item($"R{k}"))]) : Item($"S{i}"))+ .ToArray();+ var (donut, window) = Open(items);+ var neighbour = DonutGeometry.PointAt(Center(donut), donut.OuterRadius * 0.9,+ DonutGeometry.MidAngle(Group, count) + DonutGeometry.Span(count) * 0.75);+ return (donut, window, neighbour);+ }++ [AvaloniaTheory]+ [InlineData(12)]+ [InlineData(8)]+ public void A_click_on_a_neighbours_outer_half_under_an_open_ring_converts_with_that_neighbour(int count)+ {+ var (donut, window, neighbour) = OpenCrowded(count);+ var invoked = new List<int>();+ donut.SegmentInvoked += (_, index) => invoked.Add(index);+ var inner = OnGroup(donut, donut.OuterRadius * 0.6);+ window.MouseDown(inner, MouseButton.Left);+ window.MouseUp(inner, MouseButton.Left);+ Assert.True(IsOpen(donut));++ window.MouseMove(neighbour);+ Assert.Equal(new DonutHit(DonutHitKind.Segment, Group + 1), donut.HitTest(neighbour));+ Assert.Equal(Group + 1, donut.ActiveIndex);+ Assert.True(IsOpen(donut)); // still open: the pointer may be on its way to the ring's outer slices++ window.MouseDown(neighbour, MouseButton.Left);+ window.MouseUp(neighbour, MouseButton.Left);+ Assert.Equal([Group + 1], invoked);+ window.Close();+ }++ [AvaloniaTheory]+ [InlineData(12)]+ [InlineData(8)]+ public void A_drop_on_a_neighbours_outer_half_under_an_open_ring_converts_with_that_neighbour(int count)+ {+ var (donut, window, neighbour) = OpenCrowded(count);+ var inner = OnGroup(donut, donut.OuterRadius * 0.6);+ donut.SetExternalHit(donut.HitTest(inner), inner);+ donut.ExpandPendingGroup();+ Assert.True(IsOpen(donut));++ donut.SetExternalHit(donut.HitTest(neighbour), neighbour);+ Assert.True(IsOpen(donut));+ Assert.Equal(Group + 1, donut.ActiveIndex);+ var drop = donut.HitTest(neighbour); // what RadialWindow.OnDrop hands the controller+ Assert.Equal(new DonutHit(DonutHitKind.Segment, Group + 1), drop);+ Assert.True(donut.Converts(drop));++ // Carrying on across it reaches the ring's last slice.+ var last = OnRing(donut, Preset.MaxSubPresets - 1);+ donut.SetExternalHit(donut.HitTest(last), last);+ Assert.Equal(new DonutHit(DonutHitKind.SubSegment, Group, Preset.MaxSubPresets - 1), donut.HitTest(last));+ Assert.Equal(Preset.MaxSubPresets - 1, donut.ActiveSubIndex);+ window.Close();+ }+[AvaloniaFact]public void Only_enabled_slices_take_a_drop_and_an_empty_group_opens_nothing(){