accent_under.dart
3.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import '../../render/layout/vlist.dart';
import '../../render/svg/stretchy.dart';
import '../../utils/unicode_literal.dart';
import '../accents.dart';
import '../options.dart';
import '../size.dart';
import '../syntax_tree.dart';
/// AccentUnder Nodes.
///
/// Examples: `\utilde`
class AccentUnderNode extends SlotableNode<EquationRowNode> {
/// Base where the accentUnder is applied upon.
final EquationRowNode base;
/// Unicode symbol of the accent character.
final String label;
AccentUnderNode({
required this.base,
required this.label,
});
@override
BuildResult buildWidget(
MathOptions options, List<BuildResult?> childBuildResults) {
final baseResult = childBuildResults[0]!;
return BuildResult(
options: options,
italic: baseResult.italic,
skew: baseResult.skew,
widget: VList(
baselineReferenceWidgetIndex: 0,
children: <Widget>[
VListElement(
trailingMargin:
label == '\u007e' ? 0.12.cssEm.toLpUnder(options) : 0.0,
// Special case for \utilde
child: baseResult.widget,
),
VListElement(
customCrossSize: (width) => BoxConstraints(minWidth: width),
child: LayoutBuilder(
builder: (context, constraints) {
if (label == '\u00AF') {
final defaultRuleThickness = options
.fontMetrics.defaultRuleThickness.cssEm
.toLpUnder(options);
return Padding(
padding: EdgeInsets.only(top: 3 * defaultRuleThickness),
child: Container(
width: constraints.minWidth,
height: defaultRuleThickness, // TODO minRuleThickness
color: options.color,
),
);
} else {
final accentRenderConfig = accentRenderConfigs[label];
if (accentRenderConfig == null ||
accentRenderConfig.underImageName == null) {
return Container();
}
return strechySvgSpan(
accentRenderConfig.underImageName!,
constraints.minWidth,
options,
);
}
},
),
)
],
),
);
}
@override
List<MathOptions> computeChildOptions(MathOptions options) =>
[options.havingCrampedStyle()];
@override
List<EquationRowNode> computeChildren() => [base];
@override
AtomType get leftType => AtomType.ord;
@override
AtomType get rightType => AtomType.ord;
@override
bool shouldRebuildWidget(MathOptions oldOptions, MathOptions newOptions) =>
false;
@override
AccentUnderNode updateChildren(List<EquationRowNode> newChildren) =>
copyWith(base: newChildren[0]);
@override
Map<String, Object?> toJson() => super.toJson()
..addAll({
'base': base.toJson(),
'label': unicodeLiteral(label),
});
AccentUnderNode copyWith({
EquationRowNode? base,
String? label,
}) =>
AccentUnderNode(
base: base ?? this.base,
label: label ?? this.label,
);
}