Browse Source
Merge pull request #7273 from workgroupengineering/fixes/DevTools/NRE
fixes(DevTools): NRE when click 'Visualizze dirty rects' and 'Show fp…
pull/7280/head
Max Katz
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
40 additions and
4 deletions
-
src/Avalonia.Diagnostics/Diagnostics/Controls/Application.cs
-
src/Avalonia.Diagnostics/Diagnostics/ViewModels/MainViewModel.cs
|
|
|
@ -28,7 +28,12 @@ namespace Avalonia.Diagnostics.Controls |
|
|
|
}; |
|
|
|
controller.Exit += eh; |
|
|
|
} |
|
|
|
|
|
|
|
RendererRoot = application.ApplicationLifetime switch |
|
|
|
{ |
|
|
|
Lifetimes.IClassicDesktopStyleApplicationLifetime classic => classic.MainWindow.Renderer, |
|
|
|
Lifetimes.ISingleViewApplicationLifetime single => (single.MainView as VisualTree.IVisual)?.VisualRoot?.Renderer, |
|
|
|
_ => null |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
internal App Instance => _application; |
|
|
|
@ -105,5 +110,10 @@ namespace Avalonia.Diagnostics.Controls |
|
|
|
/// </summary>
|
|
|
|
public string? Name => |
|
|
|
_application.Name; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the root of the visual tree, if the control is attached to a visual tree.
|
|
|
|
/// </summary>
|
|
|
|
internal Rendering.IRenderer? RendererRoot { get; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -77,7 +77,20 @@ namespace Avalonia.Diagnostics.ViewModels |
|
|
|
get => _shouldVisualizeDirtyRects; |
|
|
|
set |
|
|
|
{ |
|
|
|
((TopLevel)_root).Renderer.DrawDirtyRects = value; |
|
|
|
var changed = true; |
|
|
|
if (_root is TopLevel topLevel && topLevel.Renderer is { }) |
|
|
|
{ |
|
|
|
topLevel.Renderer.DrawDirtyRects = value; |
|
|
|
} |
|
|
|
else if (_root is Controls.Application app && app.RendererRoot is { }) |
|
|
|
{ |
|
|
|
app.RendererRoot.DrawDirtyRects = value; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
changed = false; |
|
|
|
} |
|
|
|
if (changed) |
|
|
|
RaiseAndSetIfChanged(ref _shouldVisualizeDirtyRects, value); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -97,8 +110,21 @@ namespace Avalonia.Diagnostics.ViewModels |
|
|
|
get => _showFpsOverlay; |
|
|
|
set |
|
|
|
{ |
|
|
|
((TopLevel)_root).Renderer.DrawFps = value; |
|
|
|
RaiseAndSetIfChanged(ref _showFpsOverlay, value); |
|
|
|
var changed = true; |
|
|
|
if (_root is TopLevel topLevel && topLevel.Renderer is { }) |
|
|
|
{ |
|
|
|
topLevel.Renderer.DrawFps = value; |
|
|
|
} |
|
|
|
else if (_root is Controls.Application app && app.RendererRoot is { }) |
|
|
|
{ |
|
|
|
app.RendererRoot.DrawFps = value; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
changed = false; |
|
|
|
} |
|
|
|
if(changed) |
|
|
|
RaiseAndSetIfChanged(ref _showFpsOverlay, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|