From 9f64463060bb6a6214b48faffcda5f86f88de0e4 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 1 Jul 2020 15:17:10 -0300 Subject: [PATCH] fix nits. --- .../Chrome/CaptionButtons.cs | 10 ++-- src/Avalonia.Controls/Chrome/TitleBar.cs | 32 +++++----- src/Avalonia.Controls/Platform/IWindowImpl.cs | 60 +++++++++---------- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/Avalonia.Controls/Chrome/CaptionButtons.cs b/src/Avalonia.Controls/Chrome/CaptionButtons.cs index 58f5b09c0d..cc49b8b643 100644 --- a/src/Avalonia.Controls/Chrome/CaptionButtons.cs +++ b/src/Avalonia.Controls/Chrome/CaptionButtons.cs @@ -38,7 +38,7 @@ namespace Avalonia.Controls.Chrome { var layer = ChromeOverlayLayer.GetOverlayLayer(_hostWindow); - layer.Children.Remove(this); + layer?.Children.Remove(this); _disposables.Dispose(); _disposables = null; @@ -49,10 +49,10 @@ namespace Avalonia.Controls.Chrome { base.OnApplyTemplate(e); - var closeButton = e.NameScope.Find("PART_CloseButton"); - var restoreButton = e.NameScope.Find("PART_RestoreButton"); - var minimiseButton = e.NameScope.Find("PART_MinimiseButton"); - var fullScreenButton = e.NameScope.Find("PART_FullScreenButton"); + var closeButton = e.NameScope.Get("PART_CloseButton"); + var restoreButton = e.NameScope.Get("PART_RestoreButton"); + var minimiseButton = e.NameScope.Get("PART_MinimiseButton"); + var fullScreenButton = e.NameScope.Get("PART_FullScreenButton"); closeButton.PointerReleased += (sender, e) => _hostWindow.Close(); restoreButton.PointerReleased += (sender, e) => _hostWindow.WindowState = _hostWindow.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized; diff --git a/src/Avalonia.Controls/Chrome/TitleBar.cs b/src/Avalonia.Controls/Chrome/TitleBar.cs index 8e8010d3d4..70ab172cc6 100644 --- a/src/Avalonia.Controls/Chrome/TitleBar.cs +++ b/src/Avalonia.Controls/Chrome/TitleBar.cs @@ -26,36 +26,36 @@ namespace Avalonia.Controls.Chrome { var layer = ChromeOverlayLayer.GetOverlayLayer(_hostWindow); - layer.Children.Add(this); + layer?.Children.Add(this); _disposables = new CompositeDisposable { _hostWindow.GetObservable(Window.WindowDecorationMarginsProperty) - .Subscribe(x => InvalidateSize()), + .Subscribe(x => UpdateSize()), _hostWindow.GetObservable(Window.ExtendClientAreaTitleBarHeightHintProperty) - .Subscribe(x => InvalidateSize()), + .Subscribe(x => UpdateSize()), _hostWindow.GetObservable(Window.OffScreenMarginProperty) - .Subscribe(x => InvalidateSize()), + .Subscribe(x => UpdateSize()), _hostWindow.GetObservable(Window.WindowStateProperty) - .Subscribe(x => - { - PseudoClasses.Set(":minimized", x == WindowState.Minimized); - PseudoClasses.Set(":normal", x == WindowState.Normal); - PseudoClasses.Set(":maximized", x == WindowState.Maximized); - PseudoClasses.Set(":fullscreen", x == WindowState.FullScreen); - }) + .Subscribe(x => + { + PseudoClasses.Set(":minimized", x == WindowState.Minimized); + PseudoClasses.Set(":normal", x == WindowState.Normal); + PseudoClasses.Set(":maximized", x == WindowState.Maximized); + PseudoClasses.Set(":fullscreen", x == WindowState.FullScreen); + }) }; _captionButtons?.Attach(_hostWindow); - InvalidateSize(); + UpdateSize(); } } - void InvalidateSize() + void UpdateSize() { Margin = new Thickness( _hostWindow.OffScreenMargin.Left, @@ -80,7 +80,7 @@ namespace Avalonia.Controls.Chrome { var layer = ChromeOverlayLayer.GetOverlayLayer(_hostWindow); - layer.Children.Remove(this); + layer?.Children.Remove(this); _disposables.Dispose(); _disposables = null; @@ -93,11 +93,11 @@ namespace Avalonia.Controls.Chrome { base.OnApplyTemplate(e); - _captionButtons = e.NameScope.Find("PART_CaptionButtons"); + _captionButtons = e.NameScope.Get("PART_CaptionButtons"); _captionButtons.Attach(_hostWindow); - InvalidateSize(); + UpdateSize(); } } } diff --git a/src/Avalonia.Controls/Platform/IWindowImpl.cs b/src/Avalonia.Controls/Platform/IWindowImpl.cs index 43647dc7d0..8a1554d344 100644 --- a/src/Avalonia.Controls/Platform/IWindowImpl.cs +++ b/src/Avalonia.Controls/Platform/IWindowImpl.cs @@ -68,6 +68,34 @@ namespace Avalonia.Platform /// Func Closing { get; set; } + /// + /// Gets a value to indicate if the platform was able to extend client area to non-client area. + /// + bool IsClientAreaExtendedToDecorations { get; } + + /// + /// Gets or Sets an action that is called whenever one of the extend client area properties changed. + /// + Action ExtendClientAreaToDecorationsChanged { get; set; } + + /// + /// Gets a flag that indicates if Managed decorations i.e. caption buttons are required. + /// This property is used when is set. + /// + bool NeedsManagedDecorations { get; } + + /// + /// Gets a thickness that describes the amount each side of the non-client area extends into the client area. + /// It includes the titlebar. + /// + Thickness ExtendedMargins { get; } + + /// + /// Gets a thickness that describes the margin around the window that is offscreen. + /// This may happen when a window is maximized and is set. + /// + Thickness OffScreenMargin { get; } + /// /// Starts moving a window with left button being held. Should be called from left mouse button press event handler. /// @@ -99,12 +127,7 @@ namespace Avalonia.Platform /// Sets if the ClientArea is extended into the non-client area. /// /// true to enable, false to disable - void SetExtendClientAreaToDecorationsHint(bool extendIntoClientAreaHint); - - /// - /// Gets a value to indicate if the platform was able to extend client area to non-client area. - /// - bool IsClientAreaExtendedToDecorations { get; } + void SetExtendClientAreaToDecorationsHint(bool extendIntoClientAreaHint); /// /// Sets hints that configure how the client area extends. @@ -116,29 +139,6 @@ namespace Avalonia.Platform /// Sets how big the non-client titlebar area should be. /// /// -1 for platform default, otherwise the height in DIPs. - void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight); - - /// - /// Gets or Sets an action that is called whenever one of the extend client area properties changed. - /// - Action ExtendClientAreaToDecorationsChanged { get; set; } - - /// - /// Gets a flag that indicates if Managed decorations i.e. caption buttons are required. - /// This property is used when is set. - /// - bool NeedsManagedDecorations { get; } - - /// - /// Gets a thickness that describes the amount each side of the non-client area extends into the client area. - /// It includes the titlebar. - /// - Thickness ExtendedMargins { get; } - - /// - /// Gets a thickness that describes the margin around the window that is offscreen. - /// This may happen when a window is maximized and is set. - /// - Thickness OffScreenMargin { get; } + void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight); } }