pub trait Draw: Renderable {
// Required method
fn draw(
&self,
console: &Console,
options: &ConsoleOptions,
screen: &mut Screen,
rect: Rect,
);
}Expand description
Drawing straight into a Screen’s cells: rs-rich-ext’s fast path.
rich renders to Segments, each owning its text and a [Style]
(whose colours own their names), and a Screen turns those back into
cells. rich’s path is the faithful one, and stays the reference: rich’s
public types are unchanged. A renderable that also implements Draw
writes the same cells without building them: its own data goes into
the screen’s cells with each style interned once
(Screen::write_runs, Screen::put_rgb, Screen::put).
rs-rich-ext’s charts implement it, and intuiTUIve draws with it by
default.
rich’s path is draw_rendered: render, then Screen::write_lines.
An implementation must give the same cells as it (the tests compare the
two for every chart that has one).
use rich::Console;
use rich_ext::chart::{Dataset, Chart};
use rich_ext::surface::{Draw, Rect, Screen};
let console = Console::builder().width(30).build();
let options = console.options().update_width(30).update_height(8);
let chart = Chart::new([Dataset::new([(0.0, 0.0), (1.0, 1.0), (2.0, 0.5)])]);
let rect = Rect::new(0, 0, 30, 8);
let mut fast = Screen::new(30, 8);
chart.draw(&console, &options, &mut fast, rect);
let mut rich_path = Screen::new(30, 8);
rich_path.write_lines(rect, &console.render_lines(&chart, &options, false));
assert_eq!(fast.lines(), rich_path.lines());Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".