NewLife/XCoder

fix: 修复磁盘星图面包屑滚动条遮挡路径文字

面包屑溢出时,Fluent 默认的悬浮滚动条覆盖在内容之上,挡住路径文字。改为关闭自动隐藏让滚动条独占一行,并收敛为 8 像素细滚动条;补充无头布局测试验证滚动条与文字不重叠。
大石头 authored at 2026-11-17 22:28:21
f5e76be
Tree
1 Parent(s) 2ab4174
Summary: 2 changed files with 125 additions and 2 deletions.
Added +100 -0
Modified +25 -2
Added +100 -0
diff --git a/Tests/XCoder.App.UiTests/FolderStatBreadcrumbTests.cs b/Tests/XCoder.App.UiTests/FolderStatBreadcrumbTests.cs
new file mode 100644
index 0000000..cabb4e8
--- /dev/null
+++ b/Tests/XCoder.App.UiTests/FolderStatBreadcrumbTests.cs
@@ -0,0 +1,100 @@
+using System;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using System.Threading.Tasks;
+using Avalonia.Controls;
+using Avalonia.Controls.Presenters;
+using Avalonia.Controls.Primitives;
+using Avalonia.Layout;
+using Avalonia.VisualTree;
+using NewLife.XCoder.Tools.Folder;
+using Xunit;
+
+namespace XCoder.App.UiTests;
+
+/// <summary>磁盘星图面包屑导航的布局测试</summary>
+/// <remarks>
+/// 路径较深时面包屑溢出,Fluent 主题默认把横向滚动条覆盖绘制在内容之上,
+/// 会把路径文字盖住。这里断言滚动条与内容各占一行,互不重叠。
+/// </remarks>
+public class FolderStatBreadcrumbTests
+{
+    private static Task RunOnUi(Action action) => UiSession.Run(action);
+
+    /// <summary>构造一个指定层级深度的视图,跳过卷列表加载,避免被真实磁盘内容覆盖</summary>
+    private static FolderStatToolView CreateDeepView(Int32 depth)
+    {
+        var view = new FolderStatToolView();
+
+        var type = typeof(FolderStatToolView);
+        const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
+
+        // 标记已加载,Show 时不再执行 LoadVolumes 覆盖面包屑
+        type.GetField("_loaded", flags)!.SetValue(view, true);
+
+        DiskNode? current = null;
+        for (var i = 0; i < depth; i++)
+        {
+            var name = $"VeryLongDirectoryName{i:D2}";
+            current = DiskNode.CreateFile(name, $@"C:\{name}", 1024 * 1024, FileCategory.Other, current);
+        }
+        type.GetField("_current", flags)!.SetValue(view, current);
+        type.GetMethod("UpdateChrome", flags)!.Invoke(view, null);
+
+        return view;
+    }
+
+    [Fact]
+    [DisplayName("面包屑溢出时滚动条独占一行,不覆盖路径文字")]
+    public Task Breadcrumb_ScrollBar_DoesNotCoverText() => RunOnUi(() =>
+    {
+        var view = CreateDeepView(12);
+        var window = new Window { Width = 900, Height = 700, Content = view };
+        window.Show();
+        try
+        {
+            var scroll = view.FindControl<ScrollViewer>("CrumbScroll");
+            Assert.NotNull(scroll);
+
+            var bar = scroll!.GetVisualDescendants().OfType<ScrollBar>()
+                .FirstOrDefault(e => e.Orientation == Orientation.Horizontal);
+            Assert.NotNull(bar);
+
+            var presenter = scroll.GetVisualDescendants().OfType<ScrollContentPresenter>().FirstOrDefault();
+            Assert.NotNull(presenter);
+
+            Assert.True(bar!.IsVisible, "面包屑溢出后应出现横向滚动条");
+            Assert.True(presenter!.Bounds.Bottom <= bar.Bounds.Top + 0.5,
+                $"滚动条与路径文字重叠:内容底部 {presenter.Bounds.Bottom:F1},滚动条顶部 {bar.Bounds.Top:F1}");
+        }
+        finally
+        {
+            window.Close();
+        }
+    });
+
+    [Fact]
+    [DisplayName("面包屑不溢出时不显示滚动条")]
+    public Task Breadcrumb_ShortPath_NoScrollBar() => RunOnUi(() =>
+    {
+        var view = CreateDeepView(2);
+        var window = new Window { Width = 1400, Height = 700, Content = view };
+        window.Show();
+        try
+        {
+            var scroll = view.FindControl<ScrollViewer>("CrumbScroll");
+            Assert.NotNull(scroll);
+
+            var bar = scroll!.GetVisualDescendants().OfType<ScrollBar>()
+                .FirstOrDefault(e => e.Orientation == Orientation.Horizontal);
+            Assert.NotNull(bar);
+
+            Assert.False(bar!.IsVisible, "面包屑未溢出时不应显示横向滚动条");
+        }
+        finally
+        {
+            window.Close();
+        }
+    });
+}
Modified +25 -2
diff --git a/XCoder.App/Tools/Folder/FolderStatToolView.axaml b/XCoder.App/Tools/Folder/FolderStatToolView.axaml
index c4c519c..6cf87d2 100644
--- a/XCoder.App/Tools/Folder/FolderStatToolView.axaml
+++ b/XCoder.App/Tools/Folder/FolderStatToolView.axaml
@@ -28,8 +28,31 @@
         <Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" ColumnSpacing="10">
             <Button Name="BackButton" Classes="secondary" Content="{loc:Tr '↑ Up'}" FontSize="12"
                     ToolTip.Tip="{loc:Tr 'Go up (Alt+Up or Backspace)'}" />
-            <ScrollViewer Grid.Column="1" HorizontalScrollBarVisibility="Auto"
-                          VerticalScrollBarVisibility="Disabled">
+            <!-- AllowAutoHide=False 让滚动条独占一行,Fluent 默认的悬浮滚动条会盖住路径文字 -->
+            <ScrollViewer Name="CrumbScroll" Grid.Column="1" HorizontalScrollBarVisibility="Auto"
+                          VerticalScrollBarVisibility="Disabled" AllowAutoHide="False">
+                <ScrollViewer.Resources>
+                    <!-- 细滚动条:8 像素高,尽量少占工具栏高度 -->
+                    <x:Double x:Key="ScrollBarSize">8</x:Double>
+                </ScrollViewer.Resources>
+                <ScrollViewer.Styles>
+                    <!-- 面包屑只保留滑块,去掉箭头按钮与轨道底色 -->
+                    <Style Selector="ScrollBar:horizontal">
+                        <Setter Property="Margin" Value="0,1,0,0" />
+                    </Style>
+                    <Style Selector="ScrollBar:horizontal /template/ RepeatButton">
+                        <Setter Property="IsVisible" Value="False" />
+                    </Style>
+                    <Style Selector="ScrollBar:horizontal /template/ Rectangle#TrackRect">
+                        <Setter Property="IsVisible" Value="False" />
+                    </Style>
+                    <Style Selector="ScrollBar:horizontal /template/ Thumb">
+                        <Setter Property="CornerRadius" Value="4" />
+                    </Style>
+                    <Style Selector="ScrollBar:horizontal /template/ Grid#Root">
+                        <Setter Property="Background" Value="Transparent" />
+                    </Style>
+                </ScrollViewer.Styles>
                 <StackPanel Name="CrumbsPanel" Orientation="Horizontal" Spacing="2"
                             VerticalAlignment="Center" Margin="2,0" />
             </ScrollViewer>