Skip to content

Commit bef113b

Browse files
authored
Avalonia UI: refine navigation, search boxes, filter pane & operation banners (#4964)
1 parent d1258c4 commit bef113b

8 files changed

Lines changed: 421 additions & 143 deletions

File tree

‎src/UniGetUI.Avalonia/Infrastructure/AvaloniaOperationRegistry.cs‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,6 @@ private static void ShowOperationSuccessNotification(AbstractOperation op)
235235

236236
if (OperatingSystem.IsMacOS() && MacOsNotificationBridge.ShowSuccess(op))
237237
return;
238-
239-
if (TryGetMainWindow() is not { } mainWindow)
240-
return;
241-
242-
mainWindow.ShowRuntimeNotification(
243-
title,
244-
message,
245-
UniGetUI.Avalonia.Views.MainWindow.RuntimeNotificationLevel.Success);
246238
}
247239

248240
private static void ShowOperationFailureNotification(AbstractOperation op)

‎src/UniGetUI.Avalonia/ViewModels/SidebarViewModel.cs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,27 @@ partial void OnBundlesBadgeVisibleChanged(bool value)
4747
private bool _installedIsLoading;
4848

4949
// ─── Pane open/closed ─────────────────────────────────────────────────────
50+
// Starts collapsed: the pane is a floating overlay in every size class (see MainWindow's
51+
// adaptive logic), so there is no persistent open-on-launch state.
5052
[ObservableProperty]
51-
private bool isPaneOpen = !Settings.Get(Settings.K.CollapseNavMenuOnWideScreen);
53+
private bool isPaneOpen;
54+
55+
// Only persist the open/closed choice as the "collapse on wide screen" preference
56+
// while the pane is inline (Expanded mode). In the overlay modes used on smaller
57+
// windows, opening/closing is transient and must not overwrite the saved preference.
58+
// The MainWindow's adaptive logic keeps this in sync with the SplitView display mode.
59+
public bool PersistPaneCollapsePreference { get; set; } = true;
5260

5361
partial void OnIsPaneOpenChanged(bool value)
5462
{
55-
Settings.Set(Settings.K.CollapseNavMenuOnWideScreen, !value);
56-
OnPropertyChanged(nameof(PaneWidth));
63+
if (PersistPaneCollapsePreference)
64+
Settings.Set(Settings.K.CollapseNavMenuOnWideScreen, !value);
5765
OnPropertyChanged(nameof(UpdatesBadgeExpandedVisible));
5866
OnPropertyChanged(nameof(UpdatesBadgeCompactVisible));
5967
OnPropertyChanged(nameof(BundlesBadgeExpandedVisible));
6068
OnPropertyChanged(nameof(BundlesBadgeCompactVisible));
6169
}
6270

63-
public double PaneWidth => IsPaneOpen ? 250 : 64;
64-
6571
public bool UpdatesBadgeExpandedVisible => UpdatesBadgeVisible && IsPaneOpen;
6672
public bool UpdatesBadgeCompactVisible => UpdatesBadgeVisible && !IsPaneOpen;
6773
public bool BundlesBadgeExpandedVisible => BundlesBadgeVisible && IsPaneOpen;

‎src/UniGetUI.Avalonia/Views/MainWindow.axaml‎

Lines changed: 177 additions & 50 deletions
Large diffs are not rendered by default.

‎src/UniGetUI.Avalonia/Views/MainWindow.axaml.cs‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,14 @@ public MainWindow()
9696
DataContext = new MainWindowViewModel();
9797
InitializeComponent();
9898
SetupTitleBar();
99+
SetupResponsiveRail();
99100

100101
RestoreGeometry();
101102

102103
KeyDown += Window_KeyDown;
103104
ViewModel.CurrentPageChanged += OnCurrentPageChanged;
105+
// Title-bar back button: visible whenever there's somewhere to go back to (mirrors WinUI's TitleBar.IsBackButtonVisible).
106+
ViewModel.CanGoBackChanged += (_, canGoBack) => BackButton.IsVisible = canGoBack;
104107
ViewModel.PropertyChanged += OnViewModelPropertyChanged;
105108
UpdateOperationsPanelRow();
106109

@@ -216,6 +219,9 @@ private void Window_KeyDown(object? sender, KeyEventArgs e)
216219

217220
private void OnCurrentPageChanged(object? sender, PageType pageType)
218221
{
222+
// Like WinUI's NavigationView: picking a page collapses the sliding flyout back to the rail.
223+
ViewModel.Sidebar.IsPaneOpen = false;
224+
219225
if (!_focusSidebarSelectionOnNextPageChange)
220226
return;
221227

@@ -227,6 +233,8 @@ private void OnCurrentPageChanged(object? sender, PageType pageType)
227233
}, DispatcherPriority.Background);
228234
}
229235

236+
private void BackButton_Click(object? sender, RoutedEventArgs e) => ViewModel.NavigateBack();
237+
230238
private void OnViewModelPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
231239
{
232240
if (e.PropertyName is nameof(MainWindowViewModel.OperationsPanelExpanded)
@@ -240,10 +248,10 @@ or nameof(MainWindowViewModel.OperationsPanelVisible))
240248
// user's chosen size across collapse/expand.
241249
private void UpdateOperationsPanelRow()
242250
{
243-
if (MainContentGrid.RowDefinitions.Count < 3)
251+
if (ContentRoot.RowDefinitions.Count < 3)
244252
return;
245253

246-
RowDefinition row = MainContentGrid.RowDefinitions[2];
254+
RowDefinition row = ContentRoot.RowDefinitions[2];
247255
if (ViewModel.OperationsPanelVisible && ViewModel.OperationsPanelExpanded)
248256
{
249257
row.MinHeight = 80;
@@ -258,6 +266,21 @@ private void UpdateOperationsPanelRow()
258266
}
259267
}
260268

269+
// ─── Navigation rail (responsive) ─────────────────────────────────────────
270+
// The always-visible icon rail shows on roomy windows and collapses below 800px so narrow
271+
// windows give the content full width (the hamburger + sliding flyout still provide nav).
272+
private void SetupResponsiveRail()
273+
=> MainContentRoot.GetObservable(BoundsProperty)
274+
.Subscribe(b =>
275+
{
276+
if (b.Width <= 0) return;
277+
NavRail.IsVisible = b.Width >= 800;
278+
});
279+
280+
// Light-dismiss: clicking outside the open flyout closes it (no darkening — the layer is transparent).
281+
private void FlyoutDismiss_PointerPressed(object? sender, PointerPressedEventArgs e)
282+
=> ViewModel.Sidebar.IsPaneOpen = false;
283+
261284
private void SetupTitleBar()
262285
{
263286
if (OperatingSystem.IsMacOS())
@@ -278,8 +301,8 @@ private void SetupTitleBar()
278301
{
279302
TitleBarGrid.ClearValue(HeightProperty);
280303
TitleBarGrid.Height = 44;
281-
MainContentGrid.ClearValue(MarginProperty);
282-
MainContentGrid.Margin = new Thickness(0, 44, 0, 0);
304+
MainContentRoot.ClearValue(MarginProperty);
305+
MainContentRoot.Margin = new Thickness(0, 44, 0, 0);
283306
HamburgerPanel.Margin = new Thickness(10, 0, 8, 0);
284307
}
285308
else
@@ -288,7 +311,7 @@ private void SetupTitleBar()
288311
{
289312
RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(Window) },
290313
});
291-
MainContentGrid.Bind(MarginProperty, new Binding("WindowDecorationMargin")
314+
MainContentRoot.Bind(MarginProperty, new Binding("WindowDecorationMargin")
292315
{
293316
RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor) { AncestorType = typeof(Window) },
294317
});
@@ -311,7 +334,7 @@ private void SetupTitleBar()
311334
TitleBarGrid.Height = 44;
312335
HamburgerPanel.Margin = new Thickness(10, 0, 8, 0);
313336
WindowButtons.IsVisible = true;
314-
MainContentGrid.Margin = new Thickness(0, 44, 0, 0);
337+
MainContentRoot.Margin = new Thickness(0, 44, 0, 0);
315338
this.GetObservable(WindowStateProperty).Subscribe(state =>
316339
{
317340
UpdateMaximizeButtonState(state == WindowState.Maximized);
@@ -328,7 +351,7 @@ private void SetupTitleBar()
328351
TitleBarGrid.Height = 44;
329352
HamburgerPanel.Margin = new Thickness(10, 0, 8, 0);
330353
WindowButtons.IsVisible = !useNativeDecorations;
331-
MainContentGrid.Margin = new Thickness(0, 44, 0, 0);
354+
MainContentRoot.Margin = new Thickness(0, 44, 0, 0);
332355
// Keep maximize icon in sync with window state
333356
this.GetObservable(WindowStateProperty).Subscribe(state =>
334357
{

‎src/UniGetUI.Avalonia/Views/SidebarView.axaml‎

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
xmlns:automation="clr-namespace:Avalonia.Automation;assembly=Avalonia.Controls"
55
xmlns:vm="using:UniGetUI.Avalonia.ViewModels"
66
xmlns:controls="using:UniGetUI.Avalonia.Views.Controls"
7+
xmlns:local="using:UniGetUI.Avalonia.Views"
78
xmlns:t="using:UniGetUI.Avalonia.MarkupExtensions"
89
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
910
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1011
mc:Ignorable="d"
12+
x:Name="SidebarRoot"
1113
x:DataType="vm:SidebarViewModel"
1214
MinWidth="64">
1315

@@ -36,13 +38,16 @@
3638
FontSize="16"
3739
FontWeight="SemiBold"
3840
VerticalAlignment="Center"
39-
IsVisible="{Binding IsPaneOpen}"/>
41+
IsVisible="{Binding $parent[local:SidebarView].ShowLabels}"/>
4042
</StackPanel>
4143
<ProgressBar IsIndeterminate="True"
4244
IsVisible="{Binding DiscoverIsLoading}"
4345
Height="2"
46+
Width="32"
47+
MinWidth="0"
48+
HorizontalAlignment="Left"
4449
VerticalAlignment="Bottom"
45-
Margin="8,0"/>
50+
Margin="4,0,0,2"/>
4651
</Panel>
4752
</ListBoxItem>
4853

@@ -58,26 +63,15 @@
5863
FontSize="16"
5964
FontWeight="SemiBold"
6065
VerticalAlignment="Center"
61-
IsVisible="{Binding IsPaneOpen}"/>
62-
<!-- Updates badge (expanded) -->
63-
<Border Background="{DynamicResource SystemAccentColor}"
64-
CornerRadius="10"
65-
Padding="6,1"
66-
IsVisible="{Binding UpdatesBadgeExpandedVisible}"
67-
VerticalAlignment="Center">
68-
<TextBlock Text="{Binding UpdatesBadgeCount}"
69-
FontSize="11"
70-
FontWeight="Bold"
71-
Foreground="White"/>
72-
</Border>
66+
IsVisible="{Binding $parent[local:SidebarView].ShowLabels}"/>
7367
</StackPanel>
74-
<!-- Updates badge (compact overlay) -->
68+
<!-- Update count bubble (InfoBadge-style), anchored to the icon's top-right in both rail and flyout -->
7569
<Border Background="{DynamicResource SystemAccentColor}"
7670
CornerRadius="8"
7771
Padding="3,1"
7872
MinWidth="16"
7973
Height="16"
80-
IsVisible="{Binding UpdatesBadgeCompactVisible}"
74+
IsVisible="{Binding UpdatesBadgeVisible}"
8175
HorizontalAlignment="Left"
8276
VerticalAlignment="Top"
8377
Margin="26,3,0,0">
@@ -91,8 +85,11 @@
9185
<ProgressBar IsIndeterminate="True"
9286
IsVisible="{Binding UpdatesIsLoading}"
9387
Height="2"
88+
Width="32"
89+
MinWidth="0"
90+
HorizontalAlignment="Left"
9491
VerticalAlignment="Bottom"
95-
Margin="8,0"/>
92+
Margin="4,0,0,2"/>
9693
</Panel>
9794
</ListBoxItem>
9895

@@ -108,13 +105,16 @@
108105
FontSize="16"
109106
FontWeight="SemiBold"
110107
VerticalAlignment="Center"
111-
IsVisible="{Binding IsPaneOpen}"/>
108+
IsVisible="{Binding $parent[local:SidebarView].ShowLabels}"/>
112109
</StackPanel>
113110
<ProgressBar IsIndeterminate="True"
114111
IsVisible="{Binding InstalledIsLoading}"
115112
Height="2"
113+
Width="32"
114+
MinWidth="0"
115+
HorizontalAlignment="Left"
116116
VerticalAlignment="Bottom"
117-
Margin="8,0"/>
117+
Margin="4,0,0,2"/>
118118
</Panel>
119119
</ListBoxItem>
120120

@@ -130,27 +130,14 @@
130130
FontSize="16"
131131
FontWeight="SemiBold"
132132
VerticalAlignment="Center"
133-
IsVisible="{Binding IsPaneOpen}"/>
134-
<!-- Unsaved changes badge (expanded) -->
135-
<Border Background="{DynamicResource SystemFillColorCautionBrush}"
136-
CornerRadius="10"
137-
Width="16"
138-
Height="16"
139-
IsVisible="{Binding BundlesBadgeExpandedVisible}"
140-
VerticalAlignment="Center">
141-
<TextBlock Text="!"
142-
FontSize="10"
143-
FontWeight="Bold"
144-
HorizontalAlignment="Center"
145-
VerticalAlignment="Center"/>
146-
</Border>
133+
IsVisible="{Binding $parent[local:SidebarView].ShowLabels}"/>
147134
</StackPanel>
148-
<!-- Unsaved changes badge (compact overlay dot) -->
135+
<!-- Unsaved changes dot, anchored to the icon's top-right in both rail and flyout -->
149136
<Border Background="{DynamicResource SystemFillColorCautionBrush}"
150137
CornerRadius="5"
151138
Width="10"
152139
Height="10"
153-
IsVisible="{Binding BundlesBadgeCompactVisible}"
140+
IsVisible="{Binding BundlesBadgeVisible}"
154141
HorizontalAlignment="Left"
155142
VerticalAlignment="Top"
156143
Margin="28,5,0,0"/>
@@ -177,7 +164,7 @@
177164
<StackPanel Orientation="Horizontal" Spacing="12">
178165
<controls:SvgIcon Path="avares://UniGetUI.Avalonia/Assets/Symbols/settings.svg" Width="24" Height="24" VerticalAlignment="Center"/>
179166
<TextBlock Text="{t:Translate Settings}" FontSize="16" VerticalAlignment="Center"
180-
IsVisible="{Binding IsPaneOpen}"/>
167+
IsVisible="{Binding $parent[local:SidebarView].ShowLabels}"/>
181168
</StackPanel>
182169
</Button>
183170

@@ -195,7 +182,7 @@
195182
<StackPanel Orientation="Horizontal" Spacing="12">
196183
<controls:SvgIcon Path="avares://UniGetUI.Avalonia/Assets/Symbols/clipboard_list.svg" Width="24" Height="24" VerticalAlignment="Center"/>
197184
<TextBlock Text="{t:Translate Package Managers}" FontSize="16" VerticalAlignment="Center"
198-
IsVisible="{Binding IsPaneOpen}"/>
185+
IsVisible="{Binding $parent[local:SidebarView].ShowLabels}"/>
199186
</StackPanel>
200187
</Button>
201188

@@ -211,7 +198,7 @@
211198
<TextBlock Text="···" FontSize="20" Width="24" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center"
212199
automation:AutomationProperties.AccessibilityView="Raw"/>
213200
<TextBlock Text="{t:Translate More}" FontSize="16" VerticalAlignment="Center"
214-
IsVisible="{Binding IsPaneOpen}"/>
201+
IsVisible="{Binding $parent[local:SidebarView].ShowLabels}"/>
215202
</StackPanel>
216203
<Button.Flyout>
217204
<MenuFlyout Placement="RightEdgeAlignedTop">

‎src/UniGetUI.Avalonia/Views/SidebarView.axaml.cs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Avalonia;
12
using Avalonia.Controls;
23
using Avalonia.Input;
34
using UniGetUI.Avalonia.ViewModels;
@@ -8,6 +9,20 @@ public partial class SidebarView : BaseView<SidebarViewModel>
89
{
910
private bool _lastNavItemSelectionWasAuto;
1011

12+
/// <summary>
13+
/// Whether the nav item text labels are shown. False renders an icon-only rail; true renders the
14+
/// full labeled pane. Decoupled from the view-model's pane state so the same view can be used both
15+
/// as the always-visible rail and as the sliding flyout simultaneously.
16+
/// </summary>
17+
public static readonly StyledProperty<bool> ShowLabelsProperty =
18+
AvaloniaProperty.Register<SidebarView, bool>(nameof(ShowLabels), defaultValue: true);
19+
20+
public bool ShowLabels
21+
{
22+
get => GetValue(ShowLabelsProperty);
23+
set => SetValue(ShowLabelsProperty, value);
24+
}
25+
1126
public SidebarView()
1227
{
1328
InitializeComponent();

0 commit comments

Comments
 (0)