Skip to content

Commit 8c235b8

Browse files
authored
Restore dockable navigation pane with adaptive/docked/overlay modes (#5063)
1 parent 200feea commit 8c235b8

7 files changed

Lines changed: 126 additions & 39 deletions

File tree

‎src/Languages/lang_en.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"Navigation menu:": "Navigation menu:",
3+
"Automatic": "Automatic",
4+
"Docked open": "Docked open",
5+
"Sliding overlay": "Sliding overlay",
26
"{0} of {1} operations completed": "{0} of {1} operations completed",
37
"{0} is now {1}": "{0} is now {1}",
48
"Enabled": "Enabled",

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

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ public partial class SidebarViewModel : ViewModelBase
2424
partial void OnUpdatesBadgeCountChanged(int value) =>
2525
UpdatesBadgeVisible = value > 0;
2626

27-
partial void OnUpdatesBadgeVisibleChanged(bool value)
28-
{
29-
OnPropertyChanged(nameof(UpdatesBadgeExpandedVisible));
30-
OnPropertyChanged(nameof(UpdatesBadgeCompactVisible));
31-
}
32-
33-
partial void OnBundlesBadgeVisibleChanged(bool value)
34-
{
35-
OnPropertyChanged(nameof(BundlesBadgeExpandedVisible));
36-
OnPropertyChanged(nameof(BundlesBadgeCompactVisible));
37-
}
38-
3927
// ─── Loading indicators ───────────────────────────────────────────────────
4028
[ObservableProperty]
4129
private bool _discoverIsLoading;
@@ -47,31 +35,84 @@ partial void OnBundlesBadgeVisibleChanged(bool value)
4735
private bool _installedIsLoading;
4836

4937
// ─── 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.
38+
// NavMenuMode: Automatic mirrors WinUI (dock ≥1600px, else rail+overlay), Docked = always
39+
// inline, Overlay = always rail+overlay. IsPaneOpen = labeled pane showing, in any mode.
40+
public enum NavMode { Automatic, Docked, Overlay }
41+
42+
private const double ExpandedThreshold = 1600; // WinUI ExpandedModeThresholdWidth
43+
private const double CompactThreshold = 800; // WinUI CompactModeThresholdWidth
44+
45+
// Live window width, pushed by MainWindow's bounds observer.
5246
[ObservableProperty]
53-
private bool isPaneOpen;
47+
private double _windowWidth = 1450;
48+
49+
[ObservableProperty]
50+
private NavMode _mode = ParseMode(Settings.GetValue(Settings.K.NavMenuMode));
51+
52+
[ObservableProperty]
53+
private bool _isPaneOpen;
54+
55+
public static NavMode ParseMode(string value) => value switch
56+
{
57+
"docked" => NavMode.Docked,
58+
"overlay" => NavMode.Overlay,
59+
_ => NavMode.Automatic,
60+
};
61+
62+
// Whether the pane docks inline (vs. the rail + sliding overlay).
63+
public bool Docked => Mode switch
64+
{
65+
NavMode.Docked => true,
66+
NavMode.Overlay => false,
67+
_ => WindowWidth >= ExpandedThreshold,
68+
};
69+
70+
private bool RailAllowed => WindowWidth >= CompactThreshold;
71+
72+
// Icon rail vs docked labeled pane vs sliding overlay — mutually exclusive.
73+
public bool NavDockVisible => Docked && IsPaneOpen;
74+
public bool RailVisible => (Docked && !IsPaneOpen) || (!Docked && RailAllowed);
75+
public bool OverlayActive => !Docked && IsPaneOpen;
76+
77+
private bool _wasDocked;
78+
79+
public SidebarViewModel()
80+
{
81+
_wasDocked = Docked;
82+
_isPaneOpen = Docked && !Settings.Get(Settings.K.CollapseNavMenuOnWideScreen);
83+
}
84+
85+
partial void OnWindowWidthChanged(double value) => ReconcileDock();
5486

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;
87+
partial void OnModeChanged(NavMode value) => ReconcileDock();
88+
89+
// On a docked-state flip, open the pane by default (unless collapsed on a wide screen), or
90+
// collapse when leaving docked mode. Mirrors WinUI's startup IsPaneOpen logic.
91+
private void ReconcileDock()
92+
{
93+
bool docked = Docked;
94+
if (docked != _wasDocked)
95+
{
96+
_wasDocked = docked;
97+
IsPaneOpen = docked && !Settings.Get(Settings.K.CollapseNavMenuOnWideScreen);
98+
}
99+
RaiseLayoutChanged();
100+
}
60101

61102
partial void OnIsPaneOpenChanged(bool value)
62103
{
63-
if (PersistPaneCollapsePreference)
104+
// Persist the collapse choice only while docked (WinUI persisted only at ≥1600px).
105+
if (Docked)
64106
Settings.Set(Settings.K.CollapseNavMenuOnWideScreen, !value);
65-
OnPropertyChanged(nameof(UpdatesBadgeExpandedVisible));
66-
OnPropertyChanged(nameof(UpdatesBadgeCompactVisible));
67-
OnPropertyChanged(nameof(BundlesBadgeExpandedVisible));
68-
OnPropertyChanged(nameof(BundlesBadgeCompactVisible));
107+
RaiseLayoutChanged();
69108
}
70109

71-
public bool UpdatesBadgeExpandedVisible => UpdatesBadgeVisible && IsPaneOpen;
72-
public bool UpdatesBadgeCompactVisible => UpdatesBadgeVisible && !IsPaneOpen;
73-
public bool BundlesBadgeExpandedVisible => BundlesBadgeVisible && IsPaneOpen;
74-
public bool BundlesBadgeCompactVisible => BundlesBadgeVisible && !IsPaneOpen;
110+
private void RaiseLayoutChanged()
111+
{
112+
OnPropertyChanged(nameof(NavDockVisible));
113+
OnPropertyChanged(nameof(RailVisible));
114+
OnPropertyChanged(nameof(OverlayActive));
115+
}
75116

76117
// ─── Selected page ────────────────────────────────────────────────────────
77118
[ObservableProperty]

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@
6161
Background="{DynamicResource MicaPageBackground}"
6262
ColumnDefinitions="Auto,*">
6363

64-
<!-- ── Icon rail (always visible ≥800px; collapsed below) ── -->
64+
<!-- ── Icon rail (compact mode ≥800px, or docked-but-collapsed) ── -->
6565
<ContentControl x:Name="NavRail"
6666
Grid.Column="0"
6767
Width="64"
6868
ClipToBounds="True"
69+
IsVisible="{Binding Sidebar.RailVisible}"
6970
Content="{Binding Sidebar}"
7071
automation:AutomationProperties.AccessibilityView="Control"
7172
automation:AutomationProperties.Name="{t:Translate Navigation panel}"
@@ -79,6 +80,27 @@
7980
</ContentControl.DataTemplates>
8081
</ContentControl>
8182

83+
<!-- ── Docked labeled pane (Expanded ≥1600px, or NavMenuMode=Docked): sits inline, reflows content. ── -->
84+
<ContentControl x:Name="NavDock"
85+
Grid.Column="0"
86+
Width="250"
87+
ClipToBounds="True"
88+
IsVisible="{Binding Sidebar.NavDockVisible}"
89+
BorderBrush="{DynamicResource AppBorderBrush}"
90+
BorderThickness="0,0,1,0"
91+
Content="{Binding Sidebar}"
92+
automation:AutomationProperties.AccessibilityView="Control"
93+
automation:AutomationProperties.Name="{t:Translate Navigation panel}"
94+
automation:AutomationProperties.LandmarkType="{x:Static peers:AutomationLandmarkType.Navigation}"
95+
HorizontalContentAlignment="Stretch"
96+
VerticalContentAlignment="Stretch">
97+
<ContentControl.DataTemplates>
98+
<DataTemplate DataType="vm:SidebarViewModel">
99+
<views:SidebarView ShowLabels="True"/>
100+
</DataTemplate>
101+
</ContentControl.DataTemplates>
102+
</ContentControl>
103+
82104
<!-- ── Content: banners + page + operations ── -->
83105
<Grid x:Name="ContentRoot" Grid.Column="1" RowDefinitions="*,4,Auto">
84106

@@ -338,7 +360,7 @@
338360
Grid.Column="0" Grid.ColumnSpan="2"
339361
Background="Transparent"
340362
ZIndex="9"
341-
IsVisible="{Binding Sidebar.IsPaneOpen}"
363+
IsVisible="{Binding Sidebar.OverlayActive}"
342364
automation:AutomationProperties.AccessibilityView="Raw"
343365
PointerPressed="FlyoutDismiss_PointerPressed"/>
344366

@@ -350,8 +372,8 @@
350372
VerticalAlignment="Stretch"
351373
ZIndex="10"
352374
Background="{DynamicResource AppWindowBackground}"
353-
IsHitTestVisible="{Binding Sidebar.IsPaneOpen}"
354-
Classes.open="{Binding Sidebar.IsPaneOpen}">
375+
IsHitTestVisible="{Binding Sidebar.OverlayActive}"
376+
Classes.open="{Binding Sidebar.OverlayActive}">
355377
<Border.Transitions>
356378
<Transitions>
357379
<DoubleTransition Property="Opacity" Duration="0:0:0.18">

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ private void Window_KeyDown(object? sender, KeyEventArgs e)
259259
private void OnCurrentPageChanged(object? sender, PageType pageType)
260260
{
261261
// Like WinUI's NavigationView: picking a page collapses the sliding flyout back to the rail.
262-
ViewModel.Sidebar.IsPaneOpen = false;
262+
// A docked pane stays put (it's a persistent inline pane, not a transient overlay).
263+
if (!ViewModel.Sidebar.Docked)
264+
ViewModel.Sidebar.IsPaneOpen = false;
263265

264266
if (!_focusSidebarSelectionOnNextPageChange)
265267
return;
@@ -305,17 +307,21 @@ private void UpdateOperationsPanelRow()
305307
}
306308
}
307309

308-
// ─── Navigation rail (responsive) ─────────────────────────────────────────
309-
// The always-visible icon rail shows on roomy windows and collapses below 800px so narrow
310-
// windows give the content full width (the hamburger + sliding flyout still provide nav).
310+
// ─── Navigation rail / docked pane (responsive) ────────────────────────────
311+
// Feed the live window width to the sidebar, which resolves the layout mode and drives
312+
// the NavRail / NavDock / overlay visibility bindings.
311313
private void SetupResponsiveRail()
312314
=> MainContentRoot.GetObservable(BoundsProperty)
313315
.SubscribeValue(b =>
314316
{
315317
if (b.Width <= 0) return;
316-
NavRail.IsVisible = b.Width >= 800;
318+
ViewModel.Sidebar.WindowWidth = b.Width;
317319
});
318320

321+
// Re-reads the NavMenuMode setting so the layout switch applies live from the settings page.
322+
public void RefreshNavigationMode()
323+
=> ViewModel.Sidebar.Mode = SidebarViewModel.ParseMode(Settings.GetValue(Settings.K.NavMenuMode));
324+
319325
// Light-dismiss: clicking outside the open flyout closes it (no darkening — the layer is transparent).
320326
private void FlyoutDismiss_PointerPressed(object? sender, PointerPressedEventArgs e)
321327
=> ViewModel.Sidebar.IsPaneOpen = false;

‎src/UniGetUI.Avalonia/Views/Pages/SettingsPages/Interface_P.axaml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@
2323
CornerRadius="8,8,0,0"/>
2424

2525
<settings:ComboboxCard x:Name="StartupPageSelector"
26-
CornerRadius="0,0,8,8"
26+
CornerRadius="0"
2727
BorderThickness="1,0,1,1"/>
2828

29+
<settings:ComboboxCard x:Name="NavMenuModeSelector"
30+
CornerRadius="0,0,8,8"
31+
BorderThickness="1,0,1,1"/>
32+
2933
<Border Height="16"/>
3034

3135
<settings:TranslatedTextBlock Text="Rendering"

‎src/UniGetUI.Avalonia/Views/Pages/SettingsPages/Interface_P.axaml.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,13 @@ public Interface_P()
4343
StartupPageSelector.SettingName = CoreSettings.K.StartupPage;
4444
StartupPageSelector.Text = CoreTools.Translate("UniGetUI startup page:");
4545
StartupPageSelector.ShowAddedItems();
46+
47+
NavMenuModeSelector.AddItem(CoreTools.Translate("Automatic"), "auto");
48+
NavMenuModeSelector.AddItem(CoreTools.Translate("Docked open"), "docked");
49+
NavMenuModeSelector.AddItem(CoreTools.Translate("Sliding overlay"), "overlay");
50+
NavMenuModeSelector.SettingName = CoreSettings.K.NavMenuMode;
51+
NavMenuModeSelector.Text = CoreTools.Translate("Navigation menu:");
52+
NavMenuModeSelector.ShowAddedItems();
53+
NavMenuModeSelector.ValueChanged += (_, _) => MainWindow.Instance?.RefreshNavigationMode();
4654
}
4755
}

‎src/UniGetUI.Core.Settings/SettingsEngine_Names.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public enum K
3838
AlreadyWarnedAboutChocolateyMigration,
3939
ShownTelemetryBanner,
4040
CollapseNavMenuOnWideScreen,
41+
NavMenuMode,
4142
EnablePackageBackup_LOCAL,
4243
EnablePackageBackup_CLOUD,
4344
ChangeBackupOutputDirectory,
@@ -147,6 +148,7 @@ public static string ResolveKey(K key)
147148
K.AlreadyWarnedAboutChocolateyMigration => "AlreadyWarnedAboutChocolateyMigration",
148149
K.ShownTelemetryBanner => "ShownTelemetryBanner",
149150
K.CollapseNavMenuOnWideScreen => "CollapseNavMenuOnWideScreen",
151+
K.NavMenuMode => "NavMenuMode",
150152
K.EnablePackageBackup_LOCAL => "EnablePackageBackup",
151153
K.EnablePackageBackup_CLOUD => "EnablePackageBackup_CLOUD",
152154
K.ChangeBackupOutputDirectory => "ChangeBackupOutputDirectory",

0 commit comments

Comments
 (0)