using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Media; using System; using Avalonia.Collections; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Interactivity; using SukiUI.Enums; namespace SukiUI.Controls; public class SukiWindow : Window { protected override Type StyleKeyOverride => typeof(SukiWindow); public static readonly StyledProperty TitleFontSizeProperty = AvaloniaProperty.Register(nameof(TitleFontSize), defaultValue: 13); public double TitleFontSize { get => GetValue(TitleFontSizeProperty); set => SetValue(TitleFontSizeProperty, value); } public static readonly StyledProperty TitleFontWeightProperty = AvaloniaProperty.Register(nameof(TitleFontWeight), defaultValue: FontWeight.Bold); public FontWeight TitleFontWeight { get => GetValue(TitleFontWeightProperty); set => SetValue(TitleFontWeightProperty, value); } public static readonly StyledProperty LogoContentProperty = AvaloniaProperty.Register(nameof(LogoContent)); public Control? LogoContent { get => GetValue(LogoContentProperty); set => SetValue(LogoContentProperty, value); } public static readonly StyledProperty ShowBottomBorderProperty = AvaloniaProperty.Register(nameof(ShowBottomBorder), defaultValue: true); public bool ShowBottomBorder { get => GetValue(ShowBottomBorderProperty); set => SetValue(ShowBottomBorderProperty, value); } public static readonly StyledProperty IsTitleBarVisibleProperty = AvaloniaProperty.Register(nameof(IsTitleBarVisible), defaultValue: true); public bool IsTitleBarVisible { get => GetValue(IsTitleBarVisibleProperty); set => SetValue(IsTitleBarVisibleProperty, value); } public static readonly StyledProperty TitleBarAnimationEnabledProperty = AvaloniaProperty.Register(nameof(TitleBarAnimationEnabled), defaultValue: true); public bool TitleBarAnimationEnabled { get => GetValue(TitleBarAnimationEnabledProperty); set => SetValue(TitleBarAnimationEnabledProperty, value); } public static readonly StyledProperty IsMenuVisibleProperty = AvaloniaProperty.Register(nameof(IsMenuVisible), defaultValue: false); public bool IsMenuVisible { get => GetValue(IsMenuVisibleProperty); set => SetValue(IsMenuVisibleProperty, value); } public static readonly StyledProperty?> MenuItemsProperty = AvaloniaProperty.Register?>(nameof(MenuItems)); public AvaloniaList? MenuItems { get => GetValue(MenuItemsProperty); set => SetValue(MenuItemsProperty, value); } public static readonly StyledProperty CanMinimizeProperty = AvaloniaProperty.Register(nameof(CanMinimize), defaultValue: true); public bool CanMinimize { get => GetValue(CanMinimizeProperty); set => SetValue(CanMinimizeProperty, value); } public static readonly StyledProperty CanMaximizeProperty = AvaloniaProperty.Register(nameof(CanMaximize), defaultValue: true); public bool CanMaximize { get => GetValue(CanMaximizeProperty); set => SetValue(CanMaximizeProperty, value); } public static readonly StyledProperty CanMoveProperty = AvaloniaProperty.Register(nameof(CanMove), defaultValue: true); public bool CanMove { get => GetValue(CanMoveProperty); set => SetValue(CanMoveProperty, value); } // Background properties public static readonly StyledProperty BackgroundAnimationEnabledProperty = AvaloniaProperty.Register(nameof(BackgroundAnimationEnabled), defaultValue: false); /// public bool BackgroundAnimationEnabled { get => GetValue(BackgroundAnimationEnabledProperty); set => SetValue(BackgroundAnimationEnabledProperty, value); } public static readonly StyledProperty BackgroundStyleProperty = AvaloniaProperty.Register(nameof(BackgroundStyle), defaultValue: SukiBackgroundStyle.GradientSoft); /// public SukiBackgroundStyle BackgroundStyle { get => GetValue(BackgroundStyleProperty); set => SetValue(BackgroundStyleProperty, value); } public static readonly StyledProperty BackgroundShaderFileProperty = AvaloniaProperty.Register(nameof(BackgroundShaderFile)); /// public string? BackgroundShaderFile { get => GetValue(BackgroundShaderFileProperty); set => SetValue(BackgroundShaderFileProperty, value); } public static readonly StyledProperty BackgroundShaderCodeProperty = AvaloniaProperty.Register(nameof(BackgroundShaderCode)); /// public string? BackgroundShaderCode { get => GetValue(BackgroundShaderCodeProperty); set => SetValue(BackgroundShaderCodeProperty, value); } public static readonly StyledProperty BackgroundTransitionsEnabledProperty = AvaloniaProperty.Register(nameof(BackgroundTransitionsEnabled), defaultValue: false); /// public bool BackgroundTransitionsEnabled { get => GetValue(BackgroundTransitionsEnabledProperty); set => SetValue(BackgroundTransitionsEnabledProperty, value); } public static readonly StyledProperty BackgroundTransitionTimeProperty = AvaloniaProperty.Register(nameof(BackgroundTransitionTime), defaultValue: 1.0); /// public double BackgroundTransitionTime { get => GetValue(BackgroundTransitionTimeProperty); set => SetValue(BackgroundTransitionTimeProperty, value); } public static readonly StyledProperty RightWindowTitleBarControlsProperty = AvaloniaProperty.Register(nameof(RightWindowTitleBarControls), defaultValue: new Avalonia.Controls.Controls()); public static readonly StyledProperty BackgroundForceSoftwareRenderingProperty = AvaloniaProperty.Register(nameof(BackgroundForceSoftwareRendering)); /// /// Forces the background of the window to utilise software rendering. /// This prevents use of any advanced effects or animations and provides only a flat background colour that changes with the theme. /// public bool BackgroundForceSoftwareRendering { get => GetValue(BackgroundForceSoftwareRenderingProperty); set => SetValue(BackgroundForceSoftwareRenderingProperty, value); } /// /// Controls that are displayed on the right side of the title bar, /// to the left of the normal window control buttons. (Displays provided controls right-to-left) /// public Avalonia.Controls.Controls RightWindowTitleBarControls { get => GetValue(RightWindowTitleBarControlsProperty); set => SetValue(RightWindowTitleBarControlsProperty, value); } public static readonly StyledProperty HostsProperty = AvaloniaProperty.Register(nameof(Hosts), defaultValue: new Avalonia.Controls.Controls()); /// /// These controls are displayed above all others and fill the entire window. /// You can include and or create your own custom implementations. /// public Avalonia.Controls.Controls Hosts { get => GetValue(HostsProperty); set => SetValue(HostsProperty, value); } public SukiWindow() { MenuItems = new AvaloniaList(); RightWindowTitleBarControls = new Avalonia.Controls.Controls(); Hosts = new Avalonia.Controls.Controls(); } protected override void OnLoaded(RoutedEventArgs e) { base.OnLoaded(e); if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return; if (desktop.MainWindow is SukiWindow window && window != this) { Icon ??= window.Icon; // This would be nice to do, but obviously LogoContent is a control and you can't attach it twice. // if (LogoContent is null) LogoContent = s.LogoContent; } } protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { base.OnPropertyChanged(change); if (change.Property == WindowStateProperty && change.NewValue is WindowState windowState) OnWindowStateChanged(windowState); } protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); OnWindowStateChanged(WindowState); try { // Create handlers for buttons if (e.NameScope.Get