feat(ui): port retained widget foundations

This commit is contained in:
Erik 2026-07-10 17:55:41 +02:00
parent 44f9ec13d9
commit d825572e31
44 changed files with 84813 additions and 292 deletions

View file

@ -16,7 +16,10 @@ public class VitalsBindingTests
public void Bind_SetsHealthMeterFillFromProvider()
{
var health = new UiMeter();
var layout = FakeLayout((VitalsController.Health, health));
var healthText = new UiText();
var layout = FakeLayout(
(VitalsController.Health, health),
(VitalsController.HealthText, healthText));
float hp = 0.42f;
VitalsController.Bind(layout,
@ -28,9 +31,9 @@ public class VitalsBindingTests
manaText: () => "");
Assert.Equal(0.42f, health.Fill()!.Value);
// The meter no longer draws its own label; the cur/max is a centered UiText child.
// The meter no longer draws its own label; the authored text node is bound in place.
Assert.Null(health.Label());
Assert.Equal("42/100", NumberText(health));
Assert.Equal("42/100", NumberText(healthText));
}
// ── Test 2: All three meters wired to distinct providers ──────────────────
@ -41,10 +44,16 @@ public class VitalsBindingTests
var health = new UiMeter();
var stamina = new UiMeter();
var mana = new UiMeter();
var healthText = new UiText();
var staminaText = new UiText();
var manaText = new UiText();
var layout = FakeLayout(
(VitalsController.Health, health),
(VitalsController.Stamina, stamina),
(VitalsController.Mana, mana));
(VitalsController.Mana, mana),
(VitalsController.HealthText, healthText),
(VitalsController.StaminaText, staminaText),
(VitalsController.ManaText, manaText));
VitalsController.Bind(layout,
healthPct: () => 0.25f,
@ -56,13 +65,13 @@ public class VitalsBindingTests
// Each meter should reflect its own provider, not another's.
Assert.Equal(0.25f, health.Fill()!.Value);
Assert.Equal("25/100", NumberText(health));
Assert.Equal("25/100", NumberText(healthText));
Assert.Equal(0.50f, stamina.Fill()!.Value);
Assert.Equal("50/100", NumberText(stamina));
Assert.Equal("50/100", NumberText(staminaText));
Assert.Equal(0.75f, mana.Fill()!.Value);
Assert.Equal("75/100", NumberText(mana));
Assert.Equal("75/100", NumberText(manaText));
}
// ── Test 3: Missing meter ids are silently skipped (no throw) ─────────────
@ -89,12 +98,12 @@ public class VitalsBindingTests
// ── Helpers ───────────────────────────────────────────────────────────────
/// <summary>The cur/max text from the centered <see cref="UiText"/> number that
/// <see cref="VitalsController"/> attaches as the meter's child.</summary>
private static string NumberText(UiMeter m)
/// <summary>The cur/max text from the authored <see cref="UiText"/> node.</summary>
private static string NumberText(UiText num)
{
var num = Assert.IsType<UiText>(m.Children[0]);
Assert.True(num.Centered);
Assert.True(num.OneLine);
Assert.False(num.Selectable);
var lines = num.LinesProvider();
return lines.Count > 0 ? lines[0].Text : "";
}