Browse Source

extend api only allows to turn titlebar on or off to maintain window integrity, and decoration margins dont include border margins.

demo1
Dan Walmsley 6 years ago
parent
commit
9e81245415
  1. 7
      src/Avalonia.Controls/Platform/ExtendClientAreaChromeHints.cs
  2. 6
      src/Avalonia.Controls/Window.cs
  3. 2
      src/Avalonia.Themes.Default/CaptionButtons.xaml
  4. 43
      src/Windows/Avalonia.Win32/WindowImpl.cs

7
src/Avalonia.Controls/Platform/ExtendClientAreaChromeHints.cs

@ -6,11 +6,10 @@ namespace Avalonia.Platform
public enum ExtendClientAreaChromeHints
{
NoChrome,
Default = SystemTitleBar | SystemChromeButtons,
Default = SystemTitleBar,
SystemTitleBar = 0x01,
SystemChromeButtons = 0x02,
ManagedChromeButtons = 0x04,
PreferSystemChromeButtons = 0x08,
ManagedChromeButtons = 0x02,
PreferSystemChromeButtons = 0x04,
AdaptiveChromeWithTitleBar = SystemTitleBar | PreferSystemChromeButtons,
AdaptiveChromeWithoutTitleBar = PreferSystemChromeButtons,
}

6
src/Avalonia.Controls/Window.cs

@ -540,11 +540,7 @@ namespace Avalonia.Controls
{
IsExtendedIntoWindowDecorations = isExtended;
WindowDecorationMargins = new Thickness(
PlatformImpl.ExtendedMargins.Left,
PlatformImpl.ExtendedMargins.Top - PlatformImpl.OffScreenMargin.Top,
PlatformImpl.ExtendedMargins.Right,
PlatformImpl.ExtendedMargins.Bottom);
WindowDecorationMargins = PlatformImpl.ExtendedMargins;
OffScreenMargin = PlatformImpl.OffScreenMargin;
}

2
src/Avalonia.Themes.Default/CaptionButtons.xaml

@ -5,7 +5,7 @@
<Setter Property="MaxHeight" Value="30" />
<Setter Property="Template">
<ControlTemplate>
<StackPanel Spacing="2" Margin="0 0 7 0" Background="#7F00FF00" VerticalAlignment="Stretch" TextBlock.FontSize="10" Orientation="Horizontal">
<StackPanel Spacing="2" Margin="0 0 7 0" VerticalAlignment="Stretch" TextBlock.FontSize="10" Orientation="Horizontal">
<StackPanel.Styles>
<Style Selector="Panel">
<Setter Property="Width" Value="45" />

43
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -699,18 +699,14 @@ namespace Avalonia.Win32
margins.cyTopHeight = _extendChromeHints.HasFlag(ExtendClientAreaChromeHints.SystemTitleBar) ? borderCaptionThickness.top : 1;
_extendedMargins = new Thickness(0, borderCaptionThickness.top / Scaling, 0, 0);
if (WindowState == WindowState.Maximized && !_extendChromeHints.HasFlag(ExtendClientAreaChromeHints.SystemChromeButtons))
{
_offScreenMargin = new Thickness();
}
else if (WindowState == WindowState.Maximized)
if (WindowState == WindowState.Maximized)
{
_extendedMargins = new Thickness(0, (borderCaptionThickness.top - borderThickness.top) / Scaling, 0, 0);
_offScreenMargin = new Thickness(borderThickness.left / Scaling, borderThickness.top / Scaling, borderThickness.right / Scaling, borderThickness.bottom / Scaling);
}
else
{
{
_extendedMargins = new Thickness(0, (borderCaptionThickness.top) / Scaling, 0, 0);
_offScreenMargin = new Thickness();
}
@ -739,29 +735,6 @@ namespace Avalonia.Win32
var margins = UpdateExtendMargins();
DwmExtendFrameIntoClientArea(_hwnd, ref margins);
if(!_extendChromeHints.HasFlag(ExtendClientAreaChromeHints.SystemChromeButtons) ||
(_extendChromeHints.HasFlag(ExtendClientAreaChromeHints.PreferSystemChromeButtons) &&
!_extendChromeHints.HasFlag(ExtendClientAreaChromeHints.SystemTitleBar)))
{
var style = GetStyle();
style &= ~(WindowStyles.WS_MINIMIZEBOX | WindowStyles.WS_MAXIMIZEBOX | WindowStyles.WS_SYSMENU);
SetStyle(style);
DisableCloseButton(_hwnd);
}
else
{
var style = GetStyle();
style |= (WindowStyles.WS_MINIMIZEBOX | WindowStyles.WS_MAXIMIZEBOX | WindowStyles.WS_SYSMENU);
SetStyle(style);
EnableCloseButton(_hwnd);
}
}
else
{
@ -770,14 +743,6 @@ namespace Avalonia.Win32
_offScreenMargin = new Thickness();
_extendedMargins = new Thickness();
var style = GetStyle();
style |= (WindowStyles.WS_MINIMIZEBOX | WindowStyles.WS_MAXIMIZEBOX | WindowStyles.WS_SYSMENU);
SetStyle(style);
EnableCloseButton(_hwnd);
}
ExtendClientAreaToDecorationsChanged?.Invoke(true);

Loading…
Cancel
Save