Browse Source

alway setContentSize even before show, but preconstrain the size.

pull/10532/head
Dan Walmsley 4 years ago
parent
commit
c8b868a558
  1. 7
      native/Avalonia.Native/src/OSX/AvnView.mm
  2. 24
      native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

7
native/Avalonia.Native/src/OSX/AvnView.mm

@ -127,11 +127,8 @@
[self updateRenderTarget]; [self updateRenderTarget];
auto reason = [self inLiveResize] ? ResizeUser : _resizeReason; auto reason = [self inLiveResize] ? ResizeUser : _resizeReason;
if(_parent->IsShown()) _parent->BaseEvents->Resized(AvnSize{newSize.width, newSize.height}, reason);
{
_parent->BaseEvents->Resized(AvnSize{newSize.width, newSize.height}, reason);
}
} }
} }

24
native/Avalonia.Native/src/OSX/WindowBaseImpl.mm

@ -4,6 +4,7 @@
// //
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h>
#include "common.h" #include "common.h"
#include "AvnView.h" #include "AvnView.h"
#include "menu.h" #include "menu.h"
@ -293,29 +294,24 @@ HRESULT WindowBaseImpl::Resize(double x, double y, AvnPlatformResizeReason reaso
} }
@try { @try {
if(x != lastSize.width || y != lastSize.height) { if(x != lastSize.width || y != lastSize.height)
lastSize = NSSize{x, y}; {
if (!_shown) { if (!_shown) {
// Before the window is shown, Cocoa wont give Resized events
// constraining the window to the maximum size available on the monitor.
// we have to emulated this behavior that Avalonia relies on.
auto screenSize = [Window screen].visibleFrame.size; auto screenSize = [Window screen].visibleFrame.size;
if(x > screenSize.width){ if (x > screenSize.width) {
x = screenSize.width; x = screenSize.width;
} }
if(y > screenSize.height) if (y > screenSize.height) {
{
y = screenSize.height; y = screenSize.height;
} }
BaseEvents->Resized(AvnSize{x, y}, reason);
} else if (Window != nullptr) {
[Window setContentSize:lastSize];
[Window invalidateShadow];
} }
lastSize = NSSize{x, y};
[Window setContentSize:lastSize];
[Window invalidateShadow];
} }
} }
@finally { @finally {

Loading…
Cancel
Save