Browse Source

fix titlebar size when entering and exiting extended frame mode.

demo1
Dan Walmsley 6 years ago
parent
commit
124f12d5b6
  1. 3
      native/Avalonia.Native/src/OSX/window.h
  2. 53
      native/Avalonia.Native/src/OSX/window.mm

3
native/Avalonia.Native/src/OSX/window.h

@ -29,7 +29,8 @@ class WindowBaseImpl;
-(void) showWindowMenuWithAppMenu; -(void) showWindowMenuWithAppMenu;
-(void) applyMenu:(NSMenu* _Nullable)menu; -(void) applyMenu:(NSMenu* _Nullable)menu;
-(double) getScaling; -(double) getScaling;
-(double) getTitleBarHeight; -(double) getExtendedTitleBarHeight;
-(void) setIsExtended:(bool)value;
@end @end
struct INSWindowHolder struct INSWindowHolder

53
native/Avalonia.Native/src/OSX/window.mm

@ -35,7 +35,7 @@ public:
View = NULL; View = NULL;
Window = NULL; Window = NULL;
} }
NSVisualEffectView* VisualEffect; AutoFitContentVisualEffectView* VisualEffect;
AvnView* View; AvnView* View;
AvnWindow* Window; AvnWindow* Window;
ComPtr<IAvnWindowBaseEvents> BaseEvents; ComPtr<IAvnWindowBaseEvents> BaseEvents;
@ -826,6 +826,8 @@ private:
View.layer.zPosition = 0; View.layer.zPosition = 0;
} }
[Window setIsExtended:enable];
UpdateStyle(); UpdateStyle();
return S_OK; return S_OK;
@ -846,7 +848,7 @@ private:
return E_POINTER; return E_POINTER;
} }
*ret = [Window getTitleBarHeight]; *ret = [Window getExtendedTitleBarHeight];
return S_OK; return S_OK;
} }
@ -1049,14 +1051,21 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
} }
} }
-(void)updateSize
{
[self setFrameSize:self.frame.size];
}
-(void)setFrameSize:(NSSize)newSize -(void)setFrameSize:(NSSize)newSize
{ {
[super setFrameSize:newSize]; [super setFrameSize:newSize];
[_content setFrameSize:newSize]; [_content setFrameSize:newSize];
auto window = objc_cast<AvnWindow>([self window]);
// TODO get actual titlebar size // TODO get actual titlebar size
float height = 38; double height = [window getExtendedTitleBarHeight];
NSRect tbar; NSRect tbar;
tbar.origin.x = 0; tbar.origin.x = 0;
tbar.origin.y = newSize.height - height; tbar.origin.y = newSize.height - height;
@ -1595,28 +1604,41 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
bool _canBecomeKeyAndMain; bool _canBecomeKeyAndMain;
bool _closed; bool _closed;
bool _isEnabled; bool _isEnabled;
bool _isExtended;
AvnMenu* _menu; AvnMenu* _menu;
double _lastScaling; double _lastScaling;
} }
-(void) setIsExtended:(bool)value;
{
_isExtended = value;
}
-(double) getScaling -(double) getScaling
{ {
return _lastScaling; return _lastScaling;
} }
-(double) getTitleBarHeight -(double) getExtendedTitleBarHeight
{ {
for (id subview in self.contentView.superview.subviews) if(_isExtended)
{ {
if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) for (id subview in self.contentView.superview.subviews)
{ {
NSView *titlebarView = [subview subviews][0]; if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")])
{
return (double)titlebarView.frame.size.height; NSView *titlebarView = [subview subviews][0];
}
} return (double)titlebarView.frame.size.height;
}
return -1; }
return -1;
}
else
{
return 0;
}
} }
+(void)closeAll +(void)closeAll
@ -1737,6 +1759,7 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent
[self setOpaque:NO]; [self setOpaque:NO];
[self setBackgroundColor: [NSColor clearColor]]; [self setBackgroundColor: [NSColor clearColor]];
[self invalidateShadow]; [self invalidateShadow];
_isExtended = false;
return self; return self;
} }

Loading…
Cancel
Save