Browse Source

Merge pull request #11191 from AvaloniaUI/fix-screens-api

Fix Screens.ScreenFromWindow API
pull/11194/head
Nikita Tsukanov 4 years ago
committed by GitHub
parent
commit
017d332d7f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      src/Avalonia.Controls/Screens.cs
  2. 6
      src/Avalonia.Controls/Window.cs

40
src/Avalonia.Controls/Screens.cs

@ -1,8 +1,7 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Platform;
using Avalonia.VisualTree;
#nullable enable
@ -38,21 +37,58 @@ namespace Avalonia.Controls
_iScreenImpl = iScreenImpl;
}
/// <summary>
/// Retrieves a Screen for the display that contains the rectangle.
/// </summary>
/// <param name="bounds">Bounds that specifies the area for which to retrieve the display.</param>
/// <returns>The <see cref="Screen"/>.</returns>
public Screen? ScreenFromBounds(PixelRect bounds)
{
return _iScreenImpl.ScreenFromRect(bounds);
}
/// <summary>
/// Retrieves a Screen for the display that contains the specified <see cref="WindowBase"/>.
/// </summary>
/// <param name="window">The window for which to retrieve the Screen.</param>
/// <exception cref="ObjectDisposedException">Window platform implementation was already disposed.</exception>
/// <returns>The <see cref="Screen"/>.</returns>
public Screen? ScreenFromWindow(WindowBase window)
{
if (window.PlatformImpl is null)
{
throw new ObjectDisposedException("Window platform implementation was already disposed.");
}
return _iScreenImpl.ScreenFromWindow(window.PlatformImpl);
}
/// <summary>
/// Retrieves a Screen for the display that contains the specified <see cref="IWindowBaseImpl"/>.
/// </summary>
/// <param name="window">The window impl for which to retrieve the Screen.</param>
/// <returns>The <see cref="Screen"/>.</returns>
[Obsolete("Use ScreenFromWindow(WindowBase) overload.")]
public Screen? ScreenFromWindow(IWindowBaseImpl window)
{
return _iScreenImpl.ScreenFromWindow(window);
}
/// <summary>
/// Retrieves a Screen for the display that contains the specified point.
/// </summary>
/// <param name="point">A Point that specifies the location for which to retrieve a Screen.</param>
/// <returns>The <see cref="Screen"/>.</returns>
public Screen? ScreenFromPoint(PixelPoint point)
{
return _iScreenImpl.ScreenFromPoint(point);
}
/// <summary>
/// Retrieves a Screen for the display that contains the specified <see cref="Visual"/>.
/// </summary>
/// <param name="visual">A Visual for which to retrieve a Screen.</param>
/// <returns>The <see cref="Screen"/>.</returns>
public Screen? ScreenFromVisual(Visual visual)
{
var tl = visual.PointToScreen(visual.Bounds.TopLeft);

6
src/Avalonia.Controls/Window.cs

@ -713,7 +713,7 @@ namespace Avalonia.Controls
Owner = owner;
owner?.AddChild(this, false);
SetWindowStartupLocation(owner?.PlatformImpl);
SetWindowStartupLocation(owner);
PlatformImpl?.Show(ShowActivated, false);
Renderer.Start();
@ -789,7 +789,7 @@ namespace Avalonia.Controls
Owner = owner;
owner.AddChild(this, true);
SetWindowStartupLocation(owner.PlatformImpl);
SetWindowStartupLocation(owner);
PlatformImpl?.Show(ShowActivated, true);
@ -870,7 +870,7 @@ namespace Avalonia.Controls
}
}
private void SetWindowStartupLocation(IWindowBaseImpl? owner = null)
private void SetWindowStartupLocation(Window? owner = null)
{
var startupLocation = WindowStartupLocation;

Loading…
Cancel
Save