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 captions wrap instead of being cut off

DevOhMyCodebef8115c0d03
diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.cs
index c8a092ce..ba00c908 100644
--- a/src/Filee.App/Controls/DonutMenu.cs
+++ b/src/Filee.App/Controls/DonutMenu.cs
@@ -974,7 +974,9 @@ public sealed partial class DonutMenu : Control
var showCaption = !string.IsNullOrEmpty(item.Caption) &&
!string.Equals(item.Caption, item.Label, StringComparison.OrdinalIgnoreCase) &&
label.Height + 14 < maxHeight;
- var caption = showCaption ? MakeText(item.Caption!, regular, 10.5, hot ? OnAccentBrush : SecondaryForeground, width) : null;
+ var caption = showCaption
+ ? MakeCaption(item.Caption!, regular, hot ? OnAccentBrush : SecondaryForeground, width, label.Height, maxHeight)
+ : null;
var total = label.Height + (caption?.Height ?? 0);
var anchor = DonutGeometry.PointAt(center, radius, angle);
@@ -984,6 +986,14 @@ public sealed partial class DonutMenu : Control
DrawCentered(context, caption, anchor.X, y + label.Height);
}
+ /// <summary>
+ /// A slice's caption under its name: one line, or two where the slice is deep enough, so a caption wider than the
+ /// slice ("Same format" on a small donut) wraps instead of ending in "Same for…".
+ /// </summary>
+ internal static FormattedText MakeCaption(string caption, Typeface typeface, IBrush? brush, double width,
+ double labelHeight, double maxHeight) =>
+ MakeText(caption, typeface, 10.5, brush, width, maxLines: labelHeight + 28 < maxHeight ? 2 : 1);
+
private const double LabelFontSize = 13;
private const double MinLabelFontSize = 10;
private readonly Dictionary<(string Text, Typeface Typeface, double Width), double> _labelSizes = new();
diff --git a/src/Filee.App/Views/Pages/ToolbarPage.axaml b/src/Filee.App/Views/Pages/ToolbarPage.axaml
index ce94ec2d..cbb22035 100644
--- a/src/Filee.App/Views/Pages/ToolbarPage.axaml
+++ b/src/Filee.App/Views/Pages/ToolbarPage.axaml
@@ -365,10 +365,12 @@
<DataTemplate x:DataType="vm:PaletteChip">
<Border Classes="chip" Classes.dimmed="{Binding IsDimmed}" ToolTip.Tip="{Binding Reason}"
PointerPressed="OnChipPressed" DoubleTapped="OnChipDoubleTapped">
- <StackPanel Orientation="Horizontal" Spacing="6">
- <TextBlock Text="{Binding Label}" FontWeight="SemiBold" />
- <TextBlock Classes="caption" Text="{Binding Caption}" VerticalAlignment="Center" />
- </StackPanel>
+ <!-- A chip wider than the palette ends its caption with "…" instead of being cut at the edge. -->
+ <DockPanel>
+ <TextBlock Text="{Binding Label}" FontWeight="SemiBold" TextTrimming="CharacterEllipsis" />
+ <TextBlock Classes="caption" Text="{Binding Caption}" VerticalAlignment="Center" Margin="6,0,0,0"
+ TextTrimming="CharacterEllipsis" />
+ </DockPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
diff --git a/tests/Filee.App.Tests/DonutLabelPlacementTests.cs b/tests/Filee.App.Tests/DonutLabelPlacementTests.cs
index 27b44c8e..d35dcf0f 100644
--- a/tests/Filee.App.Tests/DonutLabelPlacementTests.cs
+++ b/tests/Filee.App.Tests/DonutLabelPlacementTests.cs
@@ -103,6 +103,19 @@ public class DonutLabelPlacementTests
Assert.Equal("Merge PDF", DonutMenu.KeepKoreanWords("Merge PDF"));
}
+ /// <summary>A caption wider than its slice wraps where the slice is deep enough, rather than ending in "Same for…".</summary>
+ [AvaloniaFact]
+ public void A_caption_wider_than_its_slice_takes_a_second_line_where_there_is_room()
+ {
+ TestServices.EnsureInitialized("en");
+ var typeface = new Typeface(FontFamily.Default);
+ var oneLine = DonutMenu.MakeCaption("PNG", typeface, null, 45, labelHeight: 17, maxHeight: 80).Height;
+
+ Assert.InRange(DonutMenu.MakeCaption("Same format", typeface, null, 45, labelHeight: 17, maxHeight: 80).Height, oneLine * 1.8, oneLine * 2.2);
+ Assert.Equal(oneLine, DonutMenu.MakeCaption("Same format", typeface, null, 45, labelHeight: 17, maxHeight: 40).Height);
+ Assert.Equal(oneLine, DonutMenu.MakeCaption("Same format", typeface, null, 120, labelHeight: 17, maxHeight: 80).Height);
+ }
+
private static (byte[] Pixels, int Width, int Height) Read(Avalonia.Media.Imaging.WriteableBitmap bitmap)
{
using var buffer = bitmap.Lock();