Browse Source

Previewer: reuse last render scaling

pull/11755/head
Julien Lebosquain 3 years ago
parent
commit
b727ada00a
No known key found for this signature in database GPG Key ID: 1833CAD10ACC46FD
  1. 7
      src/Avalonia.DesignerSupport/DesignWindowLoader.cs
  2. 4
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs
  3. 9
      src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs

7
src/Avalonia.DesignerSupport/DesignWindowLoader.cs

@ -4,6 +4,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Embedding.Offscreen;
using Avalonia.Controls.Platform; using Avalonia.Controls.Platform;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Styling; using Avalonia.Styling;
@ -13,6 +14,9 @@ namespace Avalonia.DesignerSupport
public class DesignWindowLoader public class DesignWindowLoader
{ {
public static Window LoadDesignerWindow(string xaml, string assemblyPath, string xamlFileProjectPath) public static Window LoadDesignerWindow(string xaml, string assemblyPath, string xamlFileProjectPath)
=> LoadDesignerWindow(xaml, assemblyPath, xamlFileProjectPath, 1.0);
public static Window LoadDesignerWindow(string xaml, string assemblyPath, string xamlFileProjectPath, double renderScaling)
{ {
Window window; Window window;
Control control; Control control;
@ -96,6 +100,9 @@ namespace Avalonia.DesignerSupport
window = new Window() {Content = (Control)control}; window = new Window() {Content = (Control)control};
} }
if (window.PlatformImpl is OffscreenTopLevelImplBase offscreenImpl)
offscreenImpl.RenderScaling = renderScaling;
Design.ApplyDesignModeProperties(window, control); Design.ApplyDesignModeProperties(window, control);
if (!window.IsSet(Window.SizeToContentProperty)) if (!window.IsSet(Window.SizeToContentProperty))

4
src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs

@ -67,8 +67,8 @@ namespace Avalonia.DesignerSupport.Remote
{ {
_transport.Send(new RequestViewportResizeMessage _transport.Send(new RequestViewportResizeMessage
{ {
Width = clientSize.Width, Width = Math.Ceiling(clientSize.Width * RenderScaling),
Height = clientSize.Height Height = Math.Ceiling(clientSize.Height * RenderScaling)
}); });
ClientSize = clientSize; ClientSize = clientSize;
RenderAndSendFrameIfNeeded(); RenderAndSendFrameIfNeeded();

9
src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs

@ -1,13 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Xml;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.DesignerSupport.Remote.HtmlTransport; using Avalonia.DesignerSupport.Remote.HtmlTransport;
using Avalonia.Input;
using Avalonia.Remote.Protocol; using Avalonia.Remote.Protocol;
using Avalonia.Remote.Protocol.Designer; using Avalonia.Remote.Protocol.Designer;
using Avalonia.Remote.Protocol.Viewport; using Avalonia.Remote.Protocol.Viewport;
@ -20,6 +17,7 @@ namespace Avalonia.DesignerSupport.Remote
private static ClientSupportedPixelFormatsMessage s_supportedPixelFormats; private static ClientSupportedPixelFormatsMessage s_supportedPixelFormats;
private static ClientViewportAllocatedMessage s_viewportAllocatedMessage; private static ClientViewportAllocatedMessage s_viewportAllocatedMessage;
private static ClientRenderInfoMessage s_renderInfoMessage; private static ClientRenderInfoMessage s_renderInfoMessage;
private static double s_lastRenderScaling = 1.0;
private static IAvaloniaRemoteTransportConnection s_transport; private static IAvaloniaRemoteTransportConnection s_transport;
class CommandLineArgs class CommandLineArgs
@ -226,6 +224,9 @@ namespace Avalonia.DesignerSupport.Remote
} }
if (obj is UpdateXamlMessage xaml) if (obj is UpdateXamlMessage xaml)
{ {
if (s_currentWindow is not null)
s_lastRenderScaling = s_currentWindow.RenderScaling;
try try
{ {
s_currentWindow?.Close(); s_currentWindow?.Close();
@ -237,7 +238,7 @@ namespace Avalonia.DesignerSupport.Remote
s_currentWindow = null; s_currentWindow = null;
try try
{ {
s_currentWindow = DesignWindowLoader.LoadDesignerWindow(xaml.Xaml, xaml.AssemblyPath, xaml.XamlFileProjectPath); s_currentWindow = DesignWindowLoader.LoadDesignerWindow(xaml.Xaml, xaml.AssemblyPath, xaml.XamlFileProjectPath, s_lastRenderScaling);
s_transport.Send(new UpdateXamlResultMessage(){Handle = s_currentWindow.PlatformImpl?.Handle?.Handle.ToString()}); s_transport.Send(new UpdateXamlResultMessage(){Handle = s_currentWindow.PlatformImpl?.Handle?.Handle.ToString()});
} }
catch (Exception e) catch (Exception e)

Loading…
Cancel
Save