StyleableWindow.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Controls.Primitives;
  4. using Avalonia.Input;
  5. using Avalonia.Media;
  6. using Avalonia.Platform;
  7. using FluentAvalonia.UI.Windowing;
  8. using Ryujinx.Ava.Common.Locale;
  9. using Ryujinx.Ava.UI.ViewModels;
  10. using System.Threading.Tasks;
  11. namespace Ryujinx.Ava.UI.Windows
  12. {
  13. public abstract class StyleableAppWindow : AppWindow
  14. {
  15. public static async Task ShowAsync(StyleableAppWindow appWindow, Window owner = null)
  16. {
  17. #if DEBUG
  18. appWindow.AttachDevTools(new KeyGesture(Key.F12, KeyModifiers.Control));
  19. #endif
  20. await appWindow.ShowDialog(owner ?? RyujinxApp.MainWindow);
  21. }
  22. protected StyleableAppWindow()
  23. {
  24. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  25. TransparencyLevelHint = [WindowTransparencyLevel.None];
  26. LocaleManager.Instance.LocaleChanged += LocaleChanged;
  27. LocaleChanged();
  28. Icon = MainWindowViewModel.IconBitmap;
  29. }
  30. private void LocaleChanged()
  31. {
  32. FlowDirection = LocaleManager.Instance.IsRTL() ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
  33. }
  34. protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
  35. {
  36. base.OnApplyTemplate(e);
  37. ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome | ExtendClientAreaChromeHints.OSXThickTitleBar;
  38. }
  39. }
  40. public abstract class StyleableWindow : Window
  41. {
  42. public static async Task ShowAsync(StyleableWindow window, Window owner = null)
  43. {
  44. #if DEBUG
  45. window.AttachDevTools(new KeyGesture(Key.F12, KeyModifiers.Control));
  46. #endif
  47. await window.ShowDialog(owner ?? RyujinxApp.MainWindow);
  48. }
  49. protected StyleableWindow()
  50. {
  51. WindowStartupLocation = WindowStartupLocation.CenterOwner;
  52. TransparencyLevelHint = [WindowTransparencyLevel.None];
  53. LocaleManager.Instance.LocaleChanged += LocaleChanged;
  54. LocaleChanged();
  55. Icon = new WindowIcon(MainWindowViewModel.IconBitmap);
  56. }
  57. private void LocaleChanged()
  58. {
  59. FlowDirection = LocaleManager.Instance.IsRTL() ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
  60. }
  61. protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
  62. {
  63. base.OnApplyTemplate(e);
  64. ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.SystemChrome | ExtendClientAreaChromeHints.OSXThickTitleBar;
  65. }
  66. }
  67. }