Browse Source

Merge branch 'master' into fixes/previewer-transparent-frame

pull/11749/head
Max Katz 3 years ago
committed by GitHub
parent
commit
87c7583ce1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs
  2. 12
      src/Avalonia.Controls/TextBlock.cs
  3. 7
      src/Avalonia.DesignerSupport/DesignWindowLoader.cs
  4. 4
      src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs
  5. 9
      src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
  6. 33
      tests/Avalonia.Controls.UnitTests/TextBlockTests.cs

9
src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs

@ -159,14 +159,15 @@ namespace Avalonia.Rendering.Composition.Server
_redrawRequested = false;
using (var targetContext = _renderTarget.CreateDrawingContext())
{
var layerSize = Size * Scaling;
var size = Size;
var layerSize = size * Scaling;
if (layerSize != _layerSize || _layer == null || _layer.IsCorrupted)
{
_layer?.Dispose();
_layer = null;
_layer = targetContext.CreateLayer(Size);
_layer = targetContext.CreateLayer(size);
_layerSize = layerSize;
_dirtyRect = new Rect(0, 0, layerSize.Width, layerSize.Height);
_dirtyRect = new Rect(0, 0, size.Width, size.Height);
}
if (_dirtyRect.Width != 0 || _dirtyRect.Height != 0)
@ -187,7 +188,7 @@ namespace Avalonia.Rendering.Composition.Server
else
targetContext.DrawBitmap(_layer, 1,
new Rect(_layerSize),
new Rect(Size));
new Rect(size));
if (DebugOverlays != RendererDebugOverlays.None)
{

12
src/Avalonia.Controls/TextBlock.cs

@ -668,17 +668,7 @@ namespace Avalonia.Controls
if (HasComplexContent)
{
if (_textRuns != null)
{
foreach (var textRun in _textRuns)
{
if (textRun is EmbeddedControlRun controlRun &&
controlRun.Control is Control control)
{
VisualChildren.Remove(control);
}
}
}
VisualChildren.Clear();
var textRuns = new List<TextRun>();

7
src/Avalonia.DesignerSupport/DesignWindowLoader.cs

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

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

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

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

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

33
tests/Avalonia.Controls.UnitTests/TextBlockTests.cs

@ -115,6 +115,39 @@ namespace Avalonia.Controls.UnitTests
}
}
[Fact]
public void Changing_Inlines_Should_Reset_InlineUIContainer_VisualParent_On_Measure()
{
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
{
var target = new TextBlock();
var control = new Control();
var run = new InlineUIContainer(control);
target.Inlines.Add(run);
target.Measure(Size.Infinity);
Assert.True(target.IsMeasureValid);
Assert.Equal(target, control.VisualParent);
target.Inlines = null;
Assert.Null(run.Parent);
target.Inlines = new InlineCollection { new Run("Hello World") };
Assert.Null(run.Parent);
target.Measure(Size.Infinity);
Assert.Null(control.VisualParent);
}
}
[Fact]
public void InlineUIContainer_Child_Schould_Be_Arranged()
{

Loading…
Cancel
Save