|
| 1 | +//! A dummy implementation of the AnyRender traits while simply ignores all commands |
| 2 | +
|
| 3 | +use crate::{ImageRenderer, PaintScene, WindowHandle, WindowRenderer}; |
| 4 | +use std::sync::Arc; |
| 5 | + |
| 6 | +#[derive(Copy, Clone, Default)] |
| 7 | +pub struct NullWindowRenderer { |
| 8 | + is_active: bool, |
| 9 | +} |
| 10 | + |
| 11 | +impl NullWindowRenderer { |
| 12 | + pub fn new() -> Self { |
| 13 | + Self::default() |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +impl WindowRenderer for NullWindowRenderer { |
| 18 | + type ScenePainter<'a> |
| 19 | + = NullScenePainter |
| 20 | + where |
| 21 | + Self: 'a; |
| 22 | + |
| 23 | + fn resume(&mut self, _window: Arc<dyn WindowHandle>, _width: u32, _height: u32) { |
| 24 | + self.is_active = true; |
| 25 | + } |
| 26 | + |
| 27 | + fn suspend(&mut self) { |
| 28 | + self.is_active = false |
| 29 | + } |
| 30 | + |
| 31 | + fn is_active(&self) -> bool { |
| 32 | + self.is_active |
| 33 | + } |
| 34 | + |
| 35 | + fn set_size(&mut self, _width: u32, _height: u32) {} |
| 36 | + |
| 37 | + fn render<F: FnOnce(&mut Self::ScenePainter<'_>)>(&mut self, _draw_fn: F) {} |
| 38 | +} |
| 39 | + |
| 40 | +#[derive(Copy, Clone, Default)] |
| 41 | +pub struct NullImageRenderer; |
| 42 | + |
| 43 | +impl NullImageRenderer { |
| 44 | + pub fn new() -> Self { |
| 45 | + Self::default() |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +impl ImageRenderer for NullImageRenderer { |
| 50 | + type ScenePainter<'a> |
| 51 | + = NullScenePainter |
| 52 | + where |
| 53 | + Self: 'a; |
| 54 | + |
| 55 | + fn new(_width: u32, _height: u32) -> Self { |
| 56 | + Self |
| 57 | + } |
| 58 | + |
| 59 | + fn resize(&mut self, _width: u32, _height: u32) {} |
| 60 | + |
| 61 | + fn reset(&mut self) {} |
| 62 | + |
| 63 | + fn render_to_vec<F: FnOnce(&mut Self::ScenePainter<'_>)>( |
| 64 | + &mut self, |
| 65 | + _draw_fn: F, |
| 66 | + _vec: &mut Vec<u8>, |
| 67 | + ) { |
| 68 | + } |
| 69 | + |
| 70 | + fn render<F: FnOnce(&mut Self::ScenePainter<'_>)>(&mut self, _draw_fn: F, _buffer: &mut [u8]) {} |
| 71 | +} |
| 72 | + |
| 73 | +#[derive(Copy, Clone, Default)] |
| 74 | +pub struct NullScenePainter; |
| 75 | + |
| 76 | +impl NullScenePainter { |
| 77 | + pub fn new() -> Self { |
| 78 | + Self::default() |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +impl PaintScene for NullScenePainter { |
| 83 | + fn reset(&mut self) {} |
| 84 | + |
| 85 | + fn push_layer( |
| 86 | + &mut self, |
| 87 | + _blend: impl Into<peniko::BlendMode>, |
| 88 | + _alpha: f32, |
| 89 | + _transform: kurbo::Affine, |
| 90 | + _clip: &impl kurbo::Shape, |
| 91 | + ) { |
| 92 | + } |
| 93 | + |
| 94 | + fn pop_layer(&mut self) {} |
| 95 | + |
| 96 | + fn stroke<'a>( |
| 97 | + &mut self, |
| 98 | + _style: &kurbo::Stroke, |
| 99 | + _transform: kurbo::Affine, |
| 100 | + _brush: impl Into<crate::PaintRef<'a>>, |
| 101 | + _brush_transform: Option<kurbo::Affine>, |
| 102 | + _shape: &impl kurbo::Shape, |
| 103 | + ) { |
| 104 | + } |
| 105 | + |
| 106 | + fn fill<'a>( |
| 107 | + &mut self, |
| 108 | + _style: peniko::Fill, |
| 109 | + _transform: kurbo::Affine, |
| 110 | + _brush: impl Into<crate::PaintRef<'a>>, |
| 111 | + _brush_transform: Option<kurbo::Affine>, |
| 112 | + _shape: &impl kurbo::Shape, |
| 113 | + ) { |
| 114 | + } |
| 115 | + |
| 116 | + fn draw_glyphs<'a, 's: 'a>( |
| 117 | + &'s mut self, |
| 118 | + _font: &'a peniko::FontData, |
| 119 | + _font_size: f32, |
| 120 | + _hint: bool, |
| 121 | + _normalized_coords: &'a [crate::NormalizedCoord], |
| 122 | + _style: impl Into<peniko::StyleRef<'a>>, |
| 123 | + _brush: impl Into<crate::PaintRef<'a>>, |
| 124 | + _brush_alpha: f32, |
| 125 | + _transform: kurbo::Affine, |
| 126 | + _glyph_transform: Option<kurbo::Affine>, |
| 127 | + _glyphs: impl Iterator<Item = crate::Glyph>, |
| 128 | + ) { |
| 129 | + } |
| 130 | + |
| 131 | + fn draw_box_shadow( |
| 132 | + &mut self, |
| 133 | + _transform: kurbo::Affine, |
| 134 | + _rect: kurbo::Rect, |
| 135 | + _brush: peniko::Color, |
| 136 | + _radius: f64, |
| 137 | + _std_dev: f64, |
| 138 | + ) { |
| 139 | + } |
| 140 | +} |
0 commit comments