Skip to content

armgit / Filee

Public Imported from GitHub
0

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.

Donut groups: leaving the donut or closing it folds a group

KnifeLemon31baed290d69
diff --git a/src/Filee.App/Controls/DonutMenu.Groups.cs b/src/Filee.App/Controls/DonutMenu.Groups.cs
index 3c69cc2d..1638c9a1 100644
--- a/src/Filee.App/Controls/DonutMenu.Groups.cs
+++ b/src/Filee.App/Controls/DonutMenu.Groups.cs
@@ -341,16 +341,32 @@ public sealed partial class DonutMenu
}
/// <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.
+ /// How far inside the edge of the donut and the ring's backdrop the pointer must last have been for a "leave" to be
+ /// a see-through seam: one seen closer to the edge than this went out over it.
+ /// </summary>
+ private const double LeaveEdge = 12;
+
+ /// <summary>
+ /// True when the pointer "left" at <paramref name="p"/>, well inside the donut or the backdrop of the group that is
+ /// open or about to open (<see cref="DrawHitBackdrop"/>): a see-through pixel let it through there (Windows and
+ /// macOS do that), it didn't really leave. Last seen near the edge of that area, or outside it, it did.
/// </summary>
internal bool LeftThroughSeam(Point p)
{
var group = _expanded >= 0 ? _expanded : _pendingGroup;
- if (group < 0 || IsEditMode)
+ if (group < 0 || group >= Count || IsEditMode)
return false;
var distance = Distance(p, Center);
- return distance <= OuterRadius + PopOut || distance <= SubRadii.Outer + BackdropMargin && InFan(p, group);
+ if (distance <= OuterRadius + PopOut - LeaveEdge)
+ return true;
+ var count = Items![group].Children?.Count ?? 0;
+ var reach = SubRadii.Outer + BackdropMargin;
+ if (count == 0 || distance > reach - LeaveEdge)
+ return false;
+ // Inside the backdrop's wedge, and LeaveEdge away from its sides.
+ var halfSpan = Math.Min(2 * Math.PI, SubSpanOf(count) * count + 2 * BackdropMargin / reach) / 2;
+ var inside = halfSpan - Math.Abs(Math.IEEERemainder(DonutGeometry.AngleOf(Center, p) - DonutGeometry.MidAngle(group, Count), 2 * Math.PI));
+ return inside > 0 && (inside >= Math.PI / 2 || distance * Math.Sin(inside) >= LeaveEdge);
}
/// <summary>The ring an open group fans out, growing out of its slice.</summary>
diff --git a/src/Filee.App/Services/RadialController.cs b/src/Filee.App/Services/RadialController.cs
index e6acc59e..202d9bc4 100644
--- a/src/Filee.App/Services/RadialController.cs
+++ b/src/Filee.App/Services/RadialController.cs
@@ -134,6 +134,8 @@ public sealed class RadialController(
}
_visible = false;
var window = _window;
+ // A group about to open (its dwell timer running) must not open on a closing donut.
+ window.DonutControl.CollapseGroup();
if (animate)
window.DonutControl.PlayCloseAnimation(() =>
{
@@ -284,6 +286,7 @@ public sealed class RadialController(
private void HideWindow()
{
_visible = false;
+ _window?.DonutControl.CollapseGroup();
_window?.Hide();
}
diff --git a/src/Filee.App/Views/RadialWindow.axaml.cs b/src/Filee.App/Views/RadialWindow.axaml.cs
index 245d0939..cf7b0407 100644
--- a/src/Filee.App/Views/RadialWindow.axaml.cs
+++ b/src/Filee.App/Views/RadialWindow.axaml.cs
@@ -106,6 +106,14 @@ public partial class RadialWindow : Window
public event Action? EscapePressed;
+ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
+ {
+ base.OnPropertyChanged(change);
+ // Hidden, however that happened: a group waiting to open doesn't open on the hidden donut.
+ if (change.Property == IsVisibleProperty && !change.GetNewValue<bool>())
+ Donut.CollapseGroup();
+ }
+
/// <summary>Local file paths in the drag data (folders and virtual items are ignored).</summary>
private static IReadOnlyList<string> LocalFiles(DragEventArgs e) =>
(e.DataTransfer.TryGetFiles() ?? [])
diff --git a/tests/Filee.App.Tests/DonutGroupTests.cs b/tests/Filee.App.Tests/DonutGroupTests.cs
index d0189f77..30c94a52 100644
--- a/tests/Filee.App.Tests/DonutGroupTests.cs
+++ b/tests/Filee.App.Tests/DonutGroupTests.cs
@@ -140,6 +140,9 @@ public class DonutGroupTests
donut.SetExternalHit(donut.HitTest(inner), inner);
donut.ExpandPendingGroup();
+ // The mouse comes onto the ring first: right after another test's click, a headless press with no move before it
+ // can miss the donut.
+ window.MouseMove(OnRing(donut, 2));
window.MouseDown(OnRing(donut, 2), MouseButton.Right);
window.MouseUp(OnRing(donut, 2), MouseButton.Right);
Assert.Equal([(Group, 2)], edits);
@@ -244,6 +247,7 @@ public class DonutGroupTests
var invoked = new List<int>();
donut.SegmentInvoked += (_, index) => invoked.Add(index);
var inner = OnGroup(donut, donut.OuterRadius * 0.6);
+ window.MouseMove(inner);
window.MouseDown(inner, MouseButton.Left);
window.MouseUp(inner, MouseButton.Left);
Assert.True(IsOpen(donut));
@@ -285,6 +289,74 @@ public class DonutGroupTests
window.Close();
}
+ [AvaloniaFact]
+ public void Leaving_the_window_past_the_ring_or_over_its_edge_folds_it()
+ {
+ TestServices.EnsureInitialized("en");
+ var donut = new DonutMenu { Items = [Item("PNG"), Item("JPG"), GroupOf(Item("WEBP"), Item("PDF"), Item("TIFF")), Item("BMP")] };
+ var window = new Window { Content = new Border { Padding = new Thickness(40), Child = donut }, SizeToContent = SizeToContent.WidthAndHeight };
+ window.Show();
+ Dispatcher.UIThread.RunJobs();
+ var origin = donut.TranslatePoint(new Point(0, 0), window)!.Value;
+ Point InWindow(Point p) => new(p.X + origin.X, p.Y + origin.Y);
+
+ // The mouse opens the ring, goes onto it and on out of the donut.
+ var inner = OnGroup(donut, donut.OuterRadius * 0.6);
+ window.MouseMove(InWindow(inner));
+ window.MouseDown(InWindow(inner), MouseButton.Left);
+ window.MouseUp(InWindow(inner), MouseButton.Left);
+ window.MouseMove(InWindow(OnRing(donut, 1)));
+ Assert.True(IsOpen(donut));
+ window.MouseMove(new Point(2, 2));
+ Assert.False(IsOpen(donut));
+
+ // A drag last seen on the ring's outer rim went out over it: not a see-through seam.
+ donut.SetExternalHit(donut.HitTest(inner), inner);
+ donut.ExpandPendingGroup();
+ Assert.True(IsOpen(donut));
+ var middle = OnRing(donut, 1);
+ var c = Center(donut);
+ var along = Math.Sqrt(Math.Pow(middle.X - c.X, 2) + Math.Pow(middle.Y - c.Y, 2));
+ var rim = new Point(c.X + (middle.X - c.X) * (along + 21) / along, c.Y + (middle.Y - c.Y) * (along + 21) / along);
+ donut.ExternalDragLeft(rim);
+ Assert.False(IsOpen(donut));
+ Assert.Equal(-1, donut.ActiveIndex);
+ window.Close();
+ }
+
+ [AvaloniaFact]
+ public void A_group_about_to_open_stays_closed_once_the_donut_closed()
+ {
+ TestServices.EnsureInitialized("en");
+ var store = AppHost.Get<UserDataStore>();
+ var images = store.Profiles.Single(p => p.Id == "images");
+ var before = images.PresetIds.ToList();
+ var group = new Preset { Id = "test-close-group", Name = "Formats", Kind = PresetKind.Group, SubPresetIds = ["to-png", "to-jpg"] };
+ var radial = AppHost.Get<RadialController>();
+ try
+ {
+ store.Presets.Add(group);
+ images.PresetIds.Insert(0, group.Id);
+ radial.ShowForFiles(400, 400, ["/photos/a.jpg"]);
+ Dispatcher.UIThread.RunJobs();
+ var donut = radial.Window!.DonutControl;
+ var onGroup = DonutGeometry.PointAt(Center(donut), donut.OuterRadius * 0.6, DonutGeometry.MidAngle(0, donut.Items!.Count));
+ donut.SetExternalHit(donut.HitTest(onGroup), onGroup); // resting on it: the dwell timer runs
+
+ radial.Close(animate: false); // Esc, or a click elsewhere
+ donut.ExpandPendingGroup(); // what the timer would do, had it outlived the donut
+ Assert.Equal(-1, donut.ActiveSubIndex);
+ Assert.NotEqual(DonutHitKind.SubSegment, donut.HitTest(donut.SubSliceCenter(0, 1)).Kind);
+ }
+ finally
+ {
+ radial.Close(animate: false);
+ images.PresetIds.Clear();
+ images.PresetIds.AddRange(before);
+ store.Presets.Remove(group);
+ }
+ }
+
[AvaloniaFact]
public void Only_enabled_slices_take_a_drop_and_an_empty_group_opens_nothing()
{