diff --git a/NAPS2.Lib/Config/CommonConfig.cs b/NAPS2.Lib/Config/CommonConfig.cs index 01ef5cbfb3..ee51bbd24a 100644 --- a/NAPS2.Lib/Config/CommonConfig.cs +++ b/NAPS2.Lib/Config/CommonConfig.cs @@ -203,4 +203,10 @@ public class CommonConfig [Common] public bool DisableScannerSharing { get; set; } + + [User] + public bool SidebarVisible { get; set; } + + [User] + public int SidebarWidth { get; set; } } \ No newline at end of file diff --git a/NAPS2.Lib/Config/InternalDefaults.cs b/NAPS2.Lib/Config/InternalDefaults.cs index 3859b421b4..f68bb544fa 100644 --- a/NAPS2.Lib/Config/InternalDefaults.cs +++ b/NAPS2.Lib/Config/InternalDefaults.cs @@ -58,6 +58,7 @@ public static CommonConfig GetCommonConfig() => DesktopToolStripDock = DockStyle.Top, EventLogging = EventType.None, ShowPageNumbers = false, + SidebarVisible = true, PdfSettings = new PdfSettings { Metadata = new PdfMetadata diff --git a/NAPS2.Lib/EtoForms/Desktop/Sidebar.cs b/NAPS2.Lib/EtoForms/Desktop/Sidebar.cs index 4245d15008..3cb2fa7bfc 100644 --- a/NAPS2.Lib/EtoForms/Desktop/Sidebar.cs +++ b/NAPS2.Lib/EtoForms/Desktop/Sidebar.cs @@ -88,6 +88,7 @@ private void NewProfile() public LayoutElement CreateView(IFormBase parentWindow) { + _sidebarVis.IsVisible = _config.Get(c => c.SidebarVisible); _profile.SelectedItem = _profileManager.DefaultProfile; _deviceSelectorWidget = new DeviceSelectorWidget(_scanPerformer, _deviceCapsCache, _iconProvider, parentWindow) @@ -217,5 +218,6 @@ private void UpdateUiForProfile() public void ToggleVisibility() { _sidebarVis.IsVisible = !_sidebarVis.IsVisible; + _config.User.Set(c => c.SidebarVisible, _sidebarVis.IsVisible); } } \ No newline at end of file diff --git a/NAPS2.Lib/EtoForms/Layout/L.cs b/NAPS2.Lib/EtoForms/Layout/L.cs index 4dabcc312e..c492aa9efc 100644 --- a/NAPS2.Lib/EtoForms/Layout/L.cs +++ b/NAPS2.Lib/EtoForms/Layout/L.cs @@ -56,7 +56,7 @@ public static LayoutElement Buffer(LayoutElement element, int left, int top, int return new BufferLayoutElement(element, left, top, right, bottom); } - public static LayoutElement LeftPanel(LayoutElement left, LayoutElement right) + public static LayoutLeftPanel LeftPanel(LayoutElement left, LayoutElement right) { return new LayoutLeftPanel(left, right); } diff --git a/NAPS2.Lib/EtoForms/Layout/LayoutLeftPanel.cs b/NAPS2.Lib/EtoForms/Layout/LayoutLeftPanel.cs index ef455b9471..fa9a7afdc9 100644 --- a/NAPS2.Lib/EtoForms/Layout/LayoutLeftPanel.cs +++ b/NAPS2.Lib/EtoForms/Layout/LayoutLeftPanel.cs @@ -10,6 +10,8 @@ public class LayoutLeftPanel : LayoutElement private readonly LayoutOverlay _overlay; private readonly Splitter _splitter; + private Func _widthGetter = () => 0; + private Action _widthSetter = _ => { }; private bool _isInitialized; public LayoutLeftPanel(LayoutElement left, LayoutElement right) @@ -37,12 +39,13 @@ public override void DoLayout(LayoutContext context, RectangleF bounds) if (!_isInitialized) { - _left.Width = _splitter.Position = _splitter.Panel1MinimumSize; + _left.Width = _splitter.Position = Math.Max(_widthGetter(), _splitter.Panel1MinimumSize); _splitter.PositionChanged += (_, _) => { if (_left.Width != _splitter.Position) { _left.Width = _splitter.Position; + _widthSetter(_splitter.Position); context.Invalidate(); } }; @@ -74,4 +77,11 @@ protected override SizeF GetPreferredSizeCore(LayoutContext context, RectangleF { return _overlay.GetPreferredSize(context, parentBounds); } + + public LayoutLeftPanel SizeConfig(Func getter, Action setter) + { + _widthGetter = getter; + _widthSetter = setter; + return this; + } } \ No newline at end of file diff --git a/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs b/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs index 82b1a99f80..46d1a279af 100644 --- a/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs +++ b/NAPS2.Lib/EtoForms/Ui/DesktopForm.cs @@ -135,7 +135,9 @@ protected override void BuildLayout() _notificationArea.Content) ).Padding(8) ).Scale() - ); + ).SizeConfig( + () => Config.Get(c => c.SidebarWidth), + width => Config.User.Set(c => c.SidebarWidth, width)); } private void OpeningContextMenu(object? sender, EventArgs e)