raise_box.dart
1.51 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
import '../../render/layout/shift_baseline.dart';
import '../options.dart';
import '../size.dart';
import '../syntax_tree.dart';
/// Raise box node which vertically displace its child.
///
/// Example: `\raisebox`
class RaiseBoxNode extends SlotableNode<EquationRowNode> {
/// Child to raise.
final EquationRowNode body;
/// Vertical displacement.
final Measurement dy;
RaiseBoxNode({
required this.body,
required this.dy,
});
@override
BuildResult buildWidget(
MathOptions options, List<BuildResult?> childBuildResults) =>
BuildResult(
options: options,
widget: ShiftBaseline(
offset: dy.toLpUnder(options),
child: childBuildResults[0]!.widget,
),
);
@override
List<MathOptions> computeChildOptions(MathOptions options) => [options];
@override
List<EquationRowNode> computeChildren() => [body];
@override
AtomType get leftType => AtomType.ord;
@override
AtomType get rightType => AtomType.ord;
@override
bool shouldRebuildWidget(MathOptions oldOptions, MathOptions newOptions) =>
false;
@override
RaiseBoxNode updateChildren(List<EquationRowNode> newChildren) =>
copyWith(body: newChildren[0]);
@override
Map<String, Object?> toJson() => super.toJson()
..addAll({
'body': body.toJson(),
'dy': dy.toString(),
});
RaiseBoxNode copyWith({
EquationRowNode? body,
Measurement? dy,
}) =>
RaiseBoxNode(
body: body ?? this.body,
dy: dy ?? this.dy,
);
}