User reported wanting to mark text in-game and copy it out (item names,
coordinates, NPC dialogue, etc). ImGui doesn't natively let you select
across multiple TextColored widgets, but a read-only multi-line
InputText is fully click-drag selectable + Ctrl+C copyable. This
commit adds a "Copy mode" toggle to ChatPanel that swaps the chat
tail's render path between the colored-line view and a single
selectable text region.
New IPanelRenderer primitive:
void TextMultilineReadOnly(string id, string content, Vector2 size);
ImGui maps this to InputTextMultiline with the ReadOnly flag — same
selection + Ctrl+C UX a user expects from any text-input widget.
FakePanelRenderer records the call for tests. The future D.2b
custom retail-look backend implements its own equivalent (likely
the same widget pattern with retail font/skin).
ChatPanel rendering:
· A "Copy mode (select text to Ctrl+C)" Checkbox at the top of
the panel toggles _copyMode.
· Off (default) — current per-line render with colored combat
entries. Visually unchanged from before.
· On — the chat tail becomes a single TextMultilineReadOnly
widget holding every visible line joined with newlines. Loses
per-line color, gains arbitrary-span text selection.
· Footer (separator + input field) renders identically in both
modes so the user can still type while in copy mode.
Existing ChatPanelLayoutTests's footer-separator probe was using
IndexOf("Separator") — which now matches the new pre-tail separator
between the Checkbox and the chat tail. Switched to LastIndexOf
which still pins the footer separator (between EndChild and
InputTextSubmit). Behaviour and intent unchanged.
DisplaySettingsTests' With_expression test was still asserting the
old "1920x1080" Default.Resolution; updated to the new "1280x720"
that the previous wire-up commit introduced (the earlier commit
forgot this one).
dotnet build green (0 warnings); dotnet test 1,309 / 1,309 green
(243 Core.Net + 393 UI.Abstractions + 673 Core).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
237 lines
9 KiB
C#
237 lines
9 KiB
C#
using System.Numerics;
|
|
|
|
namespace AcDream.UI.Abstractions.Tests;
|
|
|
|
/// <summary>
|
|
/// In-memory test double for <see cref="IPanelRenderer"/>. Records every
|
|
/// widget call so tests can assert against the recorded trace without
|
|
/// running an ImGui context. New widgets added to the interface must
|
|
/// implement here too — that compilation error IS the TDD red signal.
|
|
/// </summary>
|
|
internal sealed class FakePanelRenderer : IPanelRenderer
|
|
{
|
|
/// <summary>Ordered list of (method, args) pairs recorded across this renderer's lifetime.</summary>
|
|
public List<(string Method, object?[] Args)> Calls { get; } = new();
|
|
|
|
/// <summary>If <see cref="Begin"/> is called, return this value. Defaults to true so panels render.</summary>
|
|
public bool BeginReturns { get; set; } = true;
|
|
|
|
// -- Inputs the panel under test can mutate via ref args -----------
|
|
|
|
/// <summary>Pre-set return value for the next <see cref="Checkbox"/> — caller flips bool to simulate user click.</summary>
|
|
public bool CheckboxNextReturn { get; set; }
|
|
public bool? CheckboxNextValue { get; set; }
|
|
|
|
/// <summary>Pre-set return value for the next <see cref="Button"/> — caller sets to simulate user click.</summary>
|
|
public bool ButtonNextReturn { get; set; }
|
|
|
|
/// <summary>Pre-set return value for the next <see cref="Combo"/>.</summary>
|
|
public bool ComboNextReturn { get; set; }
|
|
public int? ComboNextSelectedIndex { get; set; }
|
|
|
|
/// <summary>Pre-set return for <see cref="SliderFloat"/>.</summary>
|
|
public bool SliderFloatNextReturn { get; set; }
|
|
public float? SliderFloatNextValue { get; set; }
|
|
|
|
/// <summary>Pre-set return for <see cref="CollapsingHeader"/>.</summary>
|
|
public bool CollapsingHeaderNextReturn { get; set; } = true;
|
|
|
|
/// <summary>Pre-set return for <see cref="TreeNode"/>.</summary>
|
|
public bool TreeNodeNextReturn { get; set; } = true;
|
|
|
|
/// <summary>Pre-set return for <see cref="BeginTable"/>.</summary>
|
|
public bool BeginTableNextReturn { get; set; } = true;
|
|
|
|
/// <summary>Pre-set return for <see cref="BeginChild"/>.</summary>
|
|
public bool BeginChildNextReturn { get; set; } = true;
|
|
|
|
/// <summary>Pre-set return value for <see cref="FrameHeightWithSpacing"/>.</summary>
|
|
public float FrameHeightWithSpacingValue { get; set; } = 24f;
|
|
|
|
/// <summary>Pre-set "submitted" string for the next <see cref="InputTextSubmit"/>; null = no submit this frame.</summary>
|
|
public string? InputTextSubmitNextSubmitted { get; set; }
|
|
public string? InputTextSubmitNextBufferAfter { get; set; }
|
|
|
|
/// <summary>K.3: <see cref="BeginMainMenuBar"/> return value (default true).</summary>
|
|
public bool MainMenuBarReturns { get; set; } = true;
|
|
/// <summary>K.3: <see cref="BeginMenu"/> return value (default true).</summary>
|
|
public bool MenuReturns { get; set; } = true;
|
|
/// <summary>K.3: <see cref="MenuItem"/> return value (default false — only true for the frame the user "clicks").</summary>
|
|
public bool MenuItemReturns { get; set; }
|
|
|
|
public bool Begin(string title)
|
|
{
|
|
Calls.Add(("Begin", new object?[] { title }));
|
|
return BeginReturns;
|
|
}
|
|
|
|
public void End() => Calls.Add(("End", Array.Empty<object?>()));
|
|
|
|
public void Text(string text) => Calls.Add(("Text", new object?[] { text }));
|
|
|
|
public void SameLine() => Calls.Add(("SameLine", Array.Empty<object?>()));
|
|
|
|
public void Separator() => Calls.Add(("Separator", Array.Empty<object?>()));
|
|
|
|
public void ProgressBar(float fraction, float width, string? overlay = null)
|
|
=> Calls.Add(("ProgressBar", new object?[] { fraction, width, overlay }));
|
|
|
|
public void TextColored(Vector4 rgba, string text)
|
|
=> Calls.Add(("TextColored", new object?[] { rgba, text }));
|
|
|
|
public bool CollapsingHeader(string label, bool defaultOpen = true)
|
|
{
|
|
Calls.Add(("CollapsingHeader", new object?[] { label, defaultOpen }));
|
|
return CollapsingHeaderNextReturn;
|
|
}
|
|
|
|
public bool TreeNode(string label)
|
|
{
|
|
Calls.Add(("TreeNode", new object?[] { label }));
|
|
return TreeNodeNextReturn;
|
|
}
|
|
|
|
public void TreePop() => Calls.Add(("TreePop", Array.Empty<object?>()));
|
|
|
|
public bool Checkbox(string label, ref bool value)
|
|
{
|
|
Calls.Add(("Checkbox", new object?[] { label, value }));
|
|
if (CheckboxNextValue is bool nv) value = nv;
|
|
return CheckboxNextReturn;
|
|
}
|
|
|
|
public bool Button(string label)
|
|
{
|
|
Calls.Add(("Button", new object?[] { label }));
|
|
return ButtonNextReturn;
|
|
}
|
|
|
|
public bool Combo(string label, ref int selectedIndex, string[] items)
|
|
{
|
|
Calls.Add(("Combo", new object?[] { label, selectedIndex, items }));
|
|
if (ComboNextSelectedIndex is int idx) selectedIndex = idx;
|
|
return ComboNextReturn;
|
|
}
|
|
|
|
public bool SliderFloat(string label, ref float value, float min, float max)
|
|
{
|
|
Calls.Add(("SliderFloat", new object?[] { label, value, min, max }));
|
|
if (SliderFloatNextValue is float v) value = v;
|
|
return SliderFloatNextReturn;
|
|
}
|
|
|
|
public void PlotLines(
|
|
string label,
|
|
float[] values,
|
|
int count,
|
|
int offset = 0,
|
|
string? overlay = null,
|
|
float? min = null,
|
|
float? max = null,
|
|
Vector2? size = null)
|
|
=> Calls.Add(("PlotLines", new object?[] { label, values, count, offset, overlay, min, max, size }));
|
|
|
|
public void BeginTable(string id, int columns)
|
|
=> Calls.Add(("BeginTable", new object?[] { id, columns }));
|
|
|
|
public void TableNextColumn() => Calls.Add(("TableNextColumn", Array.Empty<object?>()));
|
|
|
|
public void EndTable() => Calls.Add(("EndTable", Array.Empty<object?>()));
|
|
|
|
public bool InputTextSubmit(string label, ref string buffer, int maxLen, out string? submitted)
|
|
{
|
|
Calls.Add(("InputTextSubmit", new object?[] { label, buffer, maxLen }));
|
|
submitted = InputTextSubmitNextSubmitted;
|
|
if (submitted is not null)
|
|
buffer = InputTextSubmitNextBufferAfter ?? string.Empty;
|
|
return submitted is not null;
|
|
}
|
|
|
|
public void Spacing() => Calls.Add(("Spacing", Array.Empty<object?>()));
|
|
|
|
public void Dummy(Vector2 size) => Calls.Add(("Dummy", new object?[] { size }));
|
|
|
|
public void TextWrapped(string text) => Calls.Add(("TextWrapped", new object?[] { text }));
|
|
|
|
public bool BeginChild(string id, Vector2 size, bool border = false)
|
|
{
|
|
Calls.Add(("BeginChild", new object?[] { id, size, border }));
|
|
return BeginChildNextReturn;
|
|
}
|
|
|
|
public void EndChild() => Calls.Add(("EndChild", Array.Empty<object?>()));
|
|
|
|
public float FrameHeightWithSpacing()
|
|
{
|
|
Calls.Add(("FrameHeightWithSpacing", Array.Empty<object?>()));
|
|
return FrameHeightWithSpacingValue;
|
|
}
|
|
|
|
public void SetScrollHereY(float ratio)
|
|
=> Calls.Add(("SetScrollHereY", new object?[] { ratio }));
|
|
|
|
public void SetKeyboardFocusHere()
|
|
=> Calls.Add(("SetKeyboardFocusHere", Array.Empty<object?>()));
|
|
|
|
// -- Phase K.3 — main menu bar -----------------------------------------
|
|
|
|
public bool BeginMainMenuBar()
|
|
{
|
|
Calls.Add(("BeginMainMenuBar", Array.Empty<object?>()));
|
|
return MainMenuBarReturns;
|
|
}
|
|
|
|
public void EndMainMenuBar()
|
|
=> Calls.Add(("EndMainMenuBar", Array.Empty<object?>()));
|
|
|
|
public bool BeginMenu(string label)
|
|
{
|
|
Calls.Add(("BeginMenu", new object?[] { label }));
|
|
return MenuReturns;
|
|
}
|
|
|
|
public void EndMenu()
|
|
=> Calls.Add(("EndMenu", Array.Empty<object?>()));
|
|
|
|
public bool MenuItem(string label, string? shortcut = null)
|
|
{
|
|
Calls.Add(("MenuItem", new object?[] { label, shortcut }));
|
|
return MenuItemReturns;
|
|
}
|
|
|
|
// -- Tab bar -----------------------------------------------------------
|
|
|
|
/// <summary>Pre-set return for <see cref="BeginTabBar"/>.</summary>
|
|
public bool TabBarReturns { get; set; } = true;
|
|
|
|
/// <summary>The label of the tab the next <see cref="BeginTabItem"/>
|
|
/// call should report as "selected" (return true). All other tab
|
|
/// items return false. Defaults to null = the FIRST tab item rendered
|
|
/// is the selected one.</summary>
|
|
public string? ActiveTabLabel { get; set; }
|
|
|
|
private string? _firstTabSeen;
|
|
|
|
public bool BeginTabBar(string id)
|
|
{
|
|
Calls.Add(("BeginTabBar", new object?[] { id }));
|
|
_firstTabSeen = null;
|
|
return TabBarReturns;
|
|
}
|
|
|
|
public void EndTabBar() => Calls.Add(("EndTabBar", Array.Empty<object?>()));
|
|
|
|
public bool BeginTabItem(string label)
|
|
{
|
|
Calls.Add(("BeginTabItem", new object?[] { label }));
|
|
_firstTabSeen ??= label;
|
|
return ActiveTabLabel is null
|
|
? string.Equals(label, _firstTabSeen, StringComparison.Ordinal)
|
|
: string.Equals(label, ActiveTabLabel, StringComparison.Ordinal);
|
|
}
|
|
|
|
public void EndTabItem() => Calls.Add(("EndTabItem", Array.Empty<object?>()));
|
|
|
|
public void TextMultilineReadOnly(string id, string content, Vector2 size)
|
|
=> Calls.Add(("TextMultilineReadOnly", new object?[] { id, content, size }));
|
|
}
|