Browse Source

working titlebar height setting.

Dan Walmsley 5 years ago
parent
commit
668dd760c2

+ 1 - 0
native/Avalonia.Native/inc/avalonia-native.h

@@ -288,6 +288,7 @@ AVNCOM(IAvnWindow, 04) : virtual IAvnWindowBase
     virtual HRESULT SetExtendClientArea (bool enable) = 0;
     virtual HRESULT SetExtendClientAreaHints (AvnExtendClientAreaChromeHints hints) = 0;
     virtual HRESULT GetExtendTitleBarHeight (double*ret) = 0;
+    virtual HRESULT SetExtendTitleBarHeight (double value) = 0;
 };
 
 AVNCOM(IAvnWindowBaseEvents, 05) : IUnknown

+ 1 - 0
native/Avalonia.Native/src/OSX/window.h

@@ -15,6 +15,7 @@ class WindowBaseImpl;
 @interface AutoFitContentVisualEffectView : NSVisualEffectView
 -(AutoFitContentVisualEffectView* _Nonnull) initWithContent: (AvnView* _Nonnull) content;
 -(void) ShowTitleBar: (bool) show;
+-(void) SetTitleBarHeightHint: (double) height;
 @end
 
 @interface AvnWindow : NSWindow <NSWindowDelegate>

+ 14 - 3
native/Avalonia.Native/src/OSX/window.mm

@@ -831,6 +831,12 @@ private:
         return S_OK;
     }
     
+    virtual HRESULT SetExtendTitleBarHeight (double value) override
+    {
+        [VisualEffect SetTitleBarHeightHint:value];
+        return S_OK;
+    }
+    
     void EnterFullScreenMode ()
     {
         _fullScreenActive = true;
@@ -1004,10 +1010,12 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
 {
     NSVisualEffectView* _titleBarMaterial;
     AvnView* _content;
+    double _titleBarHeightHint;
 }
 
 -(AutoFitContentVisualEffectView* _Nonnull) initWithContent: (AvnView* _Nonnull) content;
 {
+    _titleBarHeightHint = -1;
     _content = content;
     _titleBarMaterial = [NSVisualEffectView new];
     [_titleBarMaterial setBlendingMode:NSVisualEffectBlendingModeWithinWindow];
@@ -1020,7 +1028,7 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
     return self;
 }
 
--(void) ShowTitleBar: (bool) show;
+-(void) ShowTitleBar: (bool) show
 {
     if(show)
     {
@@ -1032,8 +1040,10 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
     }
 }
 
--(void)updateSize
+-(void) SetTitleBarHeightHint: (double) height
 {
+    _titleBarHeightHint = height;
+    
     [self setFrameSize:self.frame.size];
 }
 
@@ -1046,7 +1056,8 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
     auto window = objc_cast<AvnWindow>([self window]);
     
     // TODO get actual titlebar size
-    double height = [window getExtendedTitleBarHeight];
+    
+    double height = _titleBarHeightHint == -1 ? [window getExtendedTitleBarHeight] : _titleBarHeightHint;
     NSRect tbar;
     tbar.origin.x = 0;
     tbar.origin.y = newSize.height - height;

+ 9 - 1
src/Avalonia.Native/WindowImpl.cs

@@ -16,6 +16,8 @@ namespace Avalonia.Native
         private readonly AvaloniaNativePlatformOptions _opts;
         private readonly GlPlatformFeature _glFeature;
         IAvnWindow _native;
+        private double _extendTitleBarHeight = -1;
+
         internal WindowImpl(IAvaloniaNativeFactory factory, AvaloniaNativePlatformOptions opts,
             GlPlatformFeature glFeature) : base(opts, glFeature)
         {
@@ -140,7 +142,7 @@ namespace Avalonia.Native
 
             _native.SetExtendClientArea(extendIntoClientAreaHint);
 
-            ExtendedMargins = _isExtended ? new Thickness(0, _native.GetExtendTitleBarHeight(), 0, 0) : new Thickness();
+            ExtendedMargins = _isExtended ? new Thickness(0, _extendTitleBarHeight == -1 ? _native.GetExtendTitleBarHeight() : _extendTitleBarHeight, 0, 0) : new Thickness();
 
             ExtendClientAreaToDecorationsChanged?.Invoke(true);
         }
@@ -152,6 +154,12 @@ namespace Avalonia.Native
 
         public void SetExtendClientAreaTitleBarHeightHint(double titleBarHeight)
         {
+            _extendTitleBarHeight = titleBarHeight;
+            _native.SetExtendTitleBarHeight(titleBarHeight);
+
+            ExtendedMargins = _isExtended ? new Thickness(0, titleBarHeight == -1 ? _native.GetExtendTitleBarHeight() : titleBarHeight, 0, 0) : new Thickness();
+
+            ExtendClientAreaToDecorationsChanged?.Invoke(_isExtended);
         }
 
         public void ShowTaskbarIcon(bool value)