maplibre/render/render_phase/
mod.rs1pub use draw::*;
4
5use crate::{render::tile_view_pattern::TileShape, tcs::tiles::Tile};
6
7mod draw;
8
9pub struct RenderPhase<I: PhaseItem> {
11 items: Vec<I>,
12}
13
14impl<'a, I: PhaseItem> IntoIterator for &'a RenderPhase<I> {
15 type Item = <&'a Vec<I> as IntoIterator>::Item;
16 type IntoIter = <&'a Vec<I> as IntoIterator>::IntoIter;
17
18 fn into_iter(self) -> Self::IntoIter {
19 self.items.iter()
20 }
21}
22
23impl<I: PhaseItem> Default for RenderPhase<I> {
24 fn default() -> Self {
25 Self { items: Vec::new() }
26 }
27}
28
29impl<I: PhaseItem> RenderPhase<I> {
30 pub fn add(&mut self, item: I) {
32 self.items.push(item);
33 }
34
35 pub fn sort(&mut self) {
37 self.items.sort_by_key(|d| d.sort_key());
38 }
39
40 pub fn clear(&mut self) {
41 self.items.clear();
42 }
43
44 pub fn size(&self) -> usize {
45 self.items.len()
46 }
47}
48
49pub struct LayerItem {
50 pub draw_function: Box<dyn Draw<LayerItem>>,
51 pub index: u32,
52 pub is_line: bool,
54
55 pub style_layer: String,
56
57 pub tile: Tile,
58 pub source_shape: TileShape, }
60
61impl PhaseItem for LayerItem {
62 type SortKey = u32;
63
64 fn sort_key(&self) -> Self::SortKey {
65 self.index
66 }
67
68 fn draw_function(&self) -> &dyn Draw<LayerItem> {
69 self.draw_function.as_ref()
70 }
71}
72
73pub struct TranslucentItem {
74 pub draw_function: Box<dyn Draw<TranslucentItem>>,
75 pub index: u32,
76
77 pub style_layer: String,
78
79 pub tile: Tile,
80 pub source_shape: TileShape, }
82
83impl PhaseItem for TranslucentItem {
84 type SortKey = u32;
85
86 fn sort_key(&self) -> Self::SortKey {
87 self.index
88 }
89
90 fn draw_function(&self) -> &dyn Draw<TranslucentItem> {
91 self.draw_function.as_ref()
92 }
93}
94
95pub struct TileMaskItem {
96 pub draw_function: Box<dyn Draw<TileMaskItem>>,
97 pub source_shape: TileShape,
98}
99
100impl PhaseItem for TileMaskItem {
101 type SortKey = u32;
102
103 fn sort_key(&self) -> Self::SortKey {
104 0
105 }
106
107 fn draw_function(&self) -> &dyn Draw<TileMaskItem> {
108 self.draw_function.as_ref()
109 }
110}