IDisplayView, render statistics
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
using PropertyChanged.SourceGenerator;
|
using PropertyChanged.SourceGenerator;
|
||||||
using TerminalUI.Models;
|
using TerminalUI.Models;
|
||||||
|
using TerminalUI.Traits;
|
||||||
|
|
||||||
namespace TerminalUI.Controls;
|
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 _borderThickness = 1;
|
||||||
[Notify] private Thickness _padding = 0;
|
[Notify] private Thickness _padding = 0;
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
using PropertyChanged.SourceGenerator;
|
using PropertyChanged.SourceGenerator;
|
||||||
using TerminalUI.Color;
|
using TerminalUI.Color;
|
||||||
using TerminalUI.Models;
|
using TerminalUI.Models;
|
||||||
|
using TerminalUI.Traits;
|
||||||
|
|
||||||
namespace TerminalUI.Controls;
|
namespace TerminalUI.Controls;
|
||||||
|
|
||||||
public partial class Rectangle<T> : View<T>
|
public partial class Rectangle<T> : View<T>, IDisplayView
|
||||||
{
|
{
|
||||||
private record RenderState(
|
private record RenderState(
|
||||||
Position Position,
|
Position Position,
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using PropertyChanged.SourceGenerator;
|
using PropertyChanged.SourceGenerator;
|
||||||
using TerminalUI.Color;
|
using TerminalUI.Color;
|
||||||
using TerminalUI.Extensions;
|
using TerminalUI.Extensions;
|
||||||
using TerminalUI.Models;
|
using TerminalUI.Models;
|
||||||
|
using TerminalUI.Traits;
|
||||||
|
|
||||||
namespace TerminalUI.Controls;
|
namespace TerminalUI.Controls;
|
||||||
|
|
||||||
[DebuggerDisplay("Text = {Text}")]
|
[DebuggerDisplay("Text = {Text}")]
|
||||||
public partial class TextBlock<T> : View<T>
|
public partial class TextBlock<T> : View<T>, IDisplayView
|
||||||
{
|
{
|
||||||
private record RenderState(
|
private record RenderState(
|
||||||
Position Position,
|
Position Position,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
using GeneralInputKey;
|
using GeneralInputKey;
|
||||||
using PropertyChanged.SourceGenerator;
|
using PropertyChanged.SourceGenerator;
|
||||||
using TerminalUI.Color;
|
using TerminalUI.Color;
|
||||||
@@ -7,7 +8,8 @@ using TerminalUI.Traits;
|
|||||||
|
|
||||||
namespace TerminalUI.Controls;
|
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(
|
private record RenderState(
|
||||||
string? Text,
|
string? Text,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Buffers;
|
using System.Buffers;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@@ -6,6 +6,7 @@ using PropertyChanged.SourceGenerator;
|
|||||||
using TerminalUI.Color;
|
using TerminalUI.Color;
|
||||||
using TerminalUI.ConsoleDrivers;
|
using TerminalUI.ConsoleDrivers;
|
||||||
using TerminalUI.Models;
|
using TerminalUI.Models;
|
||||||
|
using TerminalUI.Traits;
|
||||||
|
|
||||||
namespace TerminalUI.Controls;
|
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)
|
public bool Render(in RenderContext renderContext, Position position, Size size)
|
||||||
{
|
{
|
||||||
|
renderContext.Statistics.ProcessedViews++;
|
||||||
if (!Attached)
|
if (!Attached)
|
||||||
throw new InvalidOperationException("Cannot render unattached view");
|
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)
|
protected void RenderEmpty(in RenderContext renderContext, Position position, Size size)
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ public readonly ref struct RenderContext
|
|||||||
public readonly bool ForceRerender;
|
public readonly bool ForceRerender;
|
||||||
public readonly IColor? Foreground;
|
public readonly IColor? Foreground;
|
||||||
public readonly IColor? Background;
|
public readonly IColor? Background;
|
||||||
|
public readonly RenderStatistics Statistics;
|
||||||
|
|
||||||
public RenderContext(
|
public RenderContext(
|
||||||
IConsoleDriver consoleDriver,
|
IConsoleDriver consoleDriver,
|
||||||
bool forceRerender,
|
bool forceRerender,
|
||||||
IColor? foreground,
|
IColor? foreground,
|
||||||
IColor? background)
|
IColor? background,
|
||||||
|
RenderStatistics statistics)
|
||||||
{
|
{
|
||||||
RenderId = _renderId++;
|
RenderId = _renderId++;
|
||||||
|
|
||||||
@@ -26,7 +28,15 @@ public readonly ref struct RenderContext
|
|||||||
ForceRerender = forceRerender;
|
ForceRerender = forceRerender;
|
||||||
Foreground = foreground;
|
Foreground = foreground;
|
||||||
Background = background;
|
Background = background;
|
||||||
|
Statistics = statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RenderContext Empty => new(null!, false, null, null);
|
public static RenderContext Empty =>
|
||||||
|
new(
|
||||||
|
null!,
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
new RenderStatistics()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
11
src/Library/TerminalUI/Models/RenderStatistics.cs
Normal file
11
src/Library/TerminalUI/Models/RenderStatistics.cs
Normal 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; }
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using TerminalUI.Controls;
|
using TerminalUI.Controls;
|
||||||
using TerminalUI.Models;
|
using TerminalUI.Models;
|
||||||
using TerminalUI.Traits;
|
using TerminalUI.Traits;
|
||||||
|
|
||||||
@@ -82,7 +82,8 @@ public class RenderEngine : IRenderEngine
|
|||||||
driver,
|
driver,
|
||||||
true,
|
true,
|
||||||
null,
|
null,
|
||||||
null
|
null,
|
||||||
|
new RenderStatistics()
|
||||||
),
|
),
|
||||||
initialPosition,
|
initialPosition,
|
||||||
size);
|
size);
|
||||||
@@ -93,7 +94,8 @@ public class RenderEngine : IRenderEngine
|
|||||||
driver,
|
driver,
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null
|
null,
|
||||||
|
new RenderStatistics()
|
||||||
),
|
),
|
||||||
initialPosition,
|
initialPosition,
|
||||||
size);
|
size);
|
||||||
|
|||||||
6
src/Library/TerminalUI/Traits/IDisplayView.cs
Normal file
6
src/Library/TerminalUI/Traits/IDisplayView.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace TerminalUI.Traits;
|
||||||
|
|
||||||
|
public interface IDisplayView
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user