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
use prototty_render::*; #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] #[derive(Debug, Clone, Copy)] pub struct FillBackgroundView<V> { pub view: V, } impl<V> FillBackgroundView<V> { pub fn new(view: V) -> Self { Self { view } } } #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] #[derive(Debug, Clone, Copy)] pub struct FillBackgroundData<T> { pub background: Rgb24, pub data: T, } impl<'a, T, V: View<&'a T>> View<&'a FillBackgroundData<T>> for FillBackgroundView<V> { fn view<G: ViewGrid, R: ViewTransformRgb24>( &mut self, &FillBackgroundData { background, ref data, }: &'a FillBackgroundData<T>, context: ViewContext<R>, grid: &mut G, ) { self.view(FillBackgroundData { background, data }, context, grid); } fn visible_bounds<R: ViewTransformRgb24>( &mut self, &FillBackgroundData { background, ref data, }: &'a FillBackgroundData<T>, context: ViewContext<R>, ) -> Size { self.visible_bounds(FillBackgroundData { background, data }, context) } } impl<T, V: View<T>> View<FillBackgroundData<T>> for FillBackgroundView<V> { fn view<G: ViewGrid, R: ViewTransformRgb24>( &mut self, FillBackgroundData { background, data }: FillBackgroundData<T>, context: ViewContext<R>, grid: &mut G, ) { let size = self.view .view_reporting_intended_size(data, context.add_depth(1), grid); for y in 0..(size.height() as i32) { for x in 0..(size.width() as i32) { let coord = Coord::new(x, y); grid.set_cell_relative( coord, 0, ViewCell::new() .with_background(background) .with_character(' '), context, ); } } } fn visible_bounds<R: ViewTransformRgb24>( &mut self, FillBackgroundData { background: _, data, }: FillBackgroundData<T>, context: ViewContext<R>, ) -> Size { self.view.visible_bounds(data, context) } }