Polish debug terminal text box
This commit is contained in:
parent
8444da6acc
commit
8fec56dcb1
7 changed files with 54 additions and 14 deletions
|
|
@ -82,9 +82,9 @@ public sealed class AquariumUiPanelBuilder(List<AquariumUiControl> controls)
|
|||
return this;
|
||||
}
|
||||
|
||||
public AquariumUiPanelBuilder TextBox(string label, Func<string> read, Action<string> write, int lines = 3, bool acceptsReturn = true, Action? submit = null, string? tooltip = null, Func<bool>? isVisible = null)
|
||||
public AquariumUiPanelBuilder TextBox(string label, Func<string> read, Action<string> write, int lines = 3, bool acceptsReturn = true, Action? submit = null, bool monospace = false, bool alignBottom = false, string? tooltip = null, Func<bool>? isVisible = null)
|
||||
{
|
||||
controls.Add(new AquariumUiTextBox(label, read, write, Math.Max(1, lines), acceptsReturn, submit, tooltip, isVisible));
|
||||
controls.Add(new AquariumUiTextBox(label, read, write, Math.Max(1, lines), acceptsReturn, submit, monospace, alignBottom, tooltip, isVisible));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ public sealed record AquariumUiOptions(string Label, Func<int> Read, Action<int>
|
|||
public sealed record AquariumUiText(string Label, Func<string> Read, Action<string> Write, string? Tooltip = null, Func<bool>? IsVisible = null)
|
||||
: AquariumUiControl(Label, Tooltip, IsVisible);
|
||||
|
||||
public sealed record AquariumUiTextBox(string Label, Func<string> Read, Action<string> Write, int Lines = 3, bool AcceptsReturn = true, Action? Submit = null, string? Tooltip = null, Func<bool>? IsVisible = null)
|
||||
public sealed record AquariumUiTextBox(string Label, Func<string> Read, Action<string> Write, int Lines = 3, bool AcceptsReturn = true, Action? Submit = null, bool Monospace = false, bool AlignBottom = false, string? Tooltip = null, Func<bool>? IsVisible = null)
|
||||
: AquariumUiControl(Label, Tooltip, IsVisible);
|
||||
|
||||
public sealed record AquariumUiReadout(string Label, Func<string> Read, string? Tooltip = null, Func<bool>? IsVisible = null)
|
||||
|
|
|
|||
BIN
src/Aquarium.Engine/Assets/Fonts/UbuntuSansMono.ttf
Normal file
BIN
src/Aquarium.Engine/Assets/Fonts/UbuntuSansMono.ttf
Normal file
Binary file not shown.
|
|
@ -318,11 +318,11 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
.Slider("Bloom Intensity", () => settings.BloomIntensity, value => settings = (settings with { BloomIntensity = Math.Clamp(value, GraphicsSettings.MinBloomIntensity, GraphicsSettings.MaxBloomIntensity) }).Normalized(), GraphicsSettings.MinBloomIntensity, GraphicsSettings.MaxBloomIntensity, "0.###", "Strength of pre-tonemap bloom energy.", () => activeDebugTab == 0)
|
||||
.Slider("Bloom Veil", () => settings.BloomVeilIntensity, value => settings = (settings with { BloomVeilIntensity = Math.Clamp(value, GraphicsSettings.MinBloomVeilIntensity, GraphicsSettings.MaxBloomVeilIntensity) }).Normalized(), GraphicsSettings.MinBloomVeilIntensity, GraphicsSettings.MaxBloomVeilIntensity, "0.###", "Low-frequency veil from bright HDR energy.", () => activeDebugTab == 0)
|
||||
.Section("Terminal", () => activeDebugTab == 1)
|
||||
.TextBox("Session", TerminalDisplay, UpdateTerminalInputFromDisplay, lines: 8, acceptsReturn: false, submit: ExecuteTerminalInput, tooltip: "Terminal log with live command prompt.", isVisible: () => activeDebugTab == 1)
|
||||
.TextBox("Session", TerminalDisplay, UpdateTerminalInputFromDisplay, lines: 8, acceptsReturn: false, submit: ExecuteTerminalInput, monospace: true, alignBottom: true, tooltip: "Terminal log with live command prompt.", isVisible: () => activeDebugTab == 1)
|
||||
.Section("Synth Playground", () => activeDebugTab == 2)
|
||||
.Options("Preset", () => synthPlaygroundPreset, SelectSynthPreset, SynthPresetOptions, "Loads a built-in synth patch.", () => activeDebugTab == 2)
|
||||
.Readout("Compile", () => $"{synthPlaygroundStatus.State}: {synthPlaygroundStatus.Message}", "Faust compile status.", () => activeDebugTab == 2)
|
||||
.TextBox("Patch", () => synthPlaygroundScript, value => synthPlaygroundScript = value, lines: 7, acceptsReturn: true, tooltip: "Patch DSL source.", isVisible: () => activeDebugTab == 2)
|
||||
.TextBox("Patch", () => synthPlaygroundScript, value => synthPlaygroundScript = value, lines: 7, acceptsReturn: true, monospace: true, tooltip: "Patch DSL source.", isVisible: () => activeDebugTab == 2)
|
||||
.Slider("Gain", () => synthPlaygroundGain, value => synthPlaygroundGain = Math.Clamp(value, 0.0f, 1.0f), 0.0f, 1.0f, "0.###", "Playground patch gain.", () => activeDebugTab == 2)
|
||||
.Button("Compile", () => synthPlaygroundCompileRevision++, "Forces async Faust compile.", () => activeDebugTab == 2)
|
||||
.Button("Play", () => { synthPlaygroundCompileRevision++; synthPlaygroundPlayRevision++; }, "Compiles and schedules the playground patch.", () => activeDebugTab == 2);
|
||||
|
|
@ -356,6 +356,12 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
|
||||
private void UpdateTerminalInputFromDisplay(string value)
|
||||
{
|
||||
if (value.EndsWith("\n>", StringComparison.Ordinal) || string.Equals(value, ">", StringComparison.Ordinal))
|
||||
{
|
||||
terminalInput = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
var promptIndex = value.LastIndexOf("\n> ", StringComparison.Ordinal);
|
||||
if (promptIndex >= 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ internal sealed class DirectWriteOverlay : IDisposable
|
|||
private readonly ID2D1SolidColorBrush trackActiveBrush;
|
||||
private readonly IDWriteTextFormat titleFormat;
|
||||
private readonly IDWriteTextFormat smallFormat;
|
||||
private readonly IDWriteTextFormat monospaceFormat;
|
||||
private readonly int width;
|
||||
private readonly int height;
|
||||
|
||||
|
|
@ -80,6 +81,7 @@ internal sealed class DirectWriteOverlay : IDisposable
|
|||
trackActiveBrush = renderTarget.CreateSolidColorBrush(new Color4(0.45f, 0.38f, 0.34f, 1.0f));
|
||||
titleFormat = CreateTextFormat("Montserrat", 18.0f, FontWeight.Thin);
|
||||
smallFormat = CreateTextFormat("Ubuntu Sans", 11.0f, FontWeight.Regular);
|
||||
monospaceFormat = CreateTextFormat("Ubuntu Sans Mono", 11.0f, FontWeight.Regular);
|
||||
}
|
||||
|
||||
public void Render(AquariumFrame frame, int renderDebugMode, DebugUi? debugUi, IReadOnlyList<DebugUi> clientUiPanels)
|
||||
|
|
@ -115,6 +117,7 @@ internal sealed class DirectWriteOverlay : IDisposable
|
|||
renderTarget,
|
||||
titleFormat,
|
||||
smallFormat,
|
||||
monospaceFormat,
|
||||
panelBrush,
|
||||
rowBrush,
|
||||
hoverRowBrush,
|
||||
|
|
@ -136,6 +139,7 @@ internal sealed class DirectWriteOverlay : IDisposable
|
|||
renderTarget,
|
||||
titleFormat,
|
||||
smallFormat,
|
||||
monospaceFormat,
|
||||
panelBrush,
|
||||
rowBrush,
|
||||
hoverRowBrush,
|
||||
|
|
@ -158,6 +162,7 @@ internal sealed class DirectWriteOverlay : IDisposable
|
|||
public void Dispose()
|
||||
{
|
||||
smallFormat.Dispose();
|
||||
monospaceFormat.Dispose();
|
||||
titleFormat.Dispose();
|
||||
smallCapsTypography.Dispose();
|
||||
fontCollection.Dispose();
|
||||
|
|
@ -199,6 +204,7 @@ internal sealed class DirectWriteOverlay : IDisposable
|
|||
using var builder = directWriteFactory.CreateFontSetBuilder();
|
||||
builder.AddFontFile(FontAssetPath("Montserrat[wght].ttf"));
|
||||
builder.AddFontFile(FontAssetPath("UbuntuSans[wdth,wght].ttf"));
|
||||
builder.AddFontFile(FontAssetPath("UbuntuSansMono.ttf"));
|
||||
using var fontSet = builder.CreateFontSet();
|
||||
return directWriteFactory.CreateFontCollectionFromFontSet(fontSet, FontFamilyModel.Typographic);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ internal sealed class DebugUi
|
|||
controls.Add(new TextControl(text.Label, text.Read, text.Write, text.Tooltip, () => text.Visible));
|
||||
break;
|
||||
case AquariumUiTextBox textBox:
|
||||
controls.Add(new TextBoxControl(textBox.Label, textBox.Read, textBox.Write, textBox.Lines, textBox.AcceptsReturn, textBox.Submit, textBox.Tooltip, () => textBox.Visible));
|
||||
controls.Add(new TextBoxControl(textBox.Label, textBox.Read, textBox.Write, textBox.Lines, textBox.AcceptsReturn, textBox.Submit, textBox.Monospace, textBox.AlignBottom, textBox.Tooltip, () => textBox.Visible));
|
||||
break;
|
||||
case AquariumUiReadout readout:
|
||||
controls.Add(new ReadoutControl(readout.Label, readout.Read, readout.Tooltip, () => readout.Visible));
|
||||
|
|
@ -254,6 +254,7 @@ internal sealed class DebugUi
|
|||
ID2D1RenderTarget target,
|
||||
IDWriteTextFormat titleFormat,
|
||||
IDWriteTextFormat smallFormat,
|
||||
IDWriteTextFormat monospaceFormat,
|
||||
ID2D1SolidColorBrush panelBrush,
|
||||
ID2D1SolidColorBrush rowBrush,
|
||||
ID2D1SolidColorBrush hoverRowBrush,
|
||||
|
|
@ -325,7 +326,7 @@ internal sealed class DebugUi
|
|||
control.IsFocused = control.Id == focusedTextId;
|
||||
control.Draw(
|
||||
target,
|
||||
smallFormat,
|
||||
control.UseMonospace ? monospaceFormat : smallFormat,
|
||||
rowBrush,
|
||||
hoverRowBrush,
|
||||
activeRowBrush,
|
||||
|
|
@ -538,9 +539,9 @@ internal sealed class DebugUi
|
|||
return this;
|
||||
}
|
||||
|
||||
public DebugUiPanel TextBox(string label, Func<string> read, Action<string> write, int lines = 3, bool acceptsReturn = true, Action? submit = null, string? tooltip = null, Func<bool>? isVisible = null)
|
||||
public DebugUiPanel TextBox(string label, Func<string> read, Action<string> write, int lines = 3, bool acceptsReturn = true, Action? submit = null, bool monospace = false, bool alignBottom = false, string? tooltip = null, Func<bool>? isVisible = null)
|
||||
{
|
||||
controls.Add(new TextBoxControl(label, read, write, Math.Max(1, lines), acceptsReturn, submit, tooltip, isVisible));
|
||||
controls.Add(new TextBoxControl(label, read, write, Math.Max(1, lines), acceptsReturn, submit, monospace, alignBottom, tooltip, isVisible));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -580,6 +581,8 @@ internal sealed class DebugUi
|
|||
|
||||
public virtual bool IsInteractive => true;
|
||||
|
||||
public virtual bool UseMonospace => false;
|
||||
|
||||
public virtual float LayoutHeight => this is SectionControl ? SectionHeight : RowHeight;
|
||||
|
||||
public virtual bool HitTest(Vector2 mouse) => Contains(Bounds, mouse);
|
||||
|
|
@ -927,7 +930,7 @@ internal sealed class DebugUi
|
|||
}
|
||||
}
|
||||
|
||||
private sealed class TextBoxControl(string label, Func<string> read, Action<string> write, int lines, bool acceptsReturn, Action? submit, string? tooltip, Func<bool>? isVisible)
|
||||
private sealed class TextBoxControl(string label, Func<string> read, Action<string> write, int lines, bool acceptsReturn, Action? submit, bool monospace, bool alignBottom, string? tooltip, Func<bool>? isVisible)
|
||||
: DebugUiControl(label, tooltip, isVisible), ITextInputControl
|
||||
{
|
||||
private const float LabelHeight = 20.0f;
|
||||
|
|
@ -936,6 +939,8 @@ internal sealed class DebugUi
|
|||
|
||||
public override float LayoutHeight => LabelHeight + VerticalPadding * 2.0f + Math.Max(1, lines) * TextLineHeight;
|
||||
|
||||
public override bool UseMonospace => monospace;
|
||||
|
||||
public void ApplyTextInput(InputState input)
|
||||
{
|
||||
var value = read();
|
||||
|
|
@ -944,6 +949,11 @@ internal sealed class DebugUi
|
|||
switch (ch)
|
||||
{
|
||||
case '\b':
|
||||
if (submit is not null && !acceptsReturn && IsEmptyPrompt(value))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (value.Length > 0)
|
||||
{
|
||||
value = value[..^1];
|
||||
|
|
@ -1002,7 +1012,7 @@ internal sealed class DebugUi
|
|||
target.DrawText(
|
||||
DisplayText(),
|
||||
format,
|
||||
RectFromEdges(box.Left + 8.0f, box.Top + 6.0f, box.Right - 8.0f, box.Bottom - 6.0f),
|
||||
TextBounds(box),
|
||||
primaryBrush,
|
||||
DrawTextOptions.Clip);
|
||||
|
||||
|
|
@ -1020,11 +1030,28 @@ internal sealed class DebugUi
|
|||
var split = value.Split('\n');
|
||||
if (split.Length <= lines)
|
||||
{
|
||||
return value;
|
||||
return alignBottom
|
||||
? string.Join('\n', Enumerable.Repeat(string.Empty, Math.Max(0, lines - split.Length)).Concat(split))
|
||||
: value;
|
||||
}
|
||||
|
||||
return string.Join('\n', split.Skip(split.Length - lines));
|
||||
}
|
||||
|
||||
private Rect TextBounds(Rect box)
|
||||
{
|
||||
var bottom = box.Bottom - 6.0f;
|
||||
var top = alignBottom
|
||||
? Math.Max(box.Top + 6.0f, bottom - Math.Max(1, lines) * TextLineHeight)
|
||||
: box.Top + 6.0f;
|
||||
return RectFromEdges(box.Left + 8.0f, top, box.Right - 8.0f, bottom);
|
||||
}
|
||||
|
||||
private static bool IsEmptyPrompt(string value)
|
||||
{
|
||||
var normalized = value.Replace("\r\n", "\n", StringComparison.Ordinal).Replace('\r', '\n');
|
||||
return normalized.EndsWith("\n> ", StringComparison.Ordinal) || normalized == "> ";
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ReadoutControl(string label, Func<string> read, string? tooltip, Func<bool>? isVisible)
|
||||
|
|
|
|||
Loading…
Reference in a new issue