Skip to content

Commit ccf4a54

Browse files
committed
Collapse first few items when available width is shorter than desired
1 parent 8279c18 commit ccf4a54

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBarLayout.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,49 @@ protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Si
5959
{
6060
double accumulatedWidths = 0d;
6161

62-
_indexAfterEllipsis = context.Children.Count - 1;
62+
_indexAfterEllipsis = GetFirstIndexToRender(context);
6363

6464
// Go through all items and arrange them
65+
int index = 0;
6566
foreach (var item in context.Children)
6667
{
6768
if (item is BreadcrumbBarItem breadcrumbItem)
6869
{
69-
breadcrumbItem.Arrange(new Rect(accumulatedWidths, 0, breadcrumbItem.DesiredSize.Width, breadcrumbItem.DesiredSize.Height));
70+
if (index < _indexAfterEllipsis)
71+
{
72+
breadcrumbItem.Arrange(new Rect(0, 0, 0, 0));
73+
}
74+
else
75+
{
76+
breadcrumbItem.Arrange(new Rect(accumulatedWidths, 0, breadcrumbItem.DesiredSize.Width, breadcrumbItem.DesiredSize.Height));
7077

71-
accumulatedWidths += breadcrumbItem.DesiredSize.Width;
72-
accumulatedWidths += _spacing;
78+
accumulatedWidths += breadcrumbItem.DesiredSize.Width;
79+
accumulatedWidths += _spacing;
80+
}
81+
82+
index++;
7383
}
7484
}
7585

7686
return finalSize;
7787
}
88+
89+
private int GetFirstIndexToRender(NonVirtualizingLayoutContext context)
90+
{
91+
var itemCount = context.Children.Count;
92+
var accumulatedWidth = context.Children[itemCount - 1].DesiredSize.Width;
93+
94+
for (int i = itemCount - 2; i >= 0; i--)
95+
{
96+
var newAccumulatedWidth = accumulatedWidth + context.Children[i].DesiredSize.Width;
97+
98+
if (newAccumulatedWidth > _availableSize.Width)
99+
return i + 1;
100+
101+
accumulatedWidth = newAccumulatedWidth;
102+
}
103+
104+
return 0;
105+
}
78106
}
79107
}

tests/Files.App.UITests/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
SelectionChanged="NavigationView_SelectionChanged">
8383

8484
<NavigationView.MenuItems>
85-
<NavigationViewItem Content="Controls">
85+
<NavigationViewItem Content="Controls" IsExpanded="True">
8686
<NavigationViewItem.Icon>
8787
<FontIcon Glyph="&#xE73A;" />
8888
</NavigationViewItem.Icon>

0 commit comments

Comments
 (0)