ratatui_widgets/canvas/
points.rs

1use ratatui_core::style::Color;
2
3use crate::canvas::{Painter, Shape};
4
5/// A group of points with a given color
6#[derive(Debug, Default, Clone, PartialEq)]
7pub struct Points<'a> {
8    /// List of points to draw
9    pub coords: &'a [(f64, f64)],
10    /// Color of the points
11    pub color: Color,
12}
13
14impl<'a> Points<'a> {
15    /// Create a new Points shape with the given coordinates and color
16    pub const fn new(coords: &'a [(f64, f64)], color: Color) -> Self {
17        Self { coords, color }
18    }
19}
20
21impl Shape for Points<'_> {
22    fn draw(&self, painter: &mut Painter) {
23        for (x, y) in self.coords {
24            if let Some((x, y)) = painter.get_point(*x, *y) {
25                painter.paint(x, y, self.color);
26            }
27        }
28    }
29}