function.dart
1.96 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
import '../../render/layout/line.dart';
import '../options.dart';
import '../spacing.dart';
import '../syntax_tree.dart';
/// Function node
///
/// Examples: `\sin`, `\lim`, `\operatorname`
class FunctionNode extends SlotableNode<EquationRowNode> {
/// Name of the function.
final EquationRowNode functionName;
/// Argument of the function.
final EquationRowNode argument;
FunctionNode({
required this.functionName,
required this.argument,
});
@override
BuildResult buildWidget(
MathOptions options, List<BuildResult?> childBuildResults) =>
BuildResult(
options: options,
widget: Line(children: [
LineElement(
trailingMargin:
getSpacingSize(AtomType.op, argument.leftType, options.style)
.toLpUnder(options),
child: childBuildResults[0]!.widget,
),
LineElement(
trailingMargin: 0.0,
child: childBuildResults[1]!.widget,
),
]),
);
@override
List<MathOptions> computeChildOptions(MathOptions options) =>
List.filled(2, options, growable: false);
@override
List<EquationRowNode> computeChildren() => [functionName, argument];
@override
AtomType get leftType => AtomType.op;
@override
AtomType get rightType => argument.rightType;
@override
bool shouldRebuildWidget(MathOptions oldOptions, MathOptions newOptions) =>
false;
@override
FunctionNode updateChildren(List<EquationRowNode> newChildren) =>
copyWith(functionName: newChildren[0], argument: newChildren[1]);
@override
Map<String, Object?> toJson() => super.toJson()
..addAll({
'functionName': functionName.toJson(),
'argument': argument.toJson(),
});
FunctionNode copyWith({
EquationRowNode? functionName,
EquationRowNode? argument,
}) =>
FunctionNode(
functionName: functionName ?? this.functionName,
argument: argument ?? this.argument,
);
}