Implement menubar items for common window sizes.

This commit is contained in:
MutantAura 2024-04-29 20:16:08 +01:00
parent 3bea3ea077
commit 6c5f105ec1
4 changed files with 47 additions and 9 deletions

View file

@ -30,6 +30,10 @@
"MenuBarToolsManageFileTypes": "Manage file types",
"MenuBarToolsInstallFileTypes": "Install file types",
"MenuBarToolsUninstallFileTypes": "Uninstall file types",
"MenuBarView": "_View",
"MenuBarViewWindow": "Window Size",
"MenuBarViewWindow720": "720p",
"MenuBarViewWindow1080": "1080p",
"MenuBarHelp": "_Help",
"MenuBarHelpCheckForUpdates": "Check for Updates",
"MenuBarHelpAbout": "About",

View file

@ -186,6 +186,12 @@
<MenuItem Header="{locale:Locale MenuBarToolsUninstallFileTypes}" Click="UninstallFileTypes_Click"/>
</MenuItem>
</MenuItem>
<MenuItem VerticalAlignment="Center" Header="{locale:Locale MenuBarView}">
<MenuItem VerticalAlignment="Center" Header="{locale:Locale MenuBarViewWindow}">
<MenuItem Header="{locale:Locale MenuBarViewWindow720}" Tag="720" Click="ChangeWindowSize_Click" />
<MenuItem Header="{locale:Locale MenuBarViewWindow1080}" Tag="1080" Click="ChangeWindowSize_Click" />
</MenuItem>
</MenuItem>
<MenuItem VerticalAlignment="Center" Header="{locale:Locale MenuBarHelp}">
<MenuItem
Name="UpdateMenuItem"

View file

@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
using LibHac.Ncm;
using LibHac.Tools.FsSystem.NcaUtils;
using Ryujinx.Ava.Common.Locale;
@ -211,6 +212,37 @@ namespace Ryujinx.Ava.UI.Views.Main
}
}
private async void ChangeWindowSize_Click(object sender, RoutedEventArgs e)
{
if (sender is MenuItem item)
{
int height;
int width;
switch (item.Tag)
{
case "720":
height = 720;
width = 1280;
break;
case "1080":
height = 1080;
width = 1920;
break;
default:
throw new ArgumentNullException(nameof(item.Tag));
}
await Dispatcher.UIThread.InvokeAsync(() =>
{
ViewModel.WindowHeight = height + Window.StatusBarHeight + Window.MenuBarHeight;
ViewModel.WindowWidth = width;
});
}
}
public async void CheckForUpdates(object sender, RoutedEventArgs e)
{
if (Updater.CanUpdate(true))

View file

@ -67,11 +67,11 @@ namespace Ryujinx.Ava.UI.Windows
DataContext = ViewModel;
SetWindowSizePosition();
InitializeComponent();
Load();
SetWindowSizePosition();
UiHandler = new AvaHostUIHandler(this);
ViewModel.Title = $"Ryujinx {Program.Version}";
@ -324,17 +324,13 @@ namespace Ryujinx.Ava.UI.Windows
private void SetWindowSizePosition()
{
// WindowStartupLocation is unable to be used after the MainWindow is created.
// To center a window manually we need the raw display dimensions.
PixelPoint windowCenter = new(Screens.Primary.Bounds.Width / 4, Screens.Primary.Bounds.Height / 4);
if (!ConfigurationState.Instance.RememberWindowState)
{
ViewModel.WindowHeight = 777 * Program.WindowScaleFactor;
ViewModel.WindowWidth = 1280 * Program.WindowScaleFactor;
WindowState = WindowState.Normal;
Position = windowCenter;
WindowStartupLocation = WindowStartupLocation.CenterScreen;
return;
}
@ -353,7 +349,7 @@ namespace Ryujinx.Ava.UI.Windows
}
else
{
Position = windowCenter;
WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
}