tui_temp_fork/widgets/canvas/
map.rs

1use crate::style::Color;
2use crate::widgets::canvas::points::PointsIterator;
3use crate::widgets::canvas::world::{WORLD_HIGH_RESOLUTION, WORLD_LOW_RESOLUTION};
4use crate::widgets::canvas::Shape;
5
6#[derive(Clone, Copy)]
7pub enum MapResolution {
8    Low,
9    High,
10}
11
12impl MapResolution {
13    fn data(self) -> &'static [(f64, f64)] {
14        match self {
15            MapResolution::Low => &WORLD_LOW_RESOLUTION,
16            MapResolution::High => &WORLD_HIGH_RESOLUTION,
17        }
18    }
19}
20
21/// Shape to draw a world map with the given resolution and color
22pub struct Map {
23    pub resolution: MapResolution,
24    pub color: Color,
25}
26
27impl Default for Map {
28    fn default() -> Map {
29        Map {
30            resolution: MapResolution::Low,
31            color: Color::Reset,
32        }
33    }
34}
35
36impl<'a> Shape<'a> for Map {
37    fn color(&self) -> Color {
38        self.color
39    }
40    fn points(&'a self) -> Box<dyn Iterator<Item = (f64, f64)> + 'a> {
41        Box::new(self.into_iter())
42    }
43}
44
45impl<'a> IntoIterator for &'a Map {
46    type Item = (f64, f64);
47    type IntoIter = PointsIterator<'a>;
48    fn into_iter(self) -> Self::IntoIter {
49        PointsIterator::from(self.resolution.data())
50    }
51}