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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//! Semantic paint batches captured before serialization.
use super::{InkExtent, PanelPath, Rect};
use crate::elements::LayerSlot;
/// Semantic role of an actual closed drawing batch.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum PaintRole {
/// Root paper surface.
RootSurface,
/// Local plot paper surface.
PanelSurface,
/// Actual grid stroke batch.
Grid,
/// One closed scientific body containing combined dependent parts.
Body,
/// Scientific primary layer.
Primary,
/// Independently attached scientific layers.
Overlay,
/// Reference marks or panel annotations.
Annotation,
/// Significance marks.
Significance,
/// Scientific axes and frame.
Axes,
/// A local legend.
Legend,
/// Plot-owned prose.
Prose,
/// Independent text panel.
TextPanel,
/// One fixed local image and its independent clipping scope.
ImagePanel,
/// One fixed native output and its independent clipping scope.
FrozenPanel,
/// Canvas column and row headers.
Headers,
/// Canvas row titles.
RowTitles,
/// Facet strip.
FacetStrip,
/// Shared axis labels.
SharedAxes,
/// Shared legend.
SharedLegend,
/// Root title, subtitle and caption.
RootProse,
}
/// Semantic identity of a closed paint batch, independent of serializer offsets.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PaintBatchRef {
owner: PanelPath,
role: PaintRole,
layer: Option<LayerSlot>,
}
impl PaintBatchRef {
pub(crate) fn new(owner: &PanelPath, role: PaintRole, layer: Option<LayerSlot>) -> Self {
Self {
owner: owner.clone(),
role,
layer,
}
}
/// Actual native panel or shared root owner.
pub fn owner(&self) -> &PanelPath {
&self.owner
}
/// Actual painting role.
pub const fn role(&self) -> PaintRole {
self.role
}
/// An actual declaration slot when this closed batch has a single such owner.
pub const fn layer(&self) -> Option<LayerSlot> {
self.layer
}
}
/// A closed batch in physical paint order, with its actual rectangular clips.
#[derive(Clone, PartialEq)]
pub struct PaintBatch {
pub(crate) reference: PaintBatchRef,
pub(crate) clips: Vec<Rect>,
pub(crate) ink: InkExtent,
// The four actual native emission buffers. The offsets identify the closed
// insertion gap in the retained native representation, never a public ID.
pub(crate) buffer: usize,
pub(crate) range: std::ops::Range<usize>,
}
impl std::fmt::Debug for PaintBatch {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("PaintBatch")
.field("reference", &self.reference)
.field("clips", &self.clips)
.field("ink", &self.ink)
.finish_non_exhaustive()
}
}
impl PaintBatch {
/// Semantic reference to the batch.
pub fn reference(&self) -> &PaintBatchRef {
&self.reference
}
/// Actual owner.
pub fn owner(&self) -> &PanelPath {
self.reference.owner()
}
/// Painting role.
pub const fn role(&self) -> PaintRole {
self.reference.role()
}
/// Actual rectangular clip scopes reached by this batch.
pub fn clips(&self) -> &[Rect] {
&self.clips
}
/// Reliable painted bounds, empty or unknown.
pub const fn ink(&self) -> InkExtent {
self.ink
}
}
/// Reference to one actual gap between adjacent closed native batches.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BoundaryRef {
pub(super) owner: PanelPath,
pub(super) behind: Option<PaintBatchRef>,
pub(super) ahead: Option<PaintBatchRef>,
}
impl BoundaryRef {
pub(crate) fn between(behind: Option<&PaintBatch>, ahead: Option<&PaintBatch>) -> Self {
// All currently exposed gaps close their layer and clip scopes in the
// actual root. Neither neighboring batch lends its local clip.
Self {
owner: PanelPath::root(),
behind: behind.map(|batch| batch.reference.clone()),
ahead: ahead.map(|batch| batch.reference.clone()),
}
}
/// Common closed paint scope of the adjacent batches.
pub fn owner(&self) -> &PanelPath {
&self.owner
}
/// Actual immediately preceding batch, absent at the root's first gap.
pub fn behind(&self) -> Option<&PaintBatchRef> {
self.behind.as_ref()
}
/// Actual immediately following batch, absent at the root's final gap.
pub fn ahead(&self) -> Option<&PaintBatchRef> {
self.ahead.as_ref()
}
}