Skip to main content

Measure

Trait Measure 

Source
pub trait Measure {
    // Required method
    fn height_for(&self, width: u16) -> u16;
}
Expand description

A widget that can report the height it needs for a given width, before ever being rendered.

Lets a caller size a pane to fit content (e.g. a wrapped Paragraph) instead of guessing a fixed height up front. Sizing is pure content math, not drawing.

§Examples

use retroglyph_ui::widget::Measure;

struct FixedHeight(u16);

impl Measure for FixedHeight {
    fn height_for(&self, _width: u16) -> u16 {
        self.0
    }
}

assert_eq!(FixedHeight(3).height_for(80), 3);

Required Methods§

Source

fn height_for(&self, width: u16) -> u16

The number of rows this widget would need to render at width columns.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl Measure for List<'_>

Source§

impl Measure for Log<'_>

Source§

impl Measure for Panel<'_>

Source§

impl Measure for Paragraph<'_>

Available on crate feature egc only.
Source§

impl Measure for Table<'_>