lichtung_plot/layout/
paint.rs1use super::{InkExtent, PanelPath, Rect};
4use crate::elements::LayerSlot;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[non_exhaustive]
9pub enum PaintRole {
10 RootSurface,
12 PanelSurface,
14 Grid,
16 Body,
18 Primary,
20 Overlay,
22 Annotation,
24 Significance,
26 Axes,
28 Legend,
30 Prose,
32 TextPanel,
34 ImagePanel,
36 FrozenPanel,
38 Headers,
40 RowTitles,
42 FacetStrip,
44 SharedAxes,
46 SharedLegend,
48 RootProse,
50}
51
52#[derive(Debug, Clone, PartialEq, Eq, Hash)]
54pub struct PaintBatchRef {
55 owner: PanelPath,
56 role: PaintRole,
57 layer: Option<LayerSlot>,
58}
59
60impl PaintBatchRef {
61 pub(crate) fn new(owner: &PanelPath, role: PaintRole, layer: Option<LayerSlot>) -> Self {
62 Self {
63 owner: owner.clone(),
64 role,
65 layer,
66 }
67 }
68
69 pub fn owner(&self) -> &PanelPath {
71 &self.owner
72 }
73
74 pub const fn role(&self) -> PaintRole {
76 self.role
77 }
78
79 pub const fn layer(&self) -> Option<LayerSlot> {
81 self.layer
82 }
83}
84
85#[derive(Clone, PartialEq)]
87pub struct PaintBatch {
88 pub(crate) reference: PaintBatchRef,
89 pub(crate) clips: Vec<Rect>,
90 pub(crate) ink: InkExtent,
91 pub(crate) buffer: usize,
94 pub(crate) range: std::ops::Range<usize>,
95}
96
97impl std::fmt::Debug for PaintBatch {
98 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
99 formatter
100 .debug_struct("PaintBatch")
101 .field("reference", &self.reference)
102 .field("clips", &self.clips)
103 .field("ink", &self.ink)
104 .finish_non_exhaustive()
105 }
106}
107
108impl PaintBatch {
109 pub fn reference(&self) -> &PaintBatchRef {
111 &self.reference
112 }
113
114 pub fn owner(&self) -> &PanelPath {
116 self.reference.owner()
117 }
118
119 pub const fn role(&self) -> PaintRole {
121 self.reference.role()
122 }
123
124 pub fn clips(&self) -> &[Rect] {
126 &self.clips
127 }
128
129 pub const fn ink(&self) -> InkExtent {
131 self.ink
132 }
133}
134
135#[derive(Debug, Clone, PartialEq, Eq, Hash)]
137pub struct BoundaryRef {
138 pub(super) owner: PanelPath,
139 pub(super) behind: Option<PaintBatchRef>,
140 pub(super) ahead: Option<PaintBatchRef>,
141}
142
143impl BoundaryRef {
144 pub(crate) fn between(behind: Option<&PaintBatch>, ahead: Option<&PaintBatch>) -> Self {
145 Self {
148 owner: PanelPath::root(),
149 behind: behind.map(|batch| batch.reference.clone()),
150 ahead: ahead.map(|batch| batch.reference.clone()),
151 }
152 }
153
154 pub fn owner(&self) -> &PanelPath {
156 &self.owner
157 }
158
159 pub fn behind(&self) -> Option<&PaintBatchRef> {
161 self.behind.as_ref()
162 }
163
164 pub fn ahead(&self) -> Option<&PaintBatchRef> {
166 self.ahead.as_ref()
167 }
168}