Browse Source

fix nits.

pull/3967/head
Dan Walmsley 6 years ago
parent
commit
9f64463060
  1. 10
      src/Avalonia.Controls/Chrome/CaptionButtons.cs
  2. 32
      src/Avalonia.Controls/Chrome/TitleBar.cs
  3. 60
      src/Avalonia.Controls/Platform/IWindowImpl.cs

10
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<Panel>("PART_CloseButton");
var restoreButton = e.NameScope.Find<Panel>("PART_RestoreButton");
var minimiseButton = e.NameScope.Find<Panel>("PART_MinimiseButton");
var fullScreenButton = e.NameScope.Find<Panel>("PART_FullScreenButton");
var closeButton = e.NameScope.Get<Panel>("PART_CloseButton");
var restoreButton = e.NameScope.Get<Panel>("PART_RestoreButton");
var minimiseButton = e.NameScope.Get<Panel>("PART_MinimiseButton");
var fullScreenButton = e.NameScope.Get<Panel>("PART_FullScreenButton");
closeButton.PointerReleased += (sender, e) => _hostWindow.Close();
restoreButton.PointerReleased += (sender, e) => _hostWindow.WindowState = _hostWindow.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;

32
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<CaptionButtons>("PART_CaptionButtons");
_captionButtons = e.NameScope.Get<CaptionButtons>("PART_CaptionButtons");
_captionButtons.Attach(_hostWindow);
InvalidateSize();
UpdateSize();
}
}
}

60
src/Avalonia.Controls/Platform/IWindowImpl.cs

@ -68,6 +68,34 @@ namespace Avalonia.Platform
/// </summary>
Func<bool> Closing { get; set; }
/// <summary>
/// Gets a value to indicate if the platform was able to extend client area to non-client area.
/// </summary>
bool IsClientAreaExtendedToDecorations { get; }
/// <summary>
/// Gets or Sets an action that is called whenever one of the extend client area properties changed.
/// </summary>
Action<bool> ExtendClientAreaToDecorationsChanged { get; set; }
/// <summary>
/// Gets a flag that indicates if Managed decorations i.e. caption buttons are required.
/// This property is used when <see cref="IsClientAreaExtendedToDecorations"/> is set.
/// </summary>
bool NeedsManagedDecorations { get; }
/// <summary>
/// Gets a thickness that describes the amount each side of the non-client area extends into the client area.
/// It includes the titlebar.
/// </summary>
Thickness ExtendedMargins { get; }
/// <summary>
/// Gets a thickness that describes the margin around the window that is offscreen.
/// This may happen when a window is maximized and <see cref="IsClientAreaExtendedToDecorations"/> is set.
/// </summary>
Thickness OffScreenMargin { get; }
/// <summary>
/// Starts moving a window with left button being held. Should be called from left mouse button press event handler.
/// </summary>
@ -99,12 +127,7 @@ namespace Avalonia.Platform
/// Sets if the ClientArea is extended into the non-client area.
/// </summary>
/// <param name="extendIntoClientAreaHint">true to enable, false to disable</param>
void SetExtendClientAreaToDecorationsHint(bool extendIntoClientAreaHint);
/// <summary>
/// Gets a value to indicate if the platform was able to extend client area to non-client area.
/// </summary>
bool IsClientAreaExtendedToDecorations { get; }
void SetExtendClientAreaToDecorationsHint(bool extendIntoClientAreaHint);
/// <summary>
/// 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.
/// </summary>
/// <param name="titleBarHeight">-1 for platform default, otherwise the height in DIPs.</param>
void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight);
/// <summary>
/// Gets or Sets an action that is called whenever one of the extend client area properties changed.
/// </summary>
Action<bool> ExtendClientAreaToDecorationsChanged { get; set; }
/// <summary>
/// Gets a flag that indicates if Managed decorations i.e. caption buttons are required.
/// This property is used when <see cref="IsClientAreaExtendedToDecorations"/> is set.
/// </summary>
bool NeedsManagedDecorations { get; }
/// <summary>
/// Gets a thickness that describes the amount each side of the non-client area extends into the client area.
/// It includes the titlebar.
/// </summary>
Thickness ExtendedMargins { get; }
/// <summary>
/// Gets a thickness that describes the margin around the window that is offscreen.
/// This may happen when a window is maximized and <see cref="IsClientAreaExtendedToDecorations"/> is set.
/// </summary>
Thickness OffScreenMargin { get; }
void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight);
}
}

Loading…
Cancel
Save