Browse Source

Merge branch 'master' into fix/DataGrid_GroupIconFixes

pull/8493/head
Max Katz 4 years ago
committed by GitHub
parent
commit
ca29ad0b65
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      native/Avalonia.Native/src/OSX/AvnView.mm
  2. 6
      native/Avalonia.Native/src/OSX/rendertarget.mm
  3. 4
      src/Avalonia.Controls/Window.cs
  4. 27
      tests/Avalonia.Controls.UnitTests/WindowTests.cs
  5. 14
      tests/Avalonia.UnitTests/MockWindowingPlatform.cs

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

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

6
native/Avalonia.Native/src/OSX/rendertarget.mm

@ -13,6 +13,7 @@
{
@public IOSurfaceRef surface;
@public AvnPixelSize size;
@public bool hasContent;
@public float scale;
ComPtr<IAvnGlContext> _context;
GLuint _framebuffer, _texture, _renderbuffer;
@ -41,6 +42,7 @@
self->scale = scale;
self->size = size;
self->_context = context;
self->hasContent = false;
return self;
}
@ -92,6 +94,7 @@
_context->MakeCurrent(release.getPPV());
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glFlush();
self->hasContent = true;
}
-(void) dealloc
@ -170,6 +173,8 @@ static IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(IOSurfaceRenderTarget* ta
@synchronized (lock) {
if(_layer == nil)
return;
if(!surface->hasContent)
return;
[CATransaction begin];
[_layer setContents: nil];
if(surface != nil)
@ -213,6 +218,7 @@ static IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(IOSurfaceRenderTarget* ta
memcpy(pSurface + y*sstride, pFb + y*fstride, wbytes);
}
IOSurfaceUnlock(surf, 0, nil);
surface->hasContent = true;
[self updateLayer];
return S_OK;
}

4
src/Avalonia.Controls/Window.cs

@ -681,8 +681,8 @@ namespace Avalonia.Controls
IsVisible = true;
var initialSize = new Size(
double.IsNaN(Width) ? ClientSize.Width : Width,
double.IsNaN(Height) ? ClientSize.Height : Height);
double.IsNaN(Width) ? Math.Max(MinWidth, ClientSize.Width) : Width,
double.IsNaN(Height) ? Math.Max(MinHeight, ClientSize.Height) : Height);
if (initialSize != ClientSize)
{

27
tests/Avalonia.Controls.UnitTests/WindowTests.cs

@ -540,6 +540,33 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(window.Position, expectedPosition);
}
}
[Fact]
public void Window_Should_Be_Sized_To_MinSize_If_InitialSize_Less_Than_MinSize()
{
var screen1 = new Mock<Screen>(1.75, new PixelRect(new PixelSize(1920, 1080)), new PixelRect(new PixelSize(1920, 966)), true);
var screens = new Mock<IScreenImpl>();
screens.Setup(x => x.AllScreens).Returns(new Screen[] { screen1.Object });
screens.Setup(x => x.ScreenFromPoint(It.IsAny<PixelPoint>())).Returns(screen1.Object);
var windowImpl = MockWindowingPlatform.CreateWindowMock(400, 300);
windowImpl.Setup(x => x.DesktopScaling).Returns(1.75);
windowImpl.Setup(x => x.RenderScaling).Returns(1.75);
windowImpl.Setup(x => x.Screen).Returns(screens.Object);
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var window = new Window(windowImpl.Object);
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.MinWidth = 720;
window.MinHeight = 480;
window.Show();
Assert.Equal(new PixelPoint(330, 63), window.Position);
Assert.Equal(new Size(720, 480), window.Bounds.Size);
}
}
[Fact]
public void Window_Should_Be_Centered_Relative_To_Owner_When_WindowStartupLocation_Is_CenterOwner()

14
tests/Avalonia.UnitTests/MockWindowingPlatform.cs

@ -21,11 +21,11 @@ namespace Avalonia.UnitTests
_popupImpl = popupImpl;
}
public static Mock<IWindowImpl> CreateWindowMock()
public static Mock<IWindowImpl> CreateWindowMock(double initialWidth = 800, double initialHeight = 600)
{
var windowImpl = new Mock<IWindowImpl>();
var position = new PixelPoint();
var clientSize = new Size(800, 600);
var clientSize = new Size(initialWidth, initialHeight);
windowImpl.SetupAllProperties();
windowImpl.Setup(x => x.ClientSize).Returns(() => clientSize);
@ -55,12 +55,18 @@ namespace Avalonia.UnitTests
windowImpl.Setup(x => x.Resize(It.IsAny<Size>(), It.IsAny<PlatformResizeReason>()))
.Callback<Size, PlatformResizeReason>((x, y) =>
{
clientSize = x.Constrain(s_screenSize);
windowImpl.Object.Resized?.Invoke(clientSize, y);
var constrainedSize = x.Constrain(s_screenSize);
if (constrainedSize != clientSize)
{
clientSize = constrainedSize;
windowImpl.Object.Resized?.Invoke(clientSize, y);
}
});
windowImpl.Setup(x => x.Show(true, It.IsAny<bool>())).Callback(() =>
{
windowImpl.Object.Resized?.Invoke(windowImpl.Object.ClientSize, PlatformResizeReason.Unspecified);
windowImpl.Object.Activated?.Invoke();
});

Loading…
Cancel
Save