perf(ui): retain shaped report text
This commit is contained in:
parent
c0bec56dfe
commit
f2a015be8e
11 changed files with 525 additions and 38 deletions
|
|
@ -92,6 +92,46 @@ public sealed class CharacterControllerTests
|
|||
text => text.EventId == CharacterController.MainTextId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Stable_draws_reuse_report_until_source_or_layout_changes()
|
||||
{
|
||||
ImportedLayout layout = FixtureLoader.LoadCharacterInformation();
|
||||
int builds = 0;
|
||||
int deaths = 1;
|
||||
Action? changed = null;
|
||||
using CharacterInformationUiController controller =
|
||||
CharacterController.Bind(
|
||||
layout,
|
||||
() =>
|
||||
{
|
||||
builds++;
|
||||
return new CharacterSheet { Deaths = deaths };
|
||||
},
|
||||
subscribeChanged: handler =>
|
||||
{
|
||||
changed = handler;
|
||||
return new TestSubscription();
|
||||
});
|
||||
UiText text = Assert.IsType<UiText>(
|
||||
layout.FindElement(CharacterController.MainTextId));
|
||||
|
||||
IReadOnlyList<UiText.Line> first = text.LinesProvider();
|
||||
IReadOnlyList<UiText.Line> second = text.LinesProvider();
|
||||
Assert.Same(first, second);
|
||||
Assert.Equal(1, builds);
|
||||
|
||||
deaths = 2;
|
||||
changed!();
|
||||
IReadOnlyList<UiText.Line> changedLines = text.LinesProvider();
|
||||
Assert.NotSame(first, changedLines);
|
||||
Assert.Equal(2, builds);
|
||||
|
||||
text.Width -= 24f;
|
||||
IReadOnlyList<UiText.Line> resized = text.LinesProvider();
|
||||
Assert.NotSame(changedLines, resized);
|
||||
Assert.Equal(2, builds);
|
||||
}
|
||||
|
||||
private static string Report(CharacterSheet sheet)
|
||||
=> CharacterController.BuildReport(sheet, CharacterInfoStrings.English);
|
||||
|
||||
|
|
@ -101,4 +141,11 @@ public sealed class CharacterControllerTests
|
|||
private static ImportedLayout FakeLayout()
|
||||
=> new(new UiPanel { Width = 300f, Height = 362f },
|
||||
new Dictionary<uint, UiElement>());
|
||||
|
||||
private sealed class TestSubscription : IDisposable
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue