pub struct Painter<'a, 'b> { /* private fields */ }
Expand description
Implementations§
Source§impl<'a, 'b> Painter<'a, 'b>
impl<'a, 'b> Painter<'a, 'b>
Sourcepub fn get_point(&self, x: f64, y: f64) -> Option<(usize, usize)>
pub fn get_point(&self, x: f64, y: f64) -> Option<(usize, usize)>
Convert the (x, y)
coordinates to location of a point on the grid
(x, y)
coordinates are expressed in the coordinate system of the canvas. The origin is in
the lower left corner of the canvas (unlike most other coordinates in Ratatui
where the
origin is the upper left corner). The x
and y
bounds of the canvas define the specific
area of some coordinate system that will be drawn on the canvas. The resolution of the grid
is used to convert the (x, y)
coordinates to the location of a point on the grid.
The grid coordinates are expressed in the coordinate system of the grid. The origin is in
the top left corner of the grid. The x and y bounds of the grid are always [0, width - 1]
and [0, height - 1]
respectively. The resolution of the grid is used to convert the
(x, y)
coordinates to the location of a point on the grid.
§Examples
use ratatui::{
symbols,
widgets::canvas::{Context, Painter},
};
let mut ctx = Context::new(2, 2, [1.0, 2.0], [0.0, 2.0], symbols::Marker::Braille);
let mut painter = Painter::from(&mut ctx);
let point = painter.get_point(1.0, 0.0);
assert_eq!(point, Some((0, 7)));
let point = painter.get_point(1.5, 1.0);
assert_eq!(point, Some((1, 3)));
let point = painter.get_point(0.0, 0.0);
assert_eq!(point, None);
let point = painter.get_point(2.0, 2.0);
assert_eq!(point, Some((3, 0)));
let point = painter.get_point(1.0, 2.0);
assert_eq!(point, Some((0, 0)));
Sourcepub fn paint(&mut self, x: usize, y: usize, color: Color)
pub fn paint(&mut self, x: usize, y: usize, color: Color)
Paint a point of the grid
§Example
use ratatui::{
style::Color,
symbols,
widgets::canvas::{Context, Painter},
};
let mut ctx = Context::new(1, 1, [0.0, 2.0], [0.0, 2.0], symbols::Marker::Braille);
let mut painter = Painter::from(&mut ctx);
painter.paint(1, 3, Color::Red);
Trait Implementations§
Auto Trait Implementations§
impl<'a, 'b> Freeze for Painter<'a, 'b>
impl<'a, 'b> !RefUnwindSafe for Painter<'a, 'b>
impl<'a, 'b> !Send for Painter<'a, 'b>
impl<'a, 'b> !Sync for Painter<'a, 'b>
impl<'a, 'b> Unpin for Painter<'a, 'b>
impl<'a, 'b> !UnwindSafe for Painter<'a, 'b>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more