2024-08-19 14:30:11 +00:00
|
|
|
|
|
2024-08-22 23:59:16 +00:00
|
|
|
|
using Microsoft.UI.Input;
|
2024-08-17 23:27:24 +00:00
|
|
|
|
using Microsoft.UI.Xaml;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
|
|
|
|
using Microsoft.UI.Xaml.Input;
|
|
|
|
|
|
|
|
|
|
using RustTools.Contracts.Services;
|
|
|
|
|
using RustTools.Helpers;
|
2024-08-17 23:27:24 +00:00
|
|
|
|
using RustTools.muqing;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
using RustTools.ViewModels;
|
2024-08-22 23:59:16 +00:00
|
|
|
|
using Windows.Foundation;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
using Windows.System;
|
|
|
|
|
|
|
|
|
|
namespace RustTools.Views;
|
|
|
|
|
|
|
|
|
|
// TODO: Update NavigationViewItem titles and icons in ShellPage.xaml.
|
|
|
|
|
public sealed partial class ShellPage : Page
|
|
|
|
|
{
|
|
|
|
|
public ShellViewModel ViewModel
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ShellPage(ShellViewModel viewModel)
|
|
|
|
|
{
|
|
|
|
|
ViewModel = viewModel;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
ViewModel.NavigationService.Frame = NavigationFrame;
|
2024-08-22 23:59:16 +00:00
|
|
|
|
//ViewModel.NavigationService.UnregisterFrameEvents();
|
2024-07-14 11:24:10 +00:00
|
|
|
|
ViewModel.NavigationViewService.Initialize(NavigationViewControl);
|
|
|
|
|
|
|
|
|
|
// TODO: Set the title bar icon by updating /Assets/WindowIcon.ico.
|
|
|
|
|
// A custom title bar is required for full window theme and Mica support.
|
|
|
|
|
// https://docs.microsoft.com/windows/apps/develop/title-bar?tabs=winui3#full-customization
|
2024-08-17 06:41:34 +00:00
|
|
|
|
if (App.MainWindow != null)
|
|
|
|
|
{
|
|
|
|
|
App.MainWindow.SetTitleBar(AppTitleBar);
|
|
|
|
|
App.MainWindow.Activated += MainWindow_Activated;
|
|
|
|
|
}
|
2024-08-22 23:59:16 +00:00
|
|
|
|
AppTitleBarText.Text = "app_name".GetLocalized() + " PC";//+ "app_version".GetLocalized();
|
2024-07-14 11:24:10 +00:00
|
|
|
|
}
|
2024-08-22 23:59:16 +00:00
|
|
|
|
private void OnLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
2024-08-17 23:27:24 +00:00
|
|
|
|
{
|
2024-08-22 23:59:16 +00:00
|
|
|
|
if (App.MainWindow?.ExtendsContentIntoTitleBar == true)
|
2024-08-17 23:27:24 +00:00
|
|
|
|
{
|
2024-08-22 23:59:16 +00:00
|
|
|
|
// Update interactive regions if the size of the window changes.
|
|
|
|
|
SetRegionsForCustomTitleBar();
|
2024-08-17 23:27:24 +00:00
|
|
|
|
}
|
2024-08-22 23:59:16 +00:00
|
|
|
|
//TitleBarHelper.UpdateTitleBar(RequestedTheme);
|
|
|
|
|
|
|
|
|
|
//KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu));
|
|
|
|
|
//KeyboardAccelerators.Add(BuildKeyboardAccelerator(VirtualKey.GoBack));
|
2024-08-17 23:27:24 +00:00
|
|
|
|
}
|
2024-08-22 23:59:16 +00:00
|
|
|
|
|
|
|
|
|
private void SetRegionsForCustomTitleBar()
|
2024-08-17 23:27:24 +00:00
|
|
|
|
{
|
2024-08-22 23:59:16 +00:00
|
|
|
|
// Specify the interactive regions of the title bar.
|
|
|
|
|
var m_AppWindow = App.MainWindow?.AppWindow;
|
|
|
|
|
if (m_AppWindow == null) { return; }
|
|
|
|
|
var scaleAdjustment = AppTitleBar.XamlRoot.RasterizationScale;
|
|
|
|
|
var transform = TitleBarSearchBox.TransformToVisual(null);
|
|
|
|
|
var bounds = transform.TransformBounds(new Rect(0, 0,
|
|
|
|
|
TitleBarSearchBox.ActualWidth,
|
|
|
|
|
TitleBarSearchBox.ActualHeight));
|
|
|
|
|
Windows.Graphics.RectInt32 SearchBoxRect = GetRect(bounds, scaleAdjustment);
|
|
|
|
|
|
|
|
|
|
var rectArray = new Windows.Graphics.RectInt32[] { SearchBoxRect };
|
|
|
|
|
|
|
|
|
|
InputNonClientPointerSource nonClientInputSrc =
|
|
|
|
|
InputNonClientPointerSource.GetForWindowId(m_AppWindow.Id);
|
|
|
|
|
nonClientInputSrc.SetRegionRects(NonClientRegionKind.Passthrough, rectArray);
|
2024-08-17 23:27:24 +00:00
|
|
|
|
}
|
2024-07-14 11:24:10 +00:00
|
|
|
|
|
2024-08-22 23:59:16 +00:00
|
|
|
|
private Windows.Graphics.RectInt32 GetRect(Rect bounds, double scale)
|
|
|
|
|
{
|
|
|
|
|
return new Windows.Graphics.RectInt32(
|
|
|
|
|
_X: (int)Math.Round(bounds.X * scale),
|
|
|
|
|
_Y: (int)Math.Round(bounds.Y * scale),
|
|
|
|
|
_Width: (int)Math.Round(bounds.Width * scale),
|
|
|
|
|
_Height: (int)Math.Round(bounds.Height * scale)
|
|
|
|
|
);
|
2024-07-14 11:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainWindow_Activated(object sender, WindowActivatedEventArgs args)
|
|
|
|
|
{
|
2024-08-17 06:41:34 +00:00
|
|
|
|
App.AppTitlebar = AppTitleBarText;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-22 23:59:16 +00:00
|
|
|
|
//DisplayModeChanged="NavigationViewControl_DisplayModeChanged"
|
2024-07-14 11:24:10 +00:00
|
|
|
|
private void NavigationViewControl_DisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
AppTitleBar.Margin = new Thickness()
|
|
|
|
|
{
|
|
|
|
|
Left = sender.CompactPaneLength * (sender.DisplayMode == NavigationViewDisplayMode.Minimal ? 2 : 1),
|
2024-08-22 23:59:16 +00:00
|
|
|
|
//Left = sender.CompactPaneLength,
|
2024-07-14 11:24:10 +00:00
|
|
|
|
Top = AppTitleBar.Margin.Top,
|
|
|
|
|
Right = AppTitleBar.Margin.Right,
|
|
|
|
|
Bottom = AppTitleBar.Margin.Bottom
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static KeyboardAccelerator BuildKeyboardAccelerator(VirtualKey key, VirtualKeyModifiers? modifiers = null)
|
|
|
|
|
{
|
|
|
|
|
var keyboardAccelerator = new KeyboardAccelerator() { Key = key };
|
|
|
|
|
|
|
|
|
|
if (modifiers.HasValue)
|
|
|
|
|
{
|
|
|
|
|
keyboardAccelerator.Modifiers = modifiers.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
keyboardAccelerator.Invoked += OnKeyboardAcceleratorInvoked;
|
|
|
|
|
|
|
|
|
|
return keyboardAccelerator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void OnKeyboardAcceleratorInvoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var navigationService = App.GetService<INavigationService>();
|
|
|
|
|
|
|
|
|
|
var result = navigationService.GoBack();
|
|
|
|
|
|
|
|
|
|
args.Handled = result;
|
|
|
|
|
}
|
2024-08-17 23:27:24 +00:00
|
|
|
|
|
2024-08-22 23:59:16 +00:00
|
|
|
|
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (App.MainWindow?.ExtendsContentIntoTitleBar == true)
|
|
|
|
|
{
|
|
|
|
|
// Update interactive regions if the size of the window changes.
|
|
|
|
|
SetRegionsForCustomTitleBar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TitleBarSearchBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var text = sender.Text;
|
|
|
|
|
NavigationFrame.Navigate(typeof(SearchModPage),text);
|
|
|
|
|
NavigationFrame.BackStack.Clear();
|
|
|
|
|
//ViewModel.NavigationService.Frame.Visibility= Visibility.Collapsed;
|
|
|
|
|
}
|
2024-07-14 11:24:10 +00:00
|
|
|
|
}
|