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
35 changes: 31 additions & 4 deletions src/Files.App.Controls/Omnibar/Omnibar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,38 @@ protected void ChangeMode(OmnibarMode? oldMode, OmnibarMode newMode)
var modeButtonWidth = newMode.ActualWidth;
var modeSeparatorWidth = itemCount is not 0 or 1 ? _modesHostGrid.Children[1] is FrameworkElement frameworkElement ? frameworkElement.ActualWidth : 0 : 0;

var leftPadding = (itemIndex + 1) * modeButtonWidth + modeSeparatorWidth * itemIndex;
var rightPadding = (itemCount - itemIndex - 1) * modeButtonWidth + modeSeparatorWidth * (itemCount - itemIndex - 1) + 8;
// Check if the UI elements have been properly measured
// If ActualWidth is 0, defer the padding calculation to avoid division by zero in WinUI's layout system
if (modeButtonWidth > 0)
{
var leftPadding = (itemIndex + 1) * modeButtonWidth + modeSeparatorWidth * itemIndex;
var rightPadding = (itemCount - itemIndex - 1) * modeButtonWidth + modeSeparatorWidth * (itemCount - itemIndex - 1) + 8;

// Set the correct AutoSuggestBox cursor position
AutoSuggestBoxPadding = new(leftPadding, 0, rightPadding, 0);
// Set the correct AutoSuggestBox cursor position
AutoSuggestBoxPadding = new(leftPadding, 0, rightPadding, 0);
}
else
{
// Defer padding calculation until the UI elements are properly measured
DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Low, () =>
{
// Force layout update to ensure ActualWidth values are available
_modesHostGrid.UpdateLayout();
newMode.UpdateLayout();

var updatedModeButtonWidth = newMode.ActualWidth;
var updatedModeSeparatorWidth = itemCount is not 0 or 1 ? _modesHostGrid.Children[1] is FrameworkElement frameworkElement ? frameworkElement.ActualWidth : 0 : 0;

// Only update padding if we now have valid measurements
if (updatedModeButtonWidth > 0)
{
var leftPadding = (itemIndex + 1) * updatedModeButtonWidth + updatedModeSeparatorWidth * itemIndex;
var rightPadding = (itemCount - itemIndex - 1) * updatedModeButtonWidth + updatedModeSeparatorWidth * (itemCount - itemIndex - 1) + 8;

AutoSuggestBoxPadding = new(leftPadding, 0, rightPadding, 0);
}
});
}

_textChangeReason = OmnibarTextChangeReason.ProgrammaticChange;
ChangeTextBoxText(newMode.Text ?? string.Empty);
Expand Down
Loading