IDisplayView, render statistics

This commit is contained in:
2023-08-12 23:42:44 +02:00
parent 09f44e9db2
commit a594e1b989
9 changed files with 63 additions and 18 deletions

View File

@@ -1,9 +1,10 @@
using PropertyChanged.SourceGenerator;
using PropertyChanged.SourceGenerator;
using TerminalUI.Models;
using TerminalUI.Traits;
namespace TerminalUI.Controls;
public partial class Border<T> : ContentView<T>
public partial class Border<T> : ContentView<T>, IDisplayView
{
[Notify] private Thickness _borderThickness = 1;
[Notify] private Thickness _padding = 0;

View File

@@ -1,10 +1,11 @@
using PropertyChanged.SourceGenerator;
using TerminalUI.Color;
using TerminalUI.Models;
using TerminalUI.Traits;
namespace TerminalUI.Controls;
public partial class Rectangle<T> : View<T>
public partial class Rectangle<T> : View<T>, IDisplayView
{
private record RenderState(
Position Position,

View File

@@ -1,14 +1,15 @@
using System.ComponentModel;
using System.ComponentModel;
using System.Diagnostics;
using PropertyChanged.SourceGenerator;
using TerminalUI.Color;
using TerminalUI.Extensions;
using TerminalUI.Models;
using TerminalUI.Traits;
namespace TerminalUI.Controls;
[DebuggerDisplay("Text = {Text}")]
public partial class TextBlock<T> : View<T>
public partial class TextBlock<T> : View<T>, IDisplayView
{
private record RenderState(
Position Position,

View File

@@ -1,3 +1,4 @@
using System.Diagnostics;
using GeneralInputKey;
using PropertyChanged.SourceGenerator;
using TerminalUI.Color;
@@ -7,7 +8,8 @@ using TerminalUI.Traits;
namespace TerminalUI.Controls;
public partial class TextBox<T> : View<T>, IFocusable
[DebuggerDisplay("Text = {Text}")]
public partial class TextBox<T> : View<T>, IFocusable, IDisplayView
{
private record RenderState(
string? Text,

View File

@@ -1,4 +1,4 @@
using System.Buffers;
using System.Buffers;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
@@ -6,6 +6,7 @@ using PropertyChanged.SourceGenerator;
using TerminalUI.Color;
using TerminalUI.ConsoleDrivers;
using TerminalUI.Models;
using TerminalUI.Traits;
namespace TerminalUI.Controls;
@@ -118,6 +119,7 @@ public abstract partial class View<T> : IView<T>
public bool Render(in RenderContext renderContext, Position position, Size size)
{
renderContext.Statistics.ProcessedViews++;
if (!Attached)
throw new InvalidOperationException("Cannot render unattached view");
@@ -149,7 +151,16 @@ public abstract partial class View<T> : IView<T>
);
}
return RenderMethod(renderContext, position, size);
var renderResult = RenderMethod(renderContext, position, size);
if (renderResult)
{
renderContext.Statistics.RenderedViews++;
if (this is IDisplayView)
renderContext.Statistics.RenderedDisplayViews++;
}
return renderResult;
}
protected void RenderEmpty(in RenderContext renderContext, Position position, Size size)

View File

@@ -13,20 +13,30 @@ public readonly ref struct RenderContext
public readonly bool ForceRerender;
public readonly IColor? Foreground;
public readonly IColor? Background;
public readonly RenderStatistics Statistics;
public RenderContext(
IConsoleDriver consoleDriver,
bool forceRerender,
IColor? foreground,
IColor? background)
IConsoleDriver consoleDriver,
bool forceRerender,
IColor? foreground,
IColor? background,
RenderStatistics statistics)
{
RenderId = _renderId++;
ConsoleDriver = consoleDriver;
ForceRerender = forceRerender;
Foreground = foreground;
Background = background;
Statistics = statistics;
}
public static RenderContext Empty => new(null!, false, null, null);
public static RenderContext Empty =>
new(
null!,
false,
null,
null,
new RenderStatistics()
);
}

View File

@@ -0,0 +1,11 @@
using System.Diagnostics;
namespace TerminalUI.Models;
[DebuggerDisplay("RenderedViews = {RenderedViews}, RenderedDisplayViews = {RenderedDisplayViews}, ProcessedViews = {ProcessedViews}")]
public class RenderStatistics
{
public ulong RenderedViews { get; set; }
public ulong RenderedDisplayViews { get; set; }
public ulong ProcessedViews { get; set; }
}

View File

@@ -1,4 +1,4 @@
using TerminalUI.Controls;
using TerminalUI.Controls;
using TerminalUI.Models;
using TerminalUI.Traits;
@@ -82,7 +82,8 @@ public class RenderEngine : IRenderEngine
driver,
true,
null,
null
null,
new RenderStatistics()
),
initialPosition,
size);
@@ -93,7 +94,8 @@ public class RenderEngine : IRenderEngine
driver,
false,
null,
null
null,
new RenderStatistics()
),
initialPosition,
size);

View File

@@ -0,0 +1,6 @@
namespace TerminalUI.Traits;
public interface IDisplayView
{
}