diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2023-03-31 22:57:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-31 22:57:37 +0100 |
| commit | a515b06bcb556c1be2d0fc3095cd778d413fe40d (patch) | |
| tree | 4b544de9aa53d6976177c08b91aa3943ef4d9e92 /src/ratatui/widgets/canvas/map.rs | |
| parent | feat: add github action to test the nix builds (#833) (diff) | |
| download | atuin-a515b06bcb556c1be2d0fc3095cd778d413fe40d.zip | |
Vendor ratatui temporarily (#835)
* Vendor ratatui temporarily
Once https://github.com/tui-rs-revival/ratatui/pull/114 has been merged,
we can undo this! But otherwise we can't publish to crates.io with a git
dependency.
* make tests pass
* Shush.
* these literally just fail in nix, nowhere else
idk how to work with nix properly, and they're also not our tests
Diffstat (limited to 'src/ratatui/widgets/canvas/map.rs')
| -rw-r--r-- | src/ratatui/widgets/canvas/map.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/ratatui/widgets/canvas/map.rs b/src/ratatui/widgets/canvas/map.rs new file mode 100644 index 00000000..d835dd31 --- /dev/null +++ b/src/ratatui/widgets/canvas/map.rs @@ -0,0 +1,48 @@ +use crate::ratatui::{ + style::Color, + widgets::canvas::{ + world::{WORLD_HIGH_RESOLUTION, WORLD_LOW_RESOLUTION}, + Painter, Shape, + }, +}; + +#[derive(Debug, Clone, Copy)] +pub enum MapResolution { + Low, + High, +} + +impl MapResolution { + fn data(self) -> &'static [(f64, f64)] { + match self { + MapResolution::Low => &WORLD_LOW_RESOLUTION, + MapResolution::High => &WORLD_HIGH_RESOLUTION, + } + } +} + +/// Shape to draw a world map with the given resolution and color +#[derive(Debug, Clone)] +pub struct Map { + pub resolution: MapResolution, + pub color: Color, +} + +impl Default for Map { + fn default() -> Map { + Map { + resolution: MapResolution::Low, + color: Color::Reset, + } + } +} + +impl Shape for Map { + fn draw(&self, painter: &mut Painter) { + for (x, y) in self.resolution.data() { + if let Some((x, y)) = painter.get_point(*x, *y) { + painter.paint(x, y, self.color); + } + } + } +} |
