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: a ring opened with Enter waits for the mouse to come from the hole

SeoJCaliveafe1aa3e7d44
diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.cs
index 31259ef4..f1ad7a50 100644
--- a/src/Filee.App/Controls/DonutMenu.cs
+++ b/src/Filee.App/Controls/DonutMenu.cs
@@ -153,6 +153,10 @@ public sealed partial class DonutMenu : Control
// Keyboard: set by a handled key until the mouse moves KeyboardJitter away from where it was then.
private bool _keyboardHold;
+
+ // A ring opened with Enter: the mouse, resting in the hole as the donut opened at the cursor, crosses the hole on
+ // its way to it. Until it reaches the group (its slice or ring) the hole doesn't fold it.
+ private bool _ringFromKeys;
private Point? _keyAnchor;
private Point? _lastPointer;
private const double KeyboardJitter = 6;
@@ -466,6 +470,7 @@ public sealed partial class DonutMenu : Control
switch (hit.Kind)
{
case DonutHitKind.Segment when hit.Index == _expanded:
+ _ringFromKeys = false; // the mouse reached it: from here on it leads
break;
case DonutHitKind.Segment when hit.Index >= 0 && hit.Index < Count && Items![hit.Index].CanExpand:
_expanded = -1;
@@ -487,6 +492,7 @@ public sealed partial class DonutMenu : Control
}
break;
case DonutHitKind.SubSegment:
+ _ringFromKeys = false;
sub = hit.Sub;
break;
case DonutHitKind.Outside when _pendingGroup >= 0 && at is { } flick && InFan(flick, _pendingGroup) &&
@@ -498,8 +504,12 @@ public sealed partial class DonutMenu : Control
if (_expanded >= 0 && at is { } q && !InFan(q, _expanded))
_expanded = -1; // went round the outside, away from the ring
break;
+ case DonutHitKind.Center when _ringFromKeys:
+ sub = _subHover; // on its way out of the hole to the ring
+ break;
default:
_expanded = -1;
+ _ringFromKeys = false;
ClearPending();
break;
}
@@ -526,6 +536,7 @@ public sealed partial class DonutMenu : Control
private void Expand(int group)
{
+ _ringFromKeys = false;
// Another group's ring still folding away: this one grows out of its own slice, not from half open.
if (_shownExpanded != group)
_expand = default;
@@ -603,6 +614,7 @@ public sealed partial class DonutMenu : Control
{
Expand(current);
SetSub(0);
+ _ringFromKeys = true;
}
else if (Items[current].IsEnabled)
{
@@ -633,6 +645,7 @@ public sealed partial class DonutMenu : Control
public void CollapseGroup()
{
_expanded = -1;
+ _ringFromKeys = false;
ClearPending();
SetSub(-1);
StartAnimation();
@@ -668,7 +681,7 @@ public sealed partial class DonutMenu : Control
ClearPending();
_expand = default;
// The window is reused: a keyboard hold from the last time it was open must not swallow the first moves now.
- _keyboardHold = false;
+ _keyboardHold = _ringFromKeys = false;
_keyAnchor = _lastPointer = null;
InvalidateMeasure();
InvalidateVisual();
diff --git a/tests/Filee.App.Tests/DonutGroupTests.cs b/tests/Filee.App.Tests/DonutGroupTests.cs
index 05816e7e..3f3c7f1b 100644
--- a/tests/Filee.App.Tests/DonutGroupTests.cs
+++ b/tests/Filee.App.Tests/DonutGroupTests.cs
@@ -382,6 +382,33 @@ public class DonutGroupTests
window.Close();
}
+ [AvaloniaFact]
+ public void A_ring_the_keyboard_opened_stays_while_the_mouse_comes_from_the_hole_to_click_it()
+ {
+ var (donut, window) = Open();
+ var c = Center(donut);
+ window.MouseMove(c); // opened at the cursor: it rests in the hole
+ donut.HandleKey(Key.Right);
+ donut.HandleKey(Key.Right);
+ donut.HandleKey(Key.Right); // to the group
+ donut.HandleKey(Key.Enter); // its ring opens
+ Assert.True(IsOpen(donut));
+
+ // The mouse heads for the ring: out of the hole, across the group's slice, to a ring slice.
+ foreach (var radius in new[] { 15.0, donut.OuterRadius * 0.3, donut.OuterRadius * 0.7 })
+ {
+ window.MouseMove(OnGroup(donut, radius));
+ Assert.True(IsOpen(donut), $"folded at {radius:0}");
+ }
+ window.MouseMove(OnRing(donut, 2));
+ Assert.Equal(2, donut.ActiveSubIndex);
+
+ // From here the mouse leads as usual: back in the hole the ring folds.
+ window.MouseMove(new Point(c.X + 10, c.Y));
+ Assert.False(IsOpen(donut));
+ window.Close();
+ }
+
[AvaloniaFact]
public void With_animations_off_a_group_opens_at_once()
{