Skip to content

Commit 3890385

Browse files
committed
Update
1 parent ccf4a54 commit 3890385

File tree

4 files changed

+32
-39
lines changed

4 files changed

+32
-39
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Licensed under the MIT License.
33

44
using CommunityToolkit.WinUI;
5-
using Microsoft.UI;
6-
using Microsoft.UI.Xaml;
7-
using Microsoft.UI.Xaml.Controls;
8-
using Microsoft.UI.Xaml.Input;
9-
using Microsoft.UI.Xaml.Markup;
10-
using Microsoft.UI.Xaml.Media;
11-
using Microsoft.UI.Xaml.Shapes;
125

136
namespace Files.App.Controls
147
{
@@ -22,13 +15,5 @@ public partial class BreadcrumbBar : Control
2215

2316
[GeneratedDependencyProperty]
2417
public partial FrameworkElement? RootItem { get; set; }
25-
26-
partial void OnItemsSourceChanged(object? newValue)
27-
{
28-
}
29-
30-
partial void OnItemTemplateChanged(object? newValue)
31-
{
32-
}
3318
}
3419
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4-
using CommunityToolkit.WinUI;
54
using Microsoft.UI;
65
using Microsoft.UI.Xaml;
76
using Microsoft.UI.Xaml.Controls;
@@ -57,28 +56,39 @@ protected override void OnApplyTemplate()
5756
_rootBreadcrumbBarItem.SetOwner(this);
5857
_itemsRepeater.Layout = _itemsRepeaterLayout;
5958

59+
Loaded += BreadcrumbBar_Loaded;
6060
_itemsRepeater.ElementPrepared += ItemsRepeater_ElementPrepared;
6161

6262
base.OnApplyTemplate();
6363
}
6464

65-
internal void RaiseItemClickedEvent(BreadcrumbBarItem item)
65+
private void BreadcrumbBar_Loaded(object sender, RoutedEventArgs e)
66+
{
67+
}
68+
69+
internal protected virtual void RaiseItemClickedEvent(BreadcrumbBarItem item)
6670
{
6771
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
6872
var eventArgs = new BreadcrumbBarItemClickedEventArgs(item, index, item == _rootBreadcrumbBarItem);
6973
ItemClicked?.Invoke(this, eventArgs);
7074
}
7175

72-
internal void RaiseItemDropDownFlyoutOpening(BreadcrumbBarItem item, MenuFlyout flyout)
76+
internal protected virtual void RaiseItemDropDownFlyoutOpening(BreadcrumbBarItem item, MenuFlyout flyout)
7377
{
7478
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
7579
ItemDropDownFlyoutOpening?.Invoke(this, new(flyout, item, index, item == _rootBreadcrumbBarItem));
7680
}
7781

78-
internal void RaiseItemDropDownFlyoutClosed(BreadcrumbBarItem item, MenuFlyout flyout)
82+
internal protected virtual void RaiseItemDropDownFlyoutClosed(BreadcrumbBarItem item, MenuFlyout flyout)
7983
{
8084
var index = _itemsRepeater?.GetElementIndex(item) ?? throw new ArgumentNullException($"{_itemsRepeater} is null.");
8185
ItemDropDownFlyoutClosed?.Invoke(this, new(flyout, item, index, item == _rootBreadcrumbBarItem));
8286
}
87+
88+
internal protected virtual void OnLayoutUpdated()
89+
{
90+
if (_itemsRepeater is null)
91+
return;
92+
}
8393
}
8494
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Licensed under the MIT License.
33

44
using CommunityToolkit.WinUI;
5-
using Microsoft.UI;
6-
using Microsoft.UI.Xaml;
7-
using Microsoft.UI.Xaml.Controls;
8-
using Microsoft.UI.Xaml.Input;
9-
using Microsoft.UI.Xaml.Markup;
10-
using Microsoft.UI.Xaml.Media;
11-
using Microsoft.UI.Xaml.Shapes;
125

136
namespace Files.App.Controls
147
{

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
// Copyright (c) Files Community
22
// Licensed under the MIT License.
33

4-
using Microsoft.UI;
5-
using Microsoft.UI.Xaml;
6-
using Microsoft.UI.Xaml.Controls;
7-
using Microsoft.UI.Xaml.Input;
8-
using Microsoft.UI.Xaml.Markup;
9-
using Microsoft.UI.Xaml.Media;
10-
using Microsoft.UI.Xaml.Shapes;
114
using Windows.Foundation;
125

136
namespace Files.App.Controls
147
{
8+
/// <summary>
9+
/// Handles layout of <see cref="BreadcrumbBar"/>, collapsing items into an ellipsis button when necessary.
10+
/// </summary>
1511
public partial class BreadcrumbBarLayout : NonVirtualizingLayout
1612
{
13+
// Fields
14+
1715
private Size _availableSize;
1816
private BreadcrumbBarItem? _ellipsisButton = null;
1917
private WeakReference<BreadcrumbBar>? _ownerRef;
2018
private double _spacing = 0d;
2119

22-
private bool _ellipsisIsRendered;
23-
private int _indexAfterEllipsis;
24-
private int _visibleItemsCount;
20+
// Properties
21+
22+
public bool EllipsisIsRendered { get; private set; }
23+
public int IndexAfterEllipsis { get; private set; }
24+
public int VisibleItemsCount { get; private set; }
2525

2626
public BreadcrumbBarLayout(BreadcrumbBar breadcrumb, double spacing)
2727
{
@@ -50,7 +50,7 @@ protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Si
5050
_ellipsisButton ??= context.Children[0] as BreadcrumbBarItem;
5151

5252
// Sets the ellipsis item's visibility based on whether the items are overflowing
53-
_ellipsisIsRendered = accumulatedSize.Width > availableSize.Width;
53+
EllipsisIsRendered = accumulatedSize.Width > availableSize.Width;
5454

5555
return accumulatedSize;
5656
}
@@ -59,20 +59,22 @@ protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Si
5959
{
6060
double accumulatedWidths = 0d;
6161

62-
_indexAfterEllipsis = GetFirstIndexToRender(context);
62+
IndexAfterEllipsis = GetFirstIndexToRender(context);
6363

6464
// Go through all items and arrange them
6565
int index = 0;
6666
foreach (var item in context.Children)
6767
{
6868
if (item is BreadcrumbBarItem breadcrumbItem)
6969
{
70-
if (index < _indexAfterEllipsis)
70+
if (index < IndexAfterEllipsis)
7171
{
72+
// Collapse
7273
breadcrumbItem.Arrange(new Rect(0, 0, 0, 0));
7374
}
7475
else
7576
{
77+
// Arrange normally
7678
breadcrumbItem.Arrange(new Rect(accumulatedWidths, 0, breadcrumbItem.DesiredSize.Width, breadcrumbItem.DesiredSize.Height));
7779

7880
accumulatedWidths += breadcrumbItem.DesiredSize.Width;
@@ -83,6 +85,9 @@ protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Si
8385
}
8486
}
8587

88+
if (_ownerRef?.TryGetTarget(out var breadcrumbBar) ?? false)
89+
breadcrumbBar.OnLayoutUpdated();
90+
8691
return finalSize;
8792
}
8893

0 commit comments

Comments
 (0)