Skip to content

Commit a81c575

Browse files
committed
Use the custom layouting class for ItemsRepeater of BreadcrumbBar
1 parent ec8bb8b commit a81c575

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public BreadcrumbBar()
5050
{
5151
DefaultStyleKey = typeof(BreadcrumbBar);
5252

53-
_itemsRepeaterLayout = new(this);
53+
_itemsRepeaterLayout = new(this, 2d);
5454
}
5555

5656
// Methods
@@ -66,7 +66,7 @@ protected override void OnApplyTemplate()
6666
_itemsRepeater = GetTemplateChild(TemplatePartName_MainItemsRepeater) as ItemsRepeater
6767
?? throw new MissingFieldException($"Could not find {TemplatePartName_MainItemsRepeater} in the given {nameof(BreadcrumbBar)}'s style.");
6868

69-
//_itemsRepeater.Layout = _itemsRepeaterLayout;
69+
_itemsRepeater.Layout = _itemsRepeaterLayout;
7070

7171
_rootItemButton.PointerEntered += RootItemButton_PointerEntered;
7272
_rootItemButton.PointerPressed += RootItemButton_PointerPressed;

src/Files.App.Controls/BreadcrumbBar/BreadcrumbBar.xaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@
8888
x:Name="PART_MainItemsRepeater"
8989
Grid.Column="2"
9090
ItemTemplate="{Binding ItemTemplate, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
91-
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}">
92-
<ItemsRepeater.Layout>
93-
<StackLayout Orientation="Horizontal" Spacing="2" />
94-
</ItemsRepeater.Layout>
95-
</ItemsRepeater>
91+
ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}" />
9692

9793
<VisualStateManager.VisualStateGroups>
9894

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ public partial class BreadcrumbBarLayout : NonVirtualizingLayout
1717
private Size _availableSize;
1818
private BreadcrumbBarItem? _ellipsisButton = null;
1919
private WeakReference<BreadcrumbBar>? _ownerRef;
20+
private double _spacing = 0d;
2021

2122
private bool _ellipsisIsRendered;
2223
private uint _firstRenderedItemIndexAfterEllipsis;
2324
private uint _visibleItemsCount;
2425

25-
public BreadcrumbBarLayout(BreadcrumbBar breadcrumb)
26+
public BreadcrumbBarLayout(BreadcrumbBar breadcrumb, double spacing)
2627
{
2728
_ownerRef = new(breadcrumb);
29+
_spacing = spacing;
2830
}
2931

3032
protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Size availableSize)
@@ -54,16 +56,17 @@ protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Si
5456

5557
protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Size finalSize)
5658
{
57-
float accumulatedWidths = 0f;
59+
double accumulatedWidths = 0d;
5860

5961
// Go through all items and arrange them
6062
foreach (var item in context.Children)
6163
{
6264
if (item is BreadcrumbBarItem breadcrumbItem)
6365
{
64-
breadcrumbItem.Arrange(new Rect(accumulatedWidths, 0, breadcrumbItem.DesiredSize.Width, finalSize.Height));
66+
breadcrumbItem.Arrange(new Rect(accumulatedWidths, 0, breadcrumbItem.DesiredSize.Width, breadcrumbItem.DesiredSize.Height));
6567

66-
accumulatedWidths += (float)breadcrumbItem.Width;
68+
accumulatedWidths += breadcrumbItem.DesiredSize.Width;
69+
accumulatedWidths += _spacing;
6770
}
6871
}
6972

0 commit comments

Comments
 (0)