Struct ratatui::widgets::canvas::Painter

source ·
pub struct Painter<'a, 'b> { /* private fields */ }

Implementations§

source§

impl<'a, 'b> Painter<'a, 'b>

source

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

Examples:
use ratatui::{symbols, widgets::canvas::{Painter, Context}};

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)));
source

pub fn paint(&mut self, x: usize, y: usize, color: Color)

Paint a point of the grid

Examples:
use ratatui::{style::Color, symbols, widgets::canvas::{Painter, Context}};

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);
let cell = painter.paint(1, 3, Color::Red);

Trait Implementations§

source§

impl<'a, 'b> Debug for Painter<'a, 'b>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, 'b> From<&'a mut Context<'b>> for Painter<'a, 'b>

source§

fn from(context: &'a mut Context<'b>) -> Painter<'a, 'b>

Converts to this type from the input type.

Auto Trait Implementations§

§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.