phantom.dart
1.93 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 'package:flutter/cupertino.dart';
import '../../render/layout/reset_dimension.dart';
import '../options.dart';
import '../syntax_tree.dart';
import '../types.dart';
/// Phantom node.
///
/// Example: `\phantom` `\hphantom`.
class PhantomNode extends LeafNode {
Mode get mode => Mode.math;
/// The phantomed child.
// TODO: suppress editbox in edit mode
// If we use arbitrary GreenNode here, then we will face the danger of
// transparent node
final EquationRowNode phantomChild;
/// Whether to eliminate width.
final bool zeroWidth;
/// Whether to eliminate height.
final bool zeroHeight;
/// Whether to eliminate depth.
final bool zeroDepth;
PhantomNode({
required this.phantomChild,
this.zeroHeight = false,
this.zeroWidth = false,
this.zeroDepth = false,
});
@override
BuildResult buildWidget(
MathOptions options, List<BuildResult?> childBuildResults) {
final phantomRedNode =
SyntaxNode(parent: null, value: phantomChild, pos: 0);
final phantomResult = phantomRedNode.buildWidget(options);
Widget widget = Opacity(
opacity: 0.0,
child: phantomResult.widget,
);
widget = ResetDimension(
width: zeroWidth ? 0 : null,
height: zeroHeight ? 0 : null,
depth: zeroDepth ? 0 : null,
child: widget,
);
return BuildResult(
options: options,
italic: phantomResult.italic,
widget: widget,
);
}
@override
AtomType get leftType => phantomChild.leftType;
@override
AtomType get rightType => phantomChild.rightType;
@override
bool shouldRebuildWidget(MathOptions oldOptions, MathOptions newOptions) =>
phantomChild.shouldRebuildWidget(oldOptions, newOptions);
@override
Map<String, Object?> toJson() => super.toJson()
..addAll({
'phantomChild': phantomChild.toJson(),
if (zeroWidth != false) 'zeroWidth': zeroWidth,
if (zeroHeight != false) 'zeroHeight': zeroHeight,
});
}