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.

The donut's slices follow the theme's softness

KnifeLemonf0f877a6489f
diff --git a/src/Filee.App/Controls/DonutGeometry.cs b/src/Filee.App/Controls/DonutGeometry.cs
index 58de8a75..d1317a4d 100644
--- a/src/Filee.App/Controls/DonutGeometry.cs
+++ b/src/Filee.App/Controls/DonutGeometry.cs
@@ -32,6 +32,15 @@ public enum DonutHitKind
/// <param name="Sub">With <see cref="DonutHitKind.SubSegment"/>: which of the group's presets.</param>
public readonly record struct DonutHit(DonutHitKind Kind, int Index = -1, int Sub = -1);
+/// <summary>One step of a slice's outline: a straight line to <paramref name="To"/>, or (<paramref name="ArcRadius"/> &gt; 0) an arc.</summary>
+public readonly record struct OutlineStep(Point To, double ArcRadius = 0, bool IsLargeArc = false, bool Clockwise = true)
+{
+ public bool IsArc => ArcRadius > 0;
+}
+
+/// <summary>A closed slice outline, starting at <paramref name="Start"/>; <paramref name="CornerRadius"/> is the rounding used after clamping.</summary>
+public sealed record WedgeOutline(Point Start, IReadOnlyList<OutlineStep> Steps, double CornerRadius);
+
/// <summary>Geometry helpers.</summary>
public static class DonutGeometry
{
@@ -115,4 +124,121 @@ public static class DonutGeometry
return new DonutHit(DonutHitKind.EmptyRing);
return new DonutHit(DonutHitKind.Segment, IndexAt(AngleOf(center, p), count));
}
+
+ /// <summary>Rounding below this (in pixels) is not visible: the slice stays sharp.</summary>
+ public const double MinCornerRadius = 0.25;
+
+ /// <summary>
+ /// Outline of a slice of <paramref name="span"/> radians centred on <paramref name="mid"/>, between
+ /// <paramref name="innerRadius"/> and <paramref name="outerRadius"/>, with a constant <paramref name="gap"/> to its
+ /// neighbours. <paramref name="cornerRadius"/> rounds its four corners (the theme's softness); it shrinks to what fits
+ /// a thin or short slice, and 0 gives the sharp slice. The rounding only cuts into the corners, so the slice stays
+ /// inside its sharp shape and the gap between slices stays the same. Hit testing keeps the sharp sector: a corner cut
+ /// away still belongs to the slice whose angle it is in.
+ /// </summary>
+ public static WedgeOutline Wedge(Point center, double innerRadius, double outerRadius, double mid, double span, double gap,
+ double cornerRadius = 0)
+ {
+ var outerHalf = Math.Max(0.001, span / 2 - gap / 2 / outerRadius);
+ var innerHalf = Math.Max(0.001, span / 2 - gap / 2 / innerRadius);
+ var outerStart = PointAt(center, outerRadius, mid - outerHalf);
+ var innerStart = PointAt(center, innerRadius, mid - innerHalf);
+
+ var radius = Math.Min(cornerRadius, (outerRadius - innerRadius) / 2);
+ if (radius > MinCornerRadius)
+ {
+ if (Rounded(center, innerRadius, outerRadius, mid, outerHalf, innerHalf, radius) is { } rounded)
+ return rounded;
+ // Too thin or short for it: the largest rounding that fits, found by halving, so a slice growing in (the
+ // edit preview) rounds smoothly instead of in steps.
+ WedgeOutline? best = null;
+ double low = 0, high = radius;
+ for (var step = 0; step < 14; step++)
+ {
+ var r = (low + high) / 2;
+ if (Rounded(center, innerRadius, outerRadius, mid, outerHalf, innerHalf, r) is { } fits)
+ (best, low) = (fits, r);
+ else
+ high = r;
+ }
+ if (best is not null && low > MinCornerRadius)
+ return best;
+ }
+
+ return new WedgeOutline(outerStart,
+ [
+ new OutlineStep(PointAt(center, outerRadius, mid + outerHalf), outerRadius, outerHalf * 2 > Math.PI, Clockwise: true),
+ new OutlineStep(PointAt(center, innerRadius, mid + innerHalf)),
+ new OutlineStep(innerStart, innerRadius, innerHalf * 2 > Math.PI, Clockwise: false),
+ ], 0);
+ }
+
+ /// <summary>The slice with corners of <paramref name="radius"/>, or null when they don't fit.</summary>
+ private static WedgeOutline? Rounded(Point center, double r1, double r2, double mid, double outerHalf, double innerHalf, double radius)
+ {
+ // The slice is symmetric about its middle: work out the corners on its start side and mirror them.
+ var outerSide = PointAt(center, r2, mid - outerHalf);
+ var innerSide = PointAt(center, r1, mid - innerHalf);
+ if (Corner(center, outerSide, innerSide, r2, radius, outer: true) is not { } o ||
+ Corner(center, outerSide, innerSide, r1, radius, outer: false) is not { } i)
+ return null;
+ // The two corners on a side must not overlap, nor reach past the middle into the other side's.
+ if (o.Along >= i.Along || Offset(center, o.Center, mid) >= 0 || Offset(center, i.Center, mid) >= 0)
+ return null;
+
+ Point Mirror(Point p) => PointAt(center, Distance(center, p), 2 * mid - AngleOf(center, p));
+ var outerArc = -Offset(center, o.Center, mid);
+ var innerArc = -Offset(center, i.Center, mid);
+ return new WedgeOutline(o.OnArc,
+ [
+ new OutlineStep(Mirror(o.OnArc), r2, outerArc > Math.PI / 2, Clockwise: true),
+ new OutlineStep(Mirror(o.OnLine), radius),
+ new OutlineStep(Mirror(i.OnLine)),
+ new OutlineStep(Mirror(i.OnArc), radius),
+ new OutlineStep(i.OnArc, r1, innerArc > Math.PI / 2, Clockwise: false),
+ new OutlineStep(i.OnLine, radius),
+ new OutlineStep(o.OnLine),
+ new OutlineStep(o.OnArc, radius),
+ ], radius);
+ }
+
+ /// <summary>
+ /// The rounded corner where the slice's start side (the line from <paramref name="outerSide"/> to
+ /// <paramref name="innerSide"/>) meets the circle of <paramref name="circle"/>: the centre of its arc, where it touches
+ /// the circle and the side, and how far along the side (from <paramref name="outerSide"/>) it touches it.
+ /// </summary>
+ private static (Point Center, Point OnArc, Point OnLine, double Along)? Corner(Point center, Point outerSide, Point innerSide,
+ double circle, double radius, bool outer)
+ {
+ var length = Distance(outerSide, innerSide);
+ if (length <= 0)
+ return null;
+ var u = new Vector((innerSide.X - outerSide.X) / length, (innerSide.Y - outerSide.Y) / length);
+ // Into the slice: the start side's normal on the clockwise (increasing angle) side.
+ var tangent = new Vector(Math.Cos(AngleOf(center, outerSide)), Math.Sin(AngleOf(center, outerSide)));
+ var n = new Vector(-u.Y, u.X);
+ if (n.X * tangent.X + n.Y * tangent.Y < 0)
+ n = -n;
+
+ // The arc's centre lies `radius` inside the side, and touches the circle: inside it for the outer edge, outside
+ // the hole for the inner one. The nearer of the two crossings is on this side of the middle.
+ var distance = outer ? circle - radius : circle + radius;
+ var w = outerSide + n * radius - center;
+ var b = w.X * u.X + w.Y * u.Y;
+ var disc = b * b - (w.X * w.X + w.Y * w.Y - distance * distance);
+ if (disc < 0)
+ return null;
+ var t = -b - Math.Sqrt(disc);
+ if (t < 0 || t > length)
+ return null;
+ var c = outerSide + n * radius + u * t;
+ var toCenter = new Vector(c.X - center.X, c.Y - center.Y);
+ var onArc = center + toCenter / toCenter.Length * circle;
+ return (c, onArc, outerSide + u * t, t);
+ }
+
+ /// <summary>Signed angle of <paramref name="p"/> from <paramref name="mid"/>, -π..π (negative before it).</summary>
+ private static double Offset(Point center, Point p, double mid) => Math.IEEERemainder(AngleOf(center, p) - mid, 2 * Math.PI);
+
+ private static double Distance(Point a, Point b) => Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2));
}
diff --git a/src/Filee.App/Controls/DonutMenu.Groups.cs b/src/Filee.App/Controls/DonutMenu.Groups.cs
index 1638c9a1..baec5c09 100644
--- a/src/Filee.App/Controls/DonutMenu.Groups.cs
+++ b/src/Filee.App/Controls/DonutMenu.Groups.cs
@@ -337,7 +337,7 @@ public sealed partial class DonutMenu
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));
+ context.DrawGeometry(HitBackdrop, null, CreateWedge(center, OuterRadius, reach, DonutGeometry.MidAngle(group, Count), span, 0));
}
/// <summary>
diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.cs
index 2929cb38..29ef8627 100644
--- a/src/Filee.App/Controls/DonutMenu.cs
+++ b/src/Filee.App/Controls/DonutMenu.cs
@@ -68,6 +68,10 @@ public sealed partial class DonutMenu : Control
public static readonly StyledProperty<bool> ReserveSubRingProperty =
AvaloniaProperty.Register<DonutMenu, bool>(nameof(ReserveSubRing));
+ /// <summary>The theme's softness (Styles/Soft.axaml binds SoftRadius): rounds the corners of the slices.</summary>
+ public static readonly StyledProperty<CornerRadius> CornerRadiusProperty =
+ AvaloniaProperty.Register<DonutMenu, CornerRadius>(nameof(CornerRadius));
+
public static readonly StyledProperty<IBrush?> SliceBrushProperty =
AvaloniaProperty.Register<DonutMenu, IBrush?>(nameof(SliceBrush), Brushes.White);
public static readonly StyledProperty<IBrush?> SliceBorderBrushProperty =
@@ -127,7 +131,7 @@ public sealed partial class DonutMenu : Control
AffectsMeasure<DonutMenu>(OuterRadiusProperty, ReserveSubRingProperty);
AffectsRender<DonutMenu>(HoleRatioProperty, SliceOpacityProperty, CenterTitleProperty, CenterSubtitleProperty,
IsEditModeProperty, SliceBrushProperty, SliceBorderBrushProperty, CenterBrushProperty, AccentBrushProperty,
- OnAccentBrushProperty, ForegroundProperty, SecondaryForegroundProperty, SuccessBrushProperty);
+ OnAccentBrushProperty, ForegroundProperty, SecondaryForegroundProperty, SuccessBrushProperty, CornerRadiusProperty);
ItemsProperty.Changed.AddClassHandler<DonutMenu>((d, _) => d.OnItemsChanged());
}
@@ -156,6 +160,8 @@ public sealed partial class DonutMenu : Control
/// </summary>
public bool ReserveSubRing { get => GetValue(ReserveSubRingProperty); set => SetValue(ReserveSubRingProperty, value); }
+ public CornerRadius CornerRadius { get => GetValue(CornerRadiusProperty); set => SetValue(CornerRadiusProperty, value); }
+
public IBrush? SliceBrush { get => GetValue(SliceBrushProperty); set => SetValue(SliceBrushProperty, value); }
public IBrush? SliceBorderBrush { get => GetValue(SliceBorderBrushProperty); set => SetValue(SliceBorderBrushProperty, value); }
public IBrush? CenterBrush { get => GetValue(CenterBrushProperty); set => SetValue(CenterBrushProperty, value); }
@@ -966,7 +972,6 @@ public sealed partial class DonutMenu : Control
private static double Distance(Point a, Point b) => Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2));
- /// <summary>Wedge-shaped slice with a constant-width gap to its neighbours.</summary>
/// <summary>The translucent slice where a dragged preset would land, with its name.</summary>
private void DrawPreview(DrawingContext context, Point center, double r1, double r2, Typeface bold, Typeface regular)
{
@@ -982,24 +987,53 @@ public sealed partial class DonutMenu : Control
span * (r1 + r2) / 2 - 10, r2 - r1 - 16, bold, regular, hot: false);
}
- private static StreamGeometry CreateWedge(Point c, double r1, double r2, int index, int count) =>
+ /// <summary>
+ /// How round the slices' corners are: half the theme's softness (0 to 28), so the largest setting still leaves the
+ /// slices clearly apart. <see cref="DonutGeometry.Wedge"/> shrinks it for slices too thin for it.
+ /// </summary>
+ internal double SliceCornerRadius => Math.Clamp(CornerRadius.TopLeft, 0, 28) * 0.5;
+
+ private StreamGeometry CreateWedge(Point c, double r1, double r2, int index, int count) =>
count == 1 ? CreateRing(c, r1, r2) : CreateWedge(c, r1, r2, DonutGeometry.MidAngle(index, count), DonutGeometry.Span(count));
- /// <summary>A slice of <paramref name="span"/> radians centred on <paramref name="mid"/> (a ring when it is all of it).</summary>
- private static StreamGeometry CreateWedge(Point c, double r1, double r2, double mid, double span)
+ /// <summary>A rounded slice of <paramref name="span"/> radians centred on <paramref name="mid"/> (a ring when it is all of it).</summary>
+ private StreamGeometry CreateWedge(Point c, double r1, double r2, double mid, double span) =>
+ CreateWedge(c, r1, r2, mid, span, SliceCornerRadius);
+
+ // Slices are drawn every frame while the donut animates, but their shapes only change with the size, the layout
+ // or the softness: the shapes are kept and reused. Animations move them with transforms; only the edit mode's
+ // sliding slices make new ones, and the cache starts over when it fills up.
+ private readonly Dictionary<(Point C, double R1, double R2, double Mid, double Span, double Corner), StreamGeometry> _wedges = new();
+ private const int MaxCachedWedges = 256;
+
+ private StreamGeometry CreateWedge(Point c, double r1, double r2, double mid, double span, double cornerRadius)
+ {
+ var key = (c, r1, r2, mid, span, cornerRadius);
+ if (_wedges.TryGetValue(key, out var cached))
+ return cached;
+ if (_wedges.Count >= MaxCachedWedges)
+ _wedges.Clear();
+ return _wedges[key] = BuildWedge(c, r1, r2, mid, span, cornerRadius);
+ }
+
+ /// <summary>A slice with a constant-width gap to its neighbours and corners rounded by <paramref name="cornerRadius"/>.</summary>
+ private static StreamGeometry BuildWedge(Point c, double r1, double r2, double mid, double span, double cornerRadius)
{
if (span >= 2 * Math.PI - 0.001)
return CreateRing(c, r1, r2);
- var outerHalf = Math.Max(0.001, span / 2 - GapPixels / 2 / r2);
- var innerHalf = Math.Max(0.001, span / 2 - GapPixels / 2 / r1);
-
+ var outline = DonutGeometry.Wedge(c, r1, r2, mid, span, GapPixels, cornerRadius);
var geometry = new StreamGeometry();
using var ctx = geometry.Open();
- ctx.BeginFigure(DonutGeometry.PointAt(c, r2, mid - outerHalf), true);
- ctx.ArcTo(DonutGeometry.PointAt(c, r2, mid + outerHalf), new Size(r2, r2), 0, outerHalf * 2 > Math.PI, SweepDirection.Clockwise);
- ctx.LineTo(DonutGeometry.PointAt(c, r1, mid + innerHalf));
- ctx.ArcTo(DonutGeometry.PointAt(c, r1, mid - innerHalf), new Size(r1, r1), 0, innerHalf * 2 > Math.PI, SweepDirection.CounterClockwise);
+ ctx.BeginFigure(outline.Start, true);
+ foreach (var step in outline.Steps)
+ {
+ if (step.IsArc)
+ ctx.ArcTo(step.To, new Size(step.ArcRadius, step.ArcRadius), 0, step.IsLargeArc,
+ step.Clockwise ? SweepDirection.Clockwise : SweepDirection.CounterClockwise);
+ else
+ ctx.LineTo(step.To);
+ }
ctx.EndFigure(true);
return geometry;
}
diff --git a/src/Filee.App/Styles/Soft.axaml b/src/Filee.App/Styles/Soft.axaml
index e1f8e23d..d70cebf2 100644
--- a/src/Filee.App/Styles/Soft.axaml
+++ b/src/Filee.App/Styles/Soft.axaml
@@ -209,6 +209,7 @@
<Style Selector="c|DonutMenu">
<Setter Property="SliceBrush" Value="{DynamicResource SurfaceBrush}" />
<Setter Property="SliceBorderBrush" Value="{DynamicResource SubtleBorderBrush}" />
+ <Setter Property="CornerRadius" Value="{DynamicResource SoftRadius}" />
<Setter Property="CenterBrush" Value="{DynamicResource SurfaceBrush}" />
<Setter Property="AccentBrush" Value="{DynamicResource AccentBrush}" />
<Setter Property="OnAccentBrush" Value="{DynamicResource OnAccentBrush}" />
diff --git a/tests/Filee.App.Tests/DonutGeometryTests.cs b/tests/Filee.App.Tests/DonutGeometryTests.cs
index ce52a0a9..73b7166c 100644
--- a/tests/Filee.App.Tests/DonutGeometryTests.cs
+++ b/tests/Filee.App.Tests/DonutGeometryTests.cs
@@ -73,4 +73,119 @@ public class DonutGeometryTests
Assert.Equal(DonutHitKind.Segment, DonutGeometry.HitTest(C, new Point(200, 45), 60, 150, 6, slack: 8).Kind);
Assert.Equal(DonutHitKind.EmptyRing, DonutGeometry.HitTest(C, new Point(200, 100), 60, 150, 0).Kind);
}
+
+ [Theory]
+ [InlineData(2)]
+ [InlineData(6)]
+ [InlineData(12)]
+ public void A_sharp_slice_keeps_the_outline_it_always_had(int count)
+ {
+ var mid = DonutGeometry.MidAngle(1, count);
+ var span = DonutGeometry.Span(count);
+ var outline = DonutGeometry.Wedge(C, 63, 150, mid, span, 3, cornerRadius: 0);
+
+ // Outer arc clockwise, side, inner arc back: exactly the slice drawn before the softness reached the donut.
+ var outerHalf = span / 2 - 1.5 / 150;
+ var innerHalf = span / 2 - 1.5 / 63;
+ AssertNear(DonutGeometry.PointAt(C, 150, mid - outerHalf), outline.Start);
+ Assert.Equal(3, outline.Steps.Count);
+ AssertStep(new OutlineStep(DonutGeometry.PointAt(C, 150, mid + outerHalf), 150, outerHalf * 2 > Math.PI, true), outline.Steps[0]);
+ AssertStep(new OutlineStep(DonutGeometry.PointAt(C, 63, mid + innerHalf)), outline.Steps[1]);
+ AssertStep(new OutlineStep(DonutGeometry.PointAt(C, 63, mid - innerHalf), 63, innerHalf * 2 > Math.PI, false), outline.Steps[2]);
+ Assert.Equal(0, outline.CornerRadius);
+ }
+
+ [Theory]
+ [InlineData(2, 14)]
+ [InlineData(6, 14)]
+ [InlineData(10, 14)]
+ [InlineData(12, 7)]
+ public void A_rounded_slice_stays_inside_its_sharp_shape(int count, double corner)
+ {
+ const double inner = 63, outer = 150, gap = 3;
+ var mid = DonutGeometry.MidAngle(2, count);
+ var span = DonutGeometry.Span(count);
+ var outline = DonutGeometry.Wedge(C, inner, outer, mid, span, gap, corner);
+
+ Assert.Equal(corner, outline.CornerRadius, 6);
+ Assert.Equal(8, outline.Steps.Count); // two arcs, two sides, four rounded corners
+ Assert.Equal(4, outline.Steps.Count(s => s.IsArc && s.ArcRadius == corner && s.Clockwise));
+
+ foreach (var p in OutlinePoints(outline))
+ {
+ var distance = Math.Sqrt(Math.Pow(p.X - C.X, 2) + Math.Pow(p.Y - C.Y, 2));
+ Assert.InRange(distance, inner - 1e-6, outer + 1e-6);
+ // Inside the sector, and no closer to its edge than half the gap: the gap between slices stays the same.
+ var offset = Math.IEEERemainder(DonutGeometry.AngleOf(C, p) - mid, 2 * Math.PI);
+ Assert.InRange(Math.Abs(offset), 0, span / 2);
+ Assert.True(distance * Math.Sin(span / 2 - Math.Abs(offset)) >= gap / 2 - 0.05, $"{p} is in the gap");
+ }
+
+ // The corners are cut: the sharp outline's first corner is no longer on it; the edges still run along the
+ // donut's circles.
+ var sharp = DonutGeometry.Wedge(C, inner, outer, mid, span, gap);
+ Assert.DoesNotContain(OutlinePoints(outline), p => Near(p, sharp.Start, 0.5));
+ Assert.Equal(outer, Math.Sqrt(Math.Pow(outline.Start.X - C.X, 2) + Math.Pow(outline.Start.Y - C.Y, 2)), 6);
+ Assert.Contains(outline.Steps, s => s.ArcRadius == outer && s.Clockwise);
+ Assert.Contains(outline.Steps, s => s.ArcRadius == inner && !s.Clockwise);
+ }
+
+ [Fact]
+ public void Thin_or_short_slices_get_only_the_rounding_that_fits()
+ {
+ // A crowded donut: at the hole a slice is narrower than two corners of 14.
+ var thin = DonutGeometry.Wedge(C, 40, 150, 0, DonutGeometry.Span(16), 3, 14);
+ Assert.InRange(thin.CornerRadius, 1, 14 - 0.01);
+ Assert.Equal(8, thin.Steps.Count);
+
+ // A thin band (a big hole): the corners are at most half its depth.
+ var shallow = DonutGeometry.Wedge(C, 135, 150, 0, DonutGeometry.Span(4), 3, 14);
+ Assert.InRange(shallow.CornerRadius, 1, 7.5);
+
+ // A slice that is barely there (the edit preview growing in): sharp, not a broken shape.
+ var sliver = DonutGeometry.Wedge(C, 63, 150, 0, 0.02, 3, 14);
+ Assert.Equal(0, sliver.CornerRadius);
+ Assert.Equal(3, sliver.Steps.Count);
+
+ // Larger slices get more of it, never more than asked.
+ var wider = DonutGeometry.Wedge(C, 40, 150, 0, DonutGeometry.Span(12), 3, 14);
+ Assert.True(wider.CornerRadius > thin.CornerRadius);
+ }
+
+ /// <summary>The outline's corners plus the middle of each rounded corner's arc.</summary>
+ private static List<Point> OutlinePoints(WedgeOutline outline)
+ {
+ var points = new List<Point> { outline.Start };
+ var from = outline.Start;
+ foreach (var step in outline.Steps)
+ {
+ if (step.IsArc && step.ArcRadius == outline.CornerRadius)
+ {
+ // Small clockwise arc: its middle is on the circle through both ends, on the right of the chord.
+ var chord = new Vector(step.To.X - from.X, step.To.Y - from.Y);
+ var half = chord.Length / 2;
+ var normal = new Vector(-chord.Y, chord.X) / chord.Length;
+ var depth = Math.Sqrt(Math.Max(0, step.ArcRadius * step.ArcRadius - half * half));
+ var middle = from + chord / 2;
+ points.Add(middle - normal * (step.ArcRadius - depth));
+ }
+ points.Add(step.To);
+ from = step.To;
+ }
+ return points;
+ }
+
+ private static bool Near(Point a, Point b, double tolerance = 1e-6) =>
+ Math.Abs(a.X - b.X) <= tolerance && Math.Abs(a.Y - b.Y) <= tolerance;
+
+ private static void AssertNear(Point expected, Point actual) =>
+ Assert.True(Near(expected, actual), $"expected {expected}, got {actual}");
+
+ private static void AssertStep(OutlineStep expected, OutlineStep actual)
+ {
+ AssertNear(expected.To, actual.To);
+ Assert.Equal(expected.ArcRadius, actual.ArcRadius, 6);
+ Assert.Equal(expected.IsLargeArc, actual.IsLargeArc);
+ Assert.Equal(expected.Clockwise, actual.Clockwise);
+ }
}
diff --git a/tests/Filee.App.Tests/RenderTests.cs b/tests/Filee.App.Tests/RenderTests.cs
index e398335e..73a9dcc0 100644
--- a/tests/Filee.App.Tests/RenderTests.cs
+++ b/tests/Filee.App.Tests/RenderTests.cs
@@ -451,6 +451,78 @@ public class RenderTests
}
}
+ /// <summary>
+ /// The theme's softness rounds the donut's slices (and a group's ring) too, live while it is open; the corners it
+ /// cuts away still belong to their slice for clicks and drops.
+ /// </summary>
+ [AvaloniaTheory]
+ [InlineData(false)]
+ [InlineData(true)]
+ public void Donut_slices_follow_the_softness(bool dark)
+ {
+ TestServices.EnsureInitialized("en");
+ var theme = AppHost.Get<ThemeService>();
+ var store = AppHost.Get<UserDataStore>();
+ var images = store.Profiles.Single(p => p.Id == "images");
+ var before = images.PresetIds.ToList();
+ var group = new Filee.Core.Presets.Preset
+ {
+ Id = "render-soft-group",
+ Name = "Formats",
+ Kind = Filee.Core.Presets.PresetKind.Group,
+ SubPresetIds = ["to-png", "to-jpg", "to-webp"],
+ };
+ var mode = dark ? ThemeMode.Dark : ThemeMode.Light;
+ var suffix = dark ? "dark" : "light";
+ try
+ {
+ store.Presets.Add(group);
+ images.PresetIds.Add(group.Id);
+ theme.Apply(new ThemeSettings { Mode = mode, CornerRadius = 0 }, "en");
+ var vm = AppHost.Get<RadialViewModel>();
+ vm.Load([@"C:\photos\a.jpg", @"C:\photos\b.jpg"], clickMode: true);
+ vm.FitToThisDonut();
+ var window = new RadialWindow { DataContext = vm };
+ window.Show();
+ var donut = window.DonutControl;
+ donut.SetExternalHighlight(1);
+ Pump();
+ Assert.Equal(0, donut.SliceCornerRadius);
+ Save(window, $"donut-softness-0-{suffix}.png");
+
+ // Changing the setting while the donut is open rounds it at once.
+ theme.Apply(new ThemeSettings { Mode = mode, CornerRadius = 28 }, "en");
+ Pump();
+ Assert.Equal(14, donut.SliceCornerRadius);
+ Save(window, $"donut-softness-28-{suffix}.png");
+
+ // The sharp corner of slice 2, cut away now, still picks slice 2.
+ var n = vm.Items.Count;
+ var center = new Avalonia.Point(donut.Bounds.Width / 2, donut.Bounds.Height / 2);
+ var inner = vm.OuterRadius * vm.HoleRatio;
+ var corner = DonutGeometry.Wedge(center, inner, vm.OuterRadius, DonutGeometry.MidAngle(2, n), DonutGeometry.Span(n), 3).Start;
+ var inside = center + (corner - center) * 0.995;
+ Assert.Equal(new DonutHit(DonutHitKind.Segment, 2), donut.HitTest(inside));
+
+ var index = n - 1;
+ donut.SetExternalHit(new DonutHit(DonutHitKind.Segment, index));
+ donut.ExpandPendingGroup();
+ donut.SetExternalHit(new DonutHit(DonutHitKind.SubSegment, index, 1));
+ vm.ShowHint(index, donut.ActiveSubIndex, centerHot: false);
+ Pump();
+ Assert.Equal(new DonutHit(DonutHitKind.SubSegment, index, 1), donut.HitTest(donut.SubSliceCenter(index, 1)));
+ Save(window, $"donut-softness-28-group-{suffix}.png");
+ window.Close();
+ }
+ finally
+ {
+ images.PresetIds.Clear();
+ images.PresetIds.AddRange(before);
+ store.Presets.Remove(group);
+ theme.Apply(new ThemeSettings(), "en");
+ }
+ }
+
/// <summary>The middle of slot <paramref name="slot"/> of a donut with <paramref name="slots"/> slices.</summary>
private static Avalonia.Point DonutPoint(DonutMenu donut, int slot, int slots)
{