Browse Source

Implemented basic layout scaling.

Maybe works... I don't have a high DPI monitor to test on...
pull/447/head
Steven Kirk 11 years ago
parent
commit
d460ec9fd0
  1. 1
      src/Perspex.Input/Perspex.Input.csproj
  2. 33
      src/Perspex.Layout/Layoutable.cs
  3. 1
      src/Perspex.SceneGraph/Perspex.SceneGraph.csproj
  4. 2
      src/Windows/Perspex.Win32/Win32Platform.cs

1
src/Perspex.Input/Perspex.Input.csproj

@ -100,7 +100,6 @@
<Compile Include="Navigation\FocusExtensions.cs" />
<Compile Include="Navigation\DirectionalNavigation.cs" />
<Compile Include="Navigation\TabNavigation.cs" />
<Compile Include="Platform\IPlatformSettings.cs" />
<Compile Include="PointerWheelEventArgs.cs" />
<Compile Include="Raw\RawMouseWheelEventArgs.cs" />
<Compile Include="Raw\RawSizeEventArgs.cs" />

33
src/Perspex.Layout/Layoutable.cs

@ -3,6 +3,7 @@
using System;
using System.Linq;
using Perspex.Platform;
using Perspex.VisualTree;
using Serilog;
using Serilog.Core.Enrichers;
@ -466,6 +467,7 @@ namespace Perspex.Layout
.Deflate(margin);
var measured = MeasureOverride(constrained);
var width = measured.Width;
var height = measured.Height;
@ -485,6 +487,13 @@ namespace Perspex.Layout
height = Math.Min(height, MaxHeight);
height = Math.Max(height, MinHeight);
if (UseLayoutRounding)
{
var scale = GetLayoutScale();
width = Math.Ceiling(width * scale) / scale;
height = Math.Ceiling(height * scale) / scale;
}
return NonNegative(new Size(width, height).Inflate(margin));
}
else
@ -510,12 +519,6 @@ namespace Perspex.Layout
height = Math.Max(height, child.DesiredSize.Height);
}
if (UseLayoutRounding)
{
width = Math.Ceiling(width);
height = Math.Ceiling(height);
}
return new Size(width, height);
}
@ -537,6 +540,7 @@ namespace Perspex.Layout
Math.Max(0, finalRect.Width - Margin.Left - Margin.Right),
Math.Max(0, finalRect.Height - Margin.Top - Margin.Bottom));
var size = sizeMinusMargins;
var scale = GetLayoutScale();
if (HorizontalAlignment != HorizontalAlignment.Stretch)
{
@ -553,11 +557,11 @@ namespace Perspex.Layout
if (UseLayoutRounding)
{
size = new Size(
Math.Ceiling(size.Width),
Math.Ceiling(size.Height));
Math.Ceiling(size.Width * scale) / scale,
Math.Ceiling(size.Height * scale) / scale);
sizeMinusMargins = new Size(
Math.Ceiling(sizeMinusMargins.Width),
Math.Ceiling(sizeMinusMargins.Height));
Math.Ceiling(sizeMinusMargins.Width * scale) / scale,
Math.Ceiling(sizeMinusMargins.Height * scale) / scale);
}
size = ArrangeOverride(size).Constrain(size);
@ -586,8 +590,8 @@ namespace Perspex.Layout
if (UseLayoutRounding)
{
originX = Math.Floor(originX);
originY = Math.Floor(originY);
originX = Math.Floor(originX * scale) / scale;
originY = Math.Floor(originY * scale) / scale;
}
Bounds = new Rect(originX, originY, size.Width, size.Height);
@ -666,5 +670,10 @@ namespace Perspex.Layout
{
return new Size(Math.Max(size.Width, 0), Math.Max(size.Height, 0));
}
private static double GetLayoutScale()
{
return PerspexLocator.Current.GetService<IPlatformSettings>()?.LayoutScalingFactor ?? 1.0;
}
}
}

1
src/Perspex.SceneGraph/Perspex.SceneGraph.csproj

@ -106,6 +106,7 @@
<Compile Include="Media\TileBrush.cs" />
<Compile Include="Media\ImageBush.cs" />
<Compile Include="Media\VisualBrush.cs" />
<Compile Include="Platform\IPlatformSettings.cs" />
<Compile Include="RelativePoint.cs" />
<Compile Include="Platform\IFormattedTextImpl.cs" />
<Compile Include="Platform\IBitmapImpl.cs" />

2
src/Windows/Perspex.Win32/Win32Platform.cs

@ -188,7 +188,7 @@ namespace Perspex.Win32
UnmanagedMethods.GetDpiForMonitor(hMonitor, UnmanagedMethods.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out dpix, out dpiy);
// Set scale based on x DPI
_scale = dpix / 100.0;
_scale = dpix / 96.0;
}
}
}

Loading…
Cancel
Save