rumatui_tui/widgets/canvas/
map.rs1use crate::{
2 style::Color,
3 widgets::canvas::{
4 world::{WORLD_HIGH_RESOLUTION, WORLD_LOW_RESOLUTION},
5 Painter, Shape,
6 },
7};
8
9#[derive(Debug, Clone, Copy)]
10pub enum MapResolution {
11 Low,
12 High,
13}
14
15impl MapResolution {
16 fn data(self) -> &'static [(f64, f64)] {
17 match self {
18 MapResolution::Low => &WORLD_LOW_RESOLUTION,
19 MapResolution::High => &WORLD_HIGH_RESOLUTION,
20 }
21 }
22}
23
24#[derive(Debug, Clone)]
26pub struct Map {
27 pub resolution: MapResolution,
28 pub color: Color,
29}
30
31impl Default for Map {
32 fn default() -> Map {
33 Map {
34 resolution: MapResolution::Low,
35 color: Color::Reset,
36 }
37 }
38}
39
40impl Shape for Map {
41 fn draw(&self, painter: &mut Painter) {
42 for (x, y) in self.resolution.data() {
43 if let Some((x, y)) = painter.get_point(*x, *y) {
44 painter.paint(x, y, self.color);
45 }
46 }
47 }
48}