Browse Source

Comment and update the Screen class

pull/9133/head
robloo 4 years ago
parent
commit
30fd91121e
  1. 2
      samples/ControlCatalog/Pages/ScreenPage.cs
  2. 25
      src/Avalonia.Controls/Platform/Screen.cs
  3. 16
      src/Avalonia.Controls/Screens.cs
  4. 8
      src/Avalonia.X11/X11Screens.cs
  5. 2
      src/Windows/Avalonia.Win32/WindowImpl.cs

2
samples/ControlCatalog/Pages/ScreenPage.cs

@ -65,7 +65,7 @@ namespace ControlCatalog.Pages
formattedText = CreateFormattedText($"Scaling: {screen.PixelDensity * 100}%");
context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 40));
formattedText = CreateFormattedText($"Primary: {screen.Primary}");
formattedText = CreateFormattedText($"Primary: {screen.IsPrimary}");
context.DrawText(formattedText, boundsRect.Position.WithY(boundsRect.Size.Height + 60));
formattedText =

25
src/Avalonia.Controls/Platform/Screen.cs

@ -1,21 +1,42 @@
namespace Avalonia.Platform
{
/// <summary>
/// Represents a single display screen.
/// </summary>
public class Screen
{
/// <summary>
/// Gets the pixel density of the screen.
/// This is a scaling factor so multiply by 100 to get a percentage.
/// </summary>
/// <remarks>
/// Both X and Y density are assumed uniform.
/// </remarks>
public double PixelDensity { get; }
/// <summary>
/// Gets the overall pixel-size of the screen.
/// This generally is the raw pixel counts in both the X and Y direction.
/// </summary>
public PixelRect Bounds { get; }
/// <summary>
/// Gets the actual working-area pixel-size of the screen.
/// This may be smaller to account for notches and other block-out areas.
/// </summary>
public PixelRect WorkingArea { get; }
public bool Primary { get; }
/// <summary>
/// Gets a value indicating whether the screen is the primary one.
/// </summary>
public bool IsPrimary { get; }
public Screen(double pixelDensity, PixelRect bounds, PixelRect workingArea, bool primary)
{
this.PixelDensity = pixelDensity;
this.Bounds = bounds;
this.WorkingArea = workingArea;
this.Primary = primary;
this.IsPrimary = primary;
}
}
}

16
src/Avalonia.Controls/Screens.cs

@ -8,13 +8,27 @@ using Avalonia.VisualTree;
namespace Avalonia.Controls
{
/// <summary>
/// Represents all screens available on a device.
/// </summary>
public class Screens
{
private readonly IScreenImpl _iScreenImpl;
/// <summary>
/// Gets the total number of screens available on this device.
/// </summary>
public int ScreenCount => _iScreenImpl?.ScreenCount ?? 0;
/// <summary>
/// Gets the list of all screens available on this device.
/// </summary>
public IReadOnlyList<Screen> All => _iScreenImpl?.AllScreens ?? Array.Empty<Screen>();
public Screen? Primary => All.FirstOrDefault(x => x.Primary);
/// <summary>
/// Gets the primary screen on this device.
/// </summary>
public Screen? Primary => All.FirstOrDefault(x => x.IsPrimary);
public Screens(IScreenImpl iScreenImpl)
{

8
src/Avalonia.X11/X11Screens.cs

@ -9,7 +9,7 @@ using JetBrains.Annotations;
namespace Avalonia.X11
{
class X11Screens : IScreenImpl
class X11Screens : IScreenImpl
{
private IX11Screens _impl;
@ -218,7 +218,7 @@ namespace Avalonia.X11
public int ScreenCount => _impl.Screens.Length;
public IReadOnlyList<Screen> AllScreens =>
_impl.Screens.Select(s => new Screen(s.PixelDensity, s.Bounds, s.WorkingArea, s.Primary)).ToArray();
_impl.Screens.Select(s => new Screen(s.PixelDensity, s.Bounds, s.WorkingArea, s.IsPrimary)).ToArray();
}
interface IX11Screens
@ -281,7 +281,7 @@ namespace Avalonia.X11
{
private const int FullHDWidth = 1920;
private const int FullHDHeight = 1080;
public bool Primary { get; }
public bool IsPrimary { get; }
public string Name { get; set; }
public PixelRect Bounds { get; set; }
public Size? PhysicalSize { get; set; }
@ -291,7 +291,7 @@ namespace Avalonia.X11
public X11Screen(PixelRect bounds, bool primary,
string name, Size? physicalSize, double? pixelDensity)
{
Primary = primary;
IsPrimary = primary;
Name = name;
Bounds = bounds;
if (physicalSize == null && pixelDensity == null)

2
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -224,7 +224,7 @@ namespace Avalonia.Win32
}
}
private double PrimaryScreenRenderScaling => Screen.AllScreens.FirstOrDefault(screen => screen.Primary)?.PixelDensity ?? 1;
private double PrimaryScreenRenderScaling => Screen.AllScreens.FirstOrDefault(screen => screen.IsPrimary)?.PixelDensity ?? 1;
public double RenderScaling => _scaling;

Loading…
Cancel
Save