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 quick flick opens the ring, the gap holds it, clicks elsewhere go through
SeoJCalivec3ce94fe977d
diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.csindex 436eb4dc..e2804613 100644--- a/src/Filee.App/Controls/DonutMenu.cs+++ b/src/Filee.App/Controls/DonutMenu.cs@@ -386,11 +386,13 @@ 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's outer slices the pointer crosses the neighbours' outer edge: there it still- // belongs to the group, or the ring would fold away (or switch) just before it is reached.- if (hit.Kind == DonutHitKind.Segment && hit.Index != _expanded &&- Distance(p, Center) > (InnerRadius + OuterRadius) / 2 &&- DonutGeometry.SubIndexAt(Center, p, 0, double.MaxValue, parentMid, children.Count, subSpan) >= 0)+ // 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))return new DonutHit(DonutHitKind.Segment, _expanded);}return hit;@@ -412,6 +414,17 @@ public sealed partial class DonutMenu : Controlprivate (double Inner, double Outer) SubRadii => (OuterRadius + PopOut + SubGap, OuterRadius + PopOut + SubGap + SubBand);+ /// <summary>How far past an open ring (and the gap before it) the pointer still counts as on its way to it.</summary>+ private const double BackdropMargin = 8;++ /// <summary>True when <paramref name="p"/> is in the direction of <paramref name="group"/>'s ring, at any distance.</summary>+ private bool InFan(Point p, int group)+ {+ var count = group >= 0 && group < Count ? Items![group].Children?.Count ?? 0 : 0;+ return count > 0 && DonutGeometry.SubIndexAt(Center, p, 0, double.MaxValue, DonutGeometry.MidAngle(group, Count),+ count, SubSpanOf(count)) >= 0;+ }+/// <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);@@ -426,8 +439,9 @@ public sealed partial class DonutMenu : Control/// <summary>/// Fans a group out once the pointer means it: after resting on its slice for <see cref="ExpandDelay"/>, or at once- /// when it moves outward on it (<paramref name="at"/>, when known). Keeps it open while the pointer is on its ring or- /// crossing the gap to it; another slice or the hole folds it away.+ /// when it moves outward on it (<paramref name="at"/>, when known), even straight past its edge. Keeps it open while+ /// the pointer is on its ring or crossing the gap to it; another slice, the hole or going round the outside away+ /// from the ring folds it away./// </summary>private void TrackGroups(DonutHit hit, Point? at){@@ -460,8 +474,14 @@ public sealed partial class DonutMenu : Controlcase DonutHitKind.SubSegment:sub = hit.Sub;break;+ case DonutHitKind.Outside when _pendingGroup >= 0 && at is { } flick && InFan(flick, _pendingGroup) &&+ Distance(flick, Center) <= SubRadii.Outer + BackdropMargin:+ ExpandPendingGroup(); // flicked straight out to where its ring opens: no need to wait+ break;case DonutHitKind.Outside:_pendingGroup = -1; // left the slice before it opened: it stays closed+ if (_expanded >= 0 && at is { } q && !InFan(q, _expanded))+ _expanded = -1; // went round the outside, away from the ringbreak;default:_expanded = _pendingGroup = -1;@@ -1022,6 +1042,9 @@ public sealed partial class DonutMenu : Controlif (IsEditMode && _previewSpan.Value > 0.01)DrawPreview(context, center, r1, r2, typeface, typefaceRegular);+ var reaching = _expanded >= 0 ? _expanded : _pendingGroup;+ if (!IsEditMode && reaching >= 0 && reaching < n && Items![reaching].Children is { Count: > 0 } reachable)+ DrawHitBackdrop(context, center, reaching, reachable.Count);if (!IsEditMode && _shownExpanded >= 0 && _shownExpanded < n && _expand.Value > 0.01)DrawSubRing(context, center, typeface, typefaceRegular);@@ -1032,18 +1055,26 @@ public sealed partial class DonutMenu : Control}/// <summary>- /// Nearly transparent fill (alpha 1/255) under an open group's ring and the gap to it. Windows passes the mouse- /// and drags through fully transparent pixels of a layered window, so without it the pointer "leaves" the donut- /// in the gap and the ring folds away before it is reached.+ /// Nearly transparent fill (alpha 1/255) under a group's ring and the gap to it, while it is open or about to+ /// open. Windows passes the mouse and drags through fully transparent pixels of a layered window, so without it the+ /// pointer "leaves" the donut in the gap and the ring folds away (or never opens) before it is reached./// </summary>private 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.+ /// </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.DrawGeometry(HitBackdrop, null, CreateWedge(center, OuterRadius, reach, DonutGeometry.MidAngle(group, Count), span));+ }+/// <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){- var reach = SubRadii.Outer + 8;- context.DrawEllipse(HitBackdrop, null, center, reach, reach);-var group = _shownExpanded;var children = Items![group].Children!;var parentMid = DonutGeometry.MidAngle(group, Count);diff --git a/tests/Filee.App.Tests/DonutGroupTests.cs b/tests/Filee.App.Tests/DonutGroupTests.csindex a259fb20..998eeace 100644--- a/tests/Filee.App.Tests/DonutGroupTests.cs+++ b/tests/Filee.App.Tests/DonutGroupTests.cs@@ -78,6 +78,50 @@ public class DonutGroupTestswindow.Close();}+ [AvaloniaFact]+ public void A_quick_flick_out_to_where_the_ring_opens_opens_it()+ {+ var (donut, window) = Open();+ var mid = DonutGeometry.MidAngle(Group, 4) + 0.1;+ var rim = DonutGeometry.PointAt(Center(donut), donut.OuterRadius - 4, mid); // came in near the rim+ donut.SetExternalHit(donut.HitTest(rim), rim);+ var out_ = DonutGeometry.PointAt(Center(donut), donut.OuterRadius + 30, mid); // next event: already out there+ Assert.Equal(DonutHitKind.Outside, donut.HitTest(out_).Kind);+ donut.SetExternalHit(donut.HitTest(out_), out_);+ Assert.True(IsOpen(donut)); // no waiting for the delay, and not cancelled either++ // Out in another direction instead: that is leaving, it stays closed.+ donut.CollapseGroup();+ donut.SetExternalHit(donut.HitTest(rim), rim);+ var away = DonutGeometry.PointAt(Center(donut), donut.OuterRadius + 30, mid + Math.PI);+ donut.SetExternalHit(donut.HitTest(away), away);+ donut.ExpandPendingGroup();+ Assert.False(IsOpen(donut));+ window.Close();+ }++ [AvaloniaFact]+ public void An_open_ring_holds_across_the_gap_and_folds_when_the_pointer_goes_round_elsewhere()+ {+ var (donut, window) = Open();+ var inner = OnGroup(donut, donut.OuterRadius * 0.6);+ donut.SetExternalHit(donut.HitTest(inner), inner);+ donut.ExpandPendingGroup();++ // The gap between the popped-out slice and the ring still belongs to the group: no flicker on the way.+ var gap = OnGroup(donut, donut.OuterRadius + 7 + 3);+ Assert.Equal(new DonutHit(DonutHitKind.Segment, Group), donut.HitTest(gap));+ donut.SetExternalHit(donut.HitTest(gap), gap);+ Assert.True(IsOpen(donut));+ Assert.Equal(Group, donut.ActiveIndex);++ // Round the outside to the far side of the donut: away from the ring, which folds.+ var far = DonutGeometry.PointAt(Center(donut), donut.OuterRadius + 20, DonutGeometry.MidAngle(0, 4));+ donut.SetExternalHit(donut.HitTest(far), far);+ Assert.False(IsOpen(donut));+ window.Close();+ }+[AvaloniaFact]public void A_donut_of_just_a_group_fans_out_slices_that_dont_overlap(){