Scrollable Self-Test table (#2284)

This commit is contained in:
Haselnussbomber 2025-05-29 19:35:38 +02:00 committed by GitHub
parent e415699bb3
commit e52e0b6df9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
@ -9,7 +10,9 @@ using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Windowing;
using Dalamud.Logging.Internal;
using ImGuiNET;
using Lumina.Excel.Sheets;
namespace Dalamud.Interface.Internal.Windows.SelfTest;
@ -61,7 +64,7 @@ internal class SelfTestWindow : Window
private bool selfTestRunning = false;
private int currentStep = 0;
private int scrollToStep = -1;
private DateTimeOffset lastTestStart;
/// <summary>
@ -90,9 +93,10 @@ internal class SelfTestWindow : Window
if (ImGuiComponents.IconButton(FontAwesomeIcon.StepForward))
{
this.testIndexToResult.Add(this.currentStep, (SelfTestStepResult.NotRan, null));
this.testIndexToResult[this.currentStep] = (SelfTestStepResult.NotRan, null);
this.steps[this.currentStep].CleanUp();
this.currentStep++;
this.scrollToStep = this.currentStep;
this.lastTestStart = DateTimeOffset.Now;
if (this.currentStep >= this.steps.Count)
@ -107,6 +111,7 @@ internal class SelfTestWindow : Window
{
this.selfTestRunning = true;
this.currentStep = 0;
this.scrollToStep = this.currentStep;
this.testIndexToResult.Clear();
this.lastTestStart = DateTimeOffset.Now;
}
@ -116,11 +121,11 @@ internal class SelfTestWindow : Window
ImGui.TextUnformatted($"Step: {this.currentStep} / {this.steps.Count}");
ImGuiHelpers.ScaledDummy(10);
ImGui.Spacing();
this.DrawResultTable();
ImGuiHelpers.ScaledDummy(10);
ImGui.Spacing();
if (this.currentStep >= this.steps.Count)
{
@ -131,11 +136,11 @@ internal class SelfTestWindow : Window
if (this.testIndexToResult.Any(x => x.Value.Result == SelfTestStepResult.Fail))
{
ImGui.TextColored(ImGuiColors.DalamudRed, "One or more checks failed!");
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudRed, "One or more checks failed!");
}
else
{
ImGui.TextColored(ImGuiColors.HealerGreen, "All checks passed!");
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.HealerGreen, "All checks passed!");
}
return;
@ -146,8 +151,6 @@ internal class SelfTestWindow : Window
return;
}
ImGui.Separator();
var step = this.steps[this.currentStep];
ImGui.TextUnformatted($"Current: {step.Name}");
@ -164,13 +167,12 @@ internal class SelfTestWindow : Window
result = SelfTestStepResult.Fail;
}
ImGui.Separator();
if (result != SelfTestStepResult.Waiting)
{
var duration = DateTimeOffset.Now - this.lastTestStart;
this.testIndexToResult.Add(this.currentStep, (result, duration));
this.testIndexToResult[this.currentStep] = (result, duration);
this.currentStep++;
this.scrollToStep = this.currentStep;
this.lastTestStart = DateTimeOffset.Now;
}
@ -178,14 +180,24 @@ internal class SelfTestWindow : Window
private void DrawResultTable()
{
if (ImGui.BeginTable("agingResultTable", 5, ImGuiTableFlags.Borders))
{
var tableSize = ImGui.GetContentRegionAvail();
if (this.selfTestRunning)
tableSize -= new Vector2(0, 150);
tableSize.Y = Math.Min(tableSize.Y, ImGui.GetWindowViewport().Size.Y * 0.5f);
using var table = ImRaii.Table("agingResultTable", 5, ImGuiTableFlags.Borders | ImGuiTableFlags.ScrollY, tableSize);
if (!table)
return;
ImGui.TableSetupColumn("###index", ImGuiTableColumnFlags.WidthFixed, 12f * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn("Name");
ImGui.TableSetupColumn("Result", ImGuiTableColumnFlags.WidthFixed, 40f * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn("Duration", ImGuiTableColumnFlags.WidthFixed, 90f * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn(string.Empty, ImGuiTableColumnFlags.WidthFixed, 30f * ImGuiHelpers.GlobalScale);
ImGui.TableSetupScrollFreeze(0, 1);
ImGui.TableHeadersRow();
for (var i = 0; i < this.steps.Count; i++)
@ -193,54 +205,68 @@ internal class SelfTestWindow : Window
var step = this.steps[i];
ImGui.TableNextRow();
if (this.selfTestRunning && this.currentStep == i)
{
ImGui.TableSetBgColor(ImGuiTableBgTarget.RowBg0, ImGui.GetColorU32(ImGuiCol.TableRowBgAlt));
}
ImGui.TableSetColumnIndex(0);
ImGui.Text(i.ToString());
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(i.ToString());
if (this.selfTestRunning && this.scrollToStep == i)
{
ImGui.SetScrollHereY();
this.scrollToStep = -1;
}
ImGui.TableSetColumnIndex(1);
ImGui.Text(step.Name);
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(step.Name);
if (this.testIndexToResult.TryGetValue(i, out var result))
{
ImGui.TableSetColumnIndex(2);
ImGui.PushFont(InterfaceManager.MonoFont);
ImGui.AlignTextToFramePadding();
switch (result.Result)
{
case SelfTestStepResult.Pass:
ImGui.TextColored(ImGuiColors.HealerGreen, "PASS");
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.HealerGreen, "PASS");
break;
case SelfTestStepResult.Fail:
ImGui.TextColored(ImGuiColors.DalamudRed, "FAIL");
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudRed, "FAIL");
break;
default:
ImGui.TextColored(ImGuiColors.DalamudGrey, "NR");
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, "NR");
break;
}
ImGui.PopFont();
ImGui.TableSetColumnIndex(3);
if (result.Duration.HasValue)
{
ImGui.TextUnformatted(result.Duration.Value.ToString("g"));
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(this.FormatTimeSpan(result.Duration.Value));
}
}
else
{
ImGui.TableSetColumnIndex(2);
ImGui.AlignTextToFramePadding();
if (this.selfTestRunning && this.currentStep == i)
{
ImGui.TextColored(ImGuiColors.DalamudGrey, "WAIT");
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, "WAIT");
}
else
{
ImGui.TextColored(ImGuiColors.DalamudGrey, "NR");
ImGuiHelpers.SafeTextColoredWrapped(ImGuiColors.DalamudGrey, "NR");
}
ImGui.TableSetColumnIndex(3);
ImGui.AlignTextToFramePadding();
if (this.selfTestRunning && this.currentStep == i)
{
ImGui.TextUnformatted((DateTimeOffset.Now - this.lastTestStart).ToString("g"));
ImGui.TextUnformatted(this.FormatTimeSpan(DateTimeOffset.Now - this.lastTestStart));
}
}
@ -260,9 +286,6 @@ internal class SelfTestWindow : Window
ImGui.SetTooltip("Jump to this test");
}
}
ImGui.EndTable();
}
}
private void StopTests()
@ -281,4 +304,11 @@ internal class SelfTestWindow : Window
}
}
}
private string FormatTimeSpan(TimeSpan ts)
{
var str = ts.ToString("g", CultureInfo.InvariantCulture);
var commaPos = str.LastIndexOf('.');
return commaPos > -1 && commaPos + 5 < str.Length ? str[..(commaPos + 5)] : str;
}
}