Skip to content

Commit

Permalink
#117 center window, if no settings present
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Mar 8, 2024
1 parent a6bff20 commit 77e51ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
22 changes: 18 additions & 4 deletions src/PicView.WPF/UILogic/Loading/StartLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ internal static async Task LoadedEvent(Startup_Window startupWindow)

// Load sizing properties
MonitorInfo = MonitorSize.GetMonitorSize(startupWindow);
await SettingsHelper.LoadSettingsAsync().ConfigureAwait(false);
if (SettingsHelper.Settings.WindowProperties.AutoFit == false && SettingsHelper.Settings.WindowProperties.Fullscreen == false)
var settingsExist = await SettingsHelper.LoadSettingsAsync().ConfigureAwait(false);
if (settingsExist)
{
SetLastWindowSize(startupWindow);
if (SettingsHelper.Settings.WindowProperties.AutoFit == false && SettingsHelper.Settings.WindowProperties.Fullscreen == false)
{
SetLastWindowSize(startupWindow);
}
else
{
CenterWindowOnScreen(startupWindow);
}
}
else
{
Expand Down Expand Up @@ -95,7 +102,14 @@ await startupWindow.Dispatcher.InvokeAsync(() =>
SetWindowBehavior();
if (SettingsHelper.Settings.WindowProperties.AutoFit == false)
{
SetLastWindowSize(mainWindow);
if (!settingsExist)
{
CenterWindowOnScreen(mainWindow);
}
else
{
SetLastWindowSize(mainWindow);
}
}

mainWindow.Scroller.VerticalScrollBarVisibility = SettingsHelper.Settings.Zoom.ScrollEnabled
Expand Down
10 changes: 4 additions & 6 deletions src/PicView.WPF/UILogic/Sizing/WindowSizing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,11 @@ internal static void CenterWindowOnScreen(Window window, bool horizontal = true)
{
window?.Dispatcher.Invoke(() =>
{
window.Top =
((MonitorInfo.WorkArea.Height * MonitorInfo.DpiScaling) - window.ActualHeight) / 2 +
MonitorInfo.WorkArea.Top;
var width = window.ActualWidth == 0 ? window.Width : window.ActualWidth;
width = double.IsNaN(width) ? window.MinWidth : width;
window.Top = (MonitorInfo.WorkArea.Height * MonitorInfo.DpiScaling - width) / 2 + MonitorInfo.WorkArea.Top;
if (horizontal)
window.Left =
((MonitorInfo.WorkArea.Width * MonitorInfo.DpiScaling) - window.ActualWidth) / 2 +
MonitorInfo.WorkArea.Left;
window.Left = (MonitorInfo.WorkArea.Width * MonitorInfo.DpiScaling - width) / 2 + MonitorInfo.WorkArea.Left;
});
}

Expand Down

0 comments on commit 77e51ef

Please sign in to comment.