Skip to content

Commit f10a078

Browse files
content: Redo vlist implementation to be Column based, instead of Stack
This allows the children in the vlist to expand horizontally as wide as their siblings. That will enable support for vlist's children to be center aligned if they had (or inherited) a `text-align: center`.
1 parent 7b952ee commit f10a078

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

lib/widgets/content.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,11 +1027,20 @@ class _KatexVlist extends StatelessWidget {
10271027
Widget build(BuildContext context) {
10281028
final em = DefaultTextStyle.of(context).style.fontSize!;
10291029

1030-
return Stack(children: List.unmodifiable(node.rows.map((row) {
1031-
return Transform.translate(
1032-
offset: Offset(0, row.verticalOffsetEm * em),
1033-
child: _KatexSpan(row.node));
1034-
})));
1030+
return IntrinsicWidth(
1031+
child: Column(
1032+
crossAxisAlignment: CrossAxisAlignment.stretch,
1033+
textBaseline: TextBaseline.alphabetic,
1034+
children: List.unmodifiable(node.rows.map((row) {
1035+
return SizedBox(
1036+
height: 0,
1037+
child: OverflowBox(
1038+
maxHeight: double.infinity,
1039+
child: Transform.translate(
1040+
offset: Offset(0, row.verticalOffsetEm * em),
1041+
child: _KatexSpan(row.node),
1042+
)));
1043+
}))));
10351044
}
10361045
}
10371046

test/widgets/content_test.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -677,32 +677,32 @@ void main() {
677677
group('characters render at specific offsets with specific size: ', () {
678678
final testCases = [
679679
(ContentExample.mathBlockKatexVertical1, [
680-
('a', Offset(0.0, 5.28), Size(10.88, 25.0)),
681-
('′', Offset(10.88, 1.13), Size(3.96, 17.0)),
680+
('a', Offset(0.0, 4.36), Size(10.88, 25.0)),
681+
('′', Offset(10.87, 0.26), Size(3.96, 17.0))
682682
]),
683683
(ContentExample.mathBlockKatexVertical2, [
684-
('x', Offset(0.0, 5.28), Size(11.76, 25.0)),
685-
('n', Offset(11.76, 13.65), Size(8.63, 17.0)),
684+
('x', Offset(0.0, 4.36), Size(11.76, 25.0)),
685+
('n', Offset(11.76, 12.79), Size(8.63, 17.0))
686686
]),
687687
(ContentExample.mathBlockKatexVertical3, [
688-
('e', Offset(0.0, 5.28), Size(9.58, 25.0)),
689-
('x', Offset(9.58, 2.07), Size(8.23, 17.0)),
688+
('e', Offset(0.0, 4.36), Size(9.58, 25.0)),
689+
('x', Offset(9.58, 1.20), Size(8.23, 17.0))
690690
]),
691691
(ContentExample.mathBlockKatexVertical4, [
692-
('u', Offset(0.0, 15.65), Size(8.23, 17.0)),
693-
('o', Offset(0.0, 2.07), Size(6.98, 17.0)),
692+
('u', Offset(0.0, 14.82), Size(8.23, 17.0)),
693+
('o', Offset(0.0, 1.24), Size(6.98, 17.0))
694694
]),
695695
(ContentExample.mathBlockKatexVertical5, [
696-
('a', Offset(0.0, 4.16), Size(10.88, 25.0)),
697-
('b', Offset(10.88, -0.66), Size(8.82, 25.0)),
698-
('c', Offset(19.70, 4.16), Size(8.90, 25.0)),
696+
('a', Offset(0.0, 4.24), Size(10.88, 25.0)),
697+
('b', Offset(10.87, -0.57), Size(8.82, 25.0)),
698+
('c', Offset(19.69, 4.24), Size(8.9, 25.0))
699699
]),
700700
(ContentExample.mathBlockKatexNegativeMargins, [
701-
('K', Offset(0.0, 8.64), Size(16.0, 25.0)),
702-
('A', Offset(12.50, 10.85), Size(10.79, 17.0)),
703-
('T', Offset(20.21, 9.36), Size(14.85, 25.0)),
704-
('E', Offset(31.63, 14.52), Size(14.0, 25.0)),
705-
('X', Offset(43.06, 9.85), Size(15.42, 25.0)),
701+
('K', Offset(0.0, 7.75), Size(16.0, 25.0)),
702+
('A', Offset(12.50, 9.97), Size(10.79, 17.0)),
703+
('T', Offset(20.20, 8.48), Size(14.85, 25.0)),
704+
('E', Offset(31.62, 13.64), Size(14.0, 25.0)),
705+
('X', Offset(43.05, 8.96), Size(15.42, 25.0)),
706706
]),
707707
];
708708

@@ -726,9 +726,9 @@ void main() {
726726

727727
final rect = tester.getRect(find.text(character));
728728
check(rect.topLeft - baseRect.topLeft)
729-
.within(distance: 0.02, from: topLeftOffset);
729+
.within(distance: 0.05, from: topLeftOffset);
730730
check(rect.size)
731-
.within(distance: 0.02, from: size);
731+
.within(distance: 0.05, from: size);
732732
}
733733
});
734734
}

0 commit comments

Comments
 (0)