AvaloniaNativePlatformExtensions.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using Avalonia.Controls;
  3. using Avalonia.Native;
  4. namespace Avalonia
  5. {
  6. public static class AvaloniaNativePlatformExtensions
  7. {
  8. public static T UseAvaloniaNative<T>(this T builder)
  9. where T : AppBuilderBase<T>, new()
  10. {
  11. builder.UseWindowingSubsystem(() =>
  12. {
  13. var platform = AvaloniaNativePlatform.Initialize(
  14. AvaloniaLocator.Current.GetService<AvaloniaNativePlatformOptions>() ??
  15. new AvaloniaNativePlatformOptions());
  16. builder.AfterSetup (x=>
  17. {
  18. platform.SetupApplicationName();
  19. platform.SetupApplicationMenuExporter();
  20. });
  21. });
  22. return builder;
  23. }
  24. }
  25. /// <summary>
  26. /// OSX backend options.
  27. /// </summary>
  28. public class AvaloniaNativePlatformOptions
  29. {
  30. /// <summary>
  31. /// Deferred renderer would be used when set to true. Immediate renderer when set to false. The default value is true.
  32. /// </summary>
  33. /// <remarks>
  34. /// Avalonia has two rendering modes: Immediate and Deferred rendering.
  35. /// Immediate re-renders the whole scene when some element is changed on the scene. Deferred re-renders only changed elements.
  36. /// </remarks>
  37. public bool UseDeferredRendering { get; set; } = true;
  38. /// <summary>
  39. /// Determines whether to use GPU for rendering in your project. The default value is true.
  40. /// </summary>
  41. public bool UseGpu { get; set; } = true;
  42. /// <summary>
  43. /// Embeds popups to the window when set to true. The default value is false.
  44. /// </summary>
  45. public bool OverlayPopups { get; set; }
  46. /// <summary>
  47. /// This property should be used in case you want to build Avalonia OSX native part by yourself
  48. /// and make your Avalonia app run with it. The default value is null.
  49. /// </summary>
  50. public string AvaloniaNativeLibraryPath { get; set; }
  51. }
  52. // ReSharper disable once InconsistentNaming
  53. /// <summary>
  54. /// OSX front-end options.
  55. /// </summary>
  56. public class MacOSPlatformOptions
  57. {
  58. /// <summary>
  59. /// Determines whether to show your application in the dock when it runs. The default value is true.
  60. /// </summary>
  61. public bool ShowInDock { get; set; } = true;
  62. /// <summary>
  63. /// By default, Avalonia adds items like Quit, Hide to the OSX Application Menu.
  64. /// You can prevent Avalonia from adding those items to the OSX Application Menu with this property. The default value is false.
  65. /// </summary>
  66. public bool DisableDefaultApplicationMenuItems { get; set; }
  67. /// <summary>
  68. /// Gets or sets a value indicating whether the native macOS menu bar will be enabled for the application.
  69. /// </summary>
  70. public bool DisableNativeMenus { get; set; }
  71. }
  72. }