under.dart
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import 'package:flutter/widgets.dart';
import '../../render/layout/min_dimension.dart';
import '../../render/layout/vlist.dart';
import '../options.dart';
import '../size.dart';
import '../style.dart';
import '../syntax_tree.dart';
/// Under node.
///
/// Examples: `\underset`
class UnderNode extends SlotableNode {
/// Base where the under node is applied upon.
final EquationRowNode base;
/// Argumentn below the base.
final EquationRowNode below;
UnderNode({
required this.base,
required this.below,
});
// KaTeX's corresponding code is in /src/functions/utils/assembleSubSup.js
@override
BuildResult buildWidget(
MathOptions options, List<BuildResult?> childBuildResults) {
final spacing = options.fontMetrics.bigOpSpacing5.cssEm.toLpUnder(options);
return BuildResult(
italic: 0.0,
options: options,
widget: Padding(
padding: EdgeInsets.only(bottom: spacing),
child: VList(
baselineReferenceWidgetIndex: 0,
children: <Widget>[
childBuildResults[0]!.widget,
// TexBook Rule 13a
MinDimension(
minHeight:
options.fontMetrics.bigOpSpacing4.cssEm.toLpUnder(options),
topPadding:
options.fontMetrics.bigOpSpacing2.cssEm.toLpUnder(options),
child: childBuildResults[1]!.widget,
),
],
),
),
);
}
@override
List<MathOptions> computeChildOptions(MathOptions options) => [
options,
options.havingStyle(options.style.sub()),
];
@override
List<EquationRowNode> computeChildren() => [base, below];
@override
AtomType get leftType => AtomType.ord;
@override
AtomType get rightType => AtomType.ord;
@override
bool shouldRebuildWidget(MathOptions oldOptions, MathOptions newOptions) =>
false;
@override
UnderNode updateChildren(List<EquationRowNode> newChildren) =>
copyWith(base: newChildren[0], below: newChildren[1]);
@override
Map<String, Object?> toJson() => super.toJson()
..addAll({
'base': base.toJson(),
'below': below.toJson(),
});
UnderNode copyWith({
EquationRowNode? base,
EquationRowNode? below,
}) =>
UnderNode(
base: base ?? this.base,
below: below ?? this.below,
);
}