|
8 | 8 | using Microsoft.UI.Xaml.Markup; |
9 | 9 | using Microsoft.UI.Xaml.Media; |
10 | 10 | using Microsoft.UI.Xaml.Shapes; |
| 11 | +using Windows.Foundation; |
11 | 12 |
|
12 | 13 | namespace Files.App.Controls |
13 | 14 | { |
14 | 15 | public partial class BreadcrumbBarLayout : NonVirtualizingLayout |
15 | 16 | { |
| 17 | + private Size _availableSize; |
| 18 | + private BreadcrumbBarItem? _ellipsisButton = null; |
16 | 19 | private WeakReference<BreadcrumbBar>? _ownerRef; |
17 | 20 |
|
| 21 | + private bool _ellipsisIsRendered; |
| 22 | + private uint _firstRenderedItemIndexAfterEllipsis; |
| 23 | + private uint _visibleItemsCount; |
| 24 | + |
18 | 25 | public BreadcrumbBarLayout(BreadcrumbBar breadcrumb) |
19 | 26 | { |
20 | 27 | _ownerRef = new(breadcrumb); |
21 | 28 | } |
| 29 | + |
| 30 | + protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Size availableSize) |
| 31 | + { |
| 32 | + var accumulatedSize = new Size(0, 0); |
| 33 | + |
| 34 | + // Go through all items and measure them |
| 35 | + foreach (var item in context.Children) |
| 36 | + { |
| 37 | + if (item is BreadcrumbBarItem breadcrumbItem) |
| 38 | + { |
| 39 | + breadcrumbItem.Measure(availableSize); |
| 40 | + accumulatedSize.Width += breadcrumbItem.DesiredSize.Width; |
| 41 | + accumulatedSize.Height = Math.Max(accumulatedSize.Height, breadcrumbItem.DesiredSize.Height); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + // Get a reference to the ellipsis item |
| 46 | + if (context.Children.Count is not 0) |
| 47 | + _ellipsisButton ??= context.Children[0] as BreadcrumbBarItem; |
| 48 | + |
| 49 | + // Sets the ellipsis item's visibility based on whether the items are overflowing |
| 50 | + _ellipsisIsRendered = accumulatedSize.Width > availableSize.Width; |
| 51 | + |
| 52 | + return accumulatedSize; |
| 53 | + } |
| 54 | + |
| 55 | + protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Size finalSize) |
| 56 | + { |
| 57 | + float accumulatedWidths = 0f; |
| 58 | + |
| 59 | + // Go through all items and arrange them |
| 60 | + foreach (var item in context.Children) |
| 61 | + { |
| 62 | + if (item is BreadcrumbBarItem breadcrumbItem) |
| 63 | + { |
| 64 | + breadcrumbItem.Arrange(new Rect(accumulatedWidths, 0, breadcrumbItem.DesiredSize.Width, finalSize.Height)); |
| 65 | + |
| 66 | + accumulatedWidths += (float)breadcrumbItem.Width; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + return finalSize; |
| 71 | + } |
22 | 72 | } |
23 | 73 | } |
0 commit comments