diff --git a/src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs b/src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs index 0b79217..e467613 100644 --- a/src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs +++ b/src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs @@ -82,9 +82,9 @@ public sealed class AquariumUiPanelBuilder(List controls) return this; } - public AquariumUiPanelBuilder TextBox(string label, Func read, Action write, int lines = 3, bool acceptsReturn = true, Action? submit = null, string? tooltip = null, Func? isVisible = null) + public AquariumUiPanelBuilder TextBox(string label, Func read, Action write, int lines = 3, bool acceptsReturn = true, Action? submit = null, bool monospace = false, bool alignBottom = false, string? tooltip = null, Func? 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 Read, Action public sealed record AquariumUiText(string Label, Func Read, Action Write, string? Tooltip = null, Func? IsVisible = null) : AquariumUiControl(Label, Tooltip, IsVisible); -public sealed record AquariumUiTextBox(string Label, Func Read, Action Write, int Lines = 3, bool AcceptsReturn = true, Action? Submit = null, string? Tooltip = null, Func? IsVisible = null) +public sealed record AquariumUiTextBox(string Label, Func Read, Action Write, int Lines = 3, bool AcceptsReturn = true, Action? Submit = null, bool Monospace = false, bool AlignBottom = false, string? Tooltip = null, Func? IsVisible = null) : AquariumUiControl(Label, Tooltip, IsVisible); public sealed record AquariumUiReadout(string Label, Func Read, string? Tooltip = null, Func? IsVisible = null) diff --git a/src/Aquarium.Engine/Assets/Fonts/UbuntuSansMono.ttf b/src/Aquarium.Engine/Assets/Fonts/UbuntuSansMono.ttf new file mode 100644 index 0000000..3d8d0e7 Binary files /dev/null and b/src/Aquarium.Engine/Assets/Fonts/UbuntuSansMono.ttf differ diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index 3387262..5520e2e 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -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) { diff --git a/src/Aquarium.Engine/Render/DirectWriteOverlay.cs b/src/Aquarium.Engine/Render/DirectWriteOverlay.cs index fd621ba..d3ea450 100644 --- a/src/Aquarium.Engine/Render/DirectWriteOverlay.cs +++ b/src/Aquarium.Engine/Render/DirectWriteOverlay.cs @@ -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 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); } diff --git a/src/Aquarium.Engine/Render/Ui/DebugUi.cs b/src/Aquarium.Engine/Render/Ui/DebugUi.cs index 8253bc2..542f056 100644 --- a/src/Aquarium.Engine/Render/Ui/DebugUi.cs +++ b/src/Aquarium.Engine/Render/Ui/DebugUi.cs @@ -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 read, Action write, int lines = 3, bool acceptsReturn = true, Action? submit = null, string? tooltip = null, Func? isVisible = null) + public DebugUiPanel TextBox(string label, Func read, Action write, int lines = 3, bool acceptsReturn = true, Action? submit = null, bool monospace = false, bool alignBottom = false, string? tooltip = null, Func? 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 read, Action write, int lines, bool acceptsReturn, Action? submit, string? tooltip, Func? isVisible) + private sealed class TextBoxControl(string label, Func read, Action write, int lines, bool acceptsReturn, Action? submit, bool monospace, bool alignBottom, string? tooltip, Func? 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 read, string? tooltip, Func? isVisible) diff --git a/state/evidence.jsonl b/state/evidence.jsonl index b8f8ade..5be3074 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -61,3 +61,4 @@ {"timestamp":"2026-05-12T13:00:00+01:00","topic":"debug-tab-chrome","lesson":"Debug tabs are navigation chrome, not document content. The unified F2 panel title is Debug, with a row of tab buttons directly below it and visible active highlighting. Future debug surfaces should add tabs through the same chrome path instead of creating fake Tabs sections or parallel panels.","files":["src/Aquarium.Engine/Render/Ui/DebugUi.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","state/memory.json"],"source":"user UI correction"} {"timestamp":"2026-05-12T13:20:00+01:00","topic":"debug-text-box-control","lesson":"Terminal commands and synth patch source need real text box controls, not row-value text fields. AquariumUiTextBox now carries line count, return behavior, and optional submit action through the contract; DirectWrite debug UI renders it as a boxed editable region. Use row Text only for compact scalar strings.","files":["src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs","src/Aquarium.Engine/Render/Ui/DebugUi.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","state/memory.json"],"source":"debug UI improvement pass"} {"timestamp":"2026-05-12T13:27:00+01:00","topic":"multiline-debug-terminal","lesson":"The debug terminal should be one multiline session surface: recent log lines plus the live prompt at the end. Typing updates only the trailing prompt, Enter submits that prompt and appends the command/output to the log. Avoid separate output readouts plus detached command rows for terminal UI.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Ui/DebugUi.cs","state/memory.json"],"source":"user terminal correction"} +{"timestamp":"2026-05-12T13:42:00+01:00","topic":"terminal-textbox-polish","lesson":"Terminal text boxes need terminal typography and prompt-safe editing. Bundle Ubuntu Sans Mono for DirectWrite monospace surfaces, let AquariumUiTextBox opt into monospace and bottom alignment, and guard empty trailing prompts so backspace cannot collapse the prompt sentinel and reclassify the log as command input.","files":["src/Aquarium.Engine/Assets/Fonts/UbuntuSansMono.ttf","src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs","src/Aquarium.Engine/Render/DirectWriteOverlay.cs","src/Aquarium.Engine/Render/Ui/DebugUi.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","state/memory.json"],"source":"user terminal polish correction"} diff --git a/state/memory.json b/state/memory.json index cfc60d0..c231c0c 100644 --- a/state/memory.json +++ b/state/memory.json @@ -68,8 +68,8 @@ "text_and_ui": [ "Overlay text uses DirectWrite/Direct2D after scene rendering. It is crisp final-pixel UI for debug surfaces, terminals, inspectors, and splash/status text.", "Aquarium UI controls follow the CultLib code-first binding style without Unity prefab assumptions: panels, sections, sliders, toggles, buttons, option rows, and text boxes bound by explicit read/write delegates.", - "Aquarium.Engine.Contracts exposes AquariumUiDocument as the client-facing debug composition surface. Client panels are tabs inside the single Aquarium debug panel, clients can register terminal commands through AquariumUiDocument.Command, and longer editable strings should use AquariumUiTextBox instead of pretending to be row values.", - "The unified F2 debug panel is titled Debug and owns engine controls, client tabs, a multiline command terminal, and the synth playground. Tab navigation is panel chrome: a highlighted row of buttons below the title, not a content section made of ordinary controls. Do not reintroduce separate Aquarium/Epiphany debug panels fighting for the same hotkey.", + "Aquarium.Engine.Contracts exposes AquariumUiDocument as the client-facing debug composition surface. Client panels are tabs inside the single Aquarium debug panel, clients can register terminal commands through AquariumUiDocument.Command, and longer editable strings should use AquariumUiTextBox instead of pretending to be row values. Text boxes may opt into bundled Ubuntu Sans Mono and bottom alignment when the surface is terminal-like.", + "The unified F2 debug panel is titled Debug and owns engine controls, client tabs, a bottom-aligned multiline command terminal, and the synth playground. Tab navigation is panel chrome: a highlighted row of buttons below the title, not a content section made of ordinary controls. Do not reintroduce separate Aquarium/Epiphany debug panels fighting for the same hotkey.", "Vortice.Mathematics.Rect uses x, y, width, height. UI code should use explicit RectFromEdges helpers when reasoning in edges.", "Debug UI feedback needs honest element-specific states: base, hover, and active. Sliders respond on track/fill and handle separately, keep geometry stable, and brighten by lerping accent colors toward white.", "Scene/diegetic labels should use renderer-owned MSDF/SDF billboards when they live in world space. Overlay text should not be shoved into HDR for convenience."