Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/Files.App.Controls/BreadcrumbBar/BreadcrumbBarLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,40 @@ public BreadcrumbBarLayout(BreadcrumbBar breadcrumb)

protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Size availableSize)
{
var accumulatedSize = new Size(0, 0);
// Early exit for null or empty context
if (context?.Children == null || context.Children.Count == 0)
{
return new Size(0, 0);
}
Comment on lines +34 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (context?.Children == null || context.Children.Count == 0)
{
return new Size(0, 0);
}
if (context?.Children is null || context.Children.Count is 0)
return new Size(0, 0);


_availableSize = availableSize;

var indexAfterEllipsis = GetFirstIndexToRender(context);
var maxHeight = 0;
var totalWidth = 0;
var children = context.Children;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caching like this is redundant.


// Cache ellipsis button reference from first item
_ellipsisButton ??= children[0] as BreadcrumbBarItem;

// Go through all items and measure them
for (int index = 0; index < context.Children.Count; index++)
for (int index = 0; index < children.Count; index++)
{
if (context.Children[index] is BreadcrumbBarItem breadcrumbItem)
if (children[index] is not BreadcrumbBarItem breadcrumbItem)
continue;

breadcrumbItem.Measure(availableSize);
if (index >= indexAfterEllipsis)
{
breadcrumbItem.Measure(availableSize);
accumulatedSize.Width += index < indexAfterEllipsis ? 0 : breadcrumbItem.DesiredSize.Width;
accumulatedSize.Height = Math.Max(accumulatedSize.Height, breadcrumbItem.DesiredSize.Height);
totalWidth += breadcrumbItem.DesiredSize.Width;
}
maxHeight = Math.Max(maxHeight, breadcrumbItem.DesiredSize.Height);
}

// Get a reference to the ellipsis item
if (context.Children.Count > 0)
_ellipsisButton ??= context.Children[0] as BreadcrumbBarItem;

// Sets the ellipsis item's visibility based on whether the items are overflowing
EllipsisIsRendered = indexAfterEllipsis is not 0;
// Update ellipsis visibility based on whether items are hidden
EllipsisIsRendered = indexAfterEllipsis > 0;

return accumulatedSize;
return new Size(totalWidth, maxHeight);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you don't use Size instead, like I did? And I feel like the code changes in the middle are unnecessary, is there a reason why you change there?

}

protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Size finalSize)
Expand Down