Improve nine-slice atlas sampling

This commit is contained in:
gem
2026-06-09 14:49:17 +08:00
parent 4ce5fe1ae7
commit 220bb0aba1
3 changed files with 65 additions and 6 deletions

View File

@@ -284,6 +284,36 @@ void main() {
expect(parts[4].source, const Rect.fromLTRB(10, 10, 20, 20));
});
test('insets nine-slice source rects to avoid atlas edge sampling', () {
final parts = runtimeNineSliceRects(
source: const Rect.fromLTWH(10, 20, 30, 30),
destination: const Rect.fromLTWH(0, 0, 90, 90),
sliceLeft: 10,
sliceTop: 10,
sliceRight: 10,
sliceBottom: 10,
sourceInset: 0.5,
);
expect(parts.first.source, const Rect.fromLTRB(10.5, 20.5, 19.5, 29.5));
expect(parts[4].source, const Rect.fromLTRB(20.5, 30.5, 29.5, 39.5));
expect(parts.last.source, const Rect.fromLTRB(30.5, 40.5, 39.5, 49.5));
});
test('keeps tiny nine-slice source rects when inset would collapse them', () {
final parts = runtimeNineSliceRects(
source: const Rect.fromLTWH(0, 0, 3, 3),
destination: const Rect.fromLTWH(0, 0, 30, 30),
sliceLeft: 1,
sliceTop: 1,
sliceRight: 1,
sliceBottom: 1,
sourceInset: 0.5,
);
expect(parts[4].source, const Rect.fromLTRB(1, 1, 2, 2));
});
test('updates text alpha style without rebuilding text component', () {
final component = RuntimeComponent(
node: const RuntimeNode(