Skip to main content

Renderable

Trait Renderable 

Source
pub trait Renderable {
    // Required method
    fn rich_render(
        &self,
        console: &Console,
        options: &ConsoleOptions,
    ) -> Vec<Segment>;

    // Provided methods
    fn measure(
        &self,
        _console: &Console,
        options: &ConsoleOptions,
    ) -> Measurement { ... }
    fn fit_to_measurement(&self) -> bool { ... }
}
Expand description

Anything that can be rendered to a stream of Segments within a width.

The Rust equivalent of upstream’s __rich_console__(console, options) protocol. Implement it to make a custom type printable by Console. The options carry the available width (and, later, height/justify) the renderable must fit into. Newlines between lines are emitted as ordinary segments containing \n.

Required Methods§

Source

fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>

Provided Methods§

Source

fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement

The (minimum, maximum) cell width this renderable wants. The default assumes the renderable fills the available width (e.g. Panel, Table); Text overrides it with its content width so the top-level print path can shrink to fit. Port of __rich_measure__ / Measurement.get.

Source

fn fit_to_measurement(&self) -> bool

Whether a top-level Console::print shrinks this renderable to its measured width. The shrink stands in for upstream’s _collect_renderables, which joins printed str/Text values; other upstream renderables render at the full width, so one whose output pads to the width it is given (Syntax’s background) returns false.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§