feat(D.2b): UiChatView dat-font transcript + 1-line wheel quantum
- Add `DatFont` property (UiDatFont?): when set, OnDraw uses ctx.DrawStringDat + datFont.MeasureWidth for all transcript lines; BitmapFont path unchanged as fallback when DatFont is null. - Cache `_lastDatFont` alongside `_lastFont` so HitChar hit-tests the same advance source that drew the last frame. - HitChar prefers `_lastDatFont` (via UiDatFont.GlyphAdvance) over `_lastFont` (via bf.Advance) for column resolution, keeping drag-select and Ctrl+C accurate with the dat font. - Scroll event handler uses DatFont?.LineHeight first, so the wheel quantum stays correct when the dat font has a different line height. - WheelLines 3f → 1f: retail UIElement_Text::HandleMouseWheel (@0x471450) advances one line per notch; our 3-line quantum was wrong. - Add UiChatViewDatFontTests: pins GlyphAdvance formula (Before+Width+After = 10) and CharIndexAt dat-advance integration. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
50883e445b
commit
7552dcba39
2 changed files with 68 additions and 15 deletions
30
tests/AcDream.App.Tests/UI/UiChatViewDatFontTests.cs
Normal file
30
tests/AcDream.App.Tests/UI/UiChatViewDatFontTests.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using AcDream.App.UI;
|
||||
using DatReaderWriter.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace AcDream.App.Tests.UI;
|
||||
|
||||
public class UiChatViewDatFontTests
|
||||
{
|
||||
// Synthetic per-char advance: each glyph 10px (Before=2,Width=6,After=2).
|
||||
private static FontCharDesc Glyph(char c) => new()
|
||||
{
|
||||
Unicode = c, HorizontalOffsetBefore = 2, Width = 6, HorizontalOffsetAfter = 2,
|
||||
OffsetX = 0, OffsetY = 0, Height = 12, VerticalOffsetBefore = 0,
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void CharIndexAt_UsesDatGlyphAdvance()
|
||||
{
|
||||
float Adv(char c) => UiDatFont.GlyphAdvance(Glyph(c));
|
||||
Assert.Equal(0, UiChatView.CharIndexAt("abc", Adv, 4f));
|
||||
Assert.Equal(1, UiChatView.CharIndexAt("abc", Adv, 12f));
|
||||
Assert.Equal(3, UiChatView.CharIndexAt("abc", Adv, 100f));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GlyphAdvance_MatchesRetailFormula()
|
||||
{
|
||||
Assert.Equal(10f, UiDatFont.GlyphAdvance(Glyph('x')));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue