Skip to main content

Shapes

Trait Shapes 

Source
pub trait Shapes {
    type Ink: Copy;

    // Required methods
    fn stroke_rect(&mut self, area: Area, ink: Self::Ink);
    fn fill_rect(&mut self, area: Area, ink: Self::Ink);
    fn line(&mut self, from: (i32, i32), to: (i32, i32), ink: Self::Ink);
    fn bar(
        &mut self,
        area: Area,
        fraction: f32,
        fill: Self::Ink,
        track: Self::Ink,
    );
    fn rounded_rect(&mut self, area: Area, radius: u32, ink: Self::Ink);
    fn fill_rounded_rect(&mut self, area: Area, radius: u32, ink: Self::Ink);
    fn circle(&mut self, centre: (f32, f32), radius: f32, ink: Self::Ink);
    fn fill_circle(&mut self, centre: (f32, f32), radius: f32, ink: Self::Ink);
    fn label(&mut self, x: i32, y: i32, text: &str, ink: Self::Ink) -> u32;
}
Expand description

Shapes both surface models draw. Ink is what paints: a style for cells, a colour for pixels.

Required Associated Types§

Required Methods§

Source

fn stroke_rect(&mut self, area: Area, ink: Self::Ink)

A one-unit outline of area.

Source

fn fill_rect(&mut self, area: Area, ink: Self::Ink)

area, filled.

Source

fn line(&mut self, from: (i32, i32), to: (i32, i32), ink: Self::Ink)

A line from from to to, both ends included.

Source

fn bar(&mut self, area: Area, fraction: f32, fill: Self::Ink, track: Self::Ink)

A horizontal bar across area: the left fraction (0 to 1) in fill, the rest in track. Partial units are shown with eighth blocks (cells) or coverage (pixels).

Source

fn rounded_rect(&mut self, area: Area, radius: u32, ink: Self::Ink)

The outline of area with corners of radius (cells round their corners with arcs whatever the radius; a zero radius is square).

Source

fn fill_rounded_rect(&mut self, area: Area, radius: u32, ink: Self::Ink)

area filled, with corners of radius.

Source

fn circle(&mut self, centre: (f32, f32), radius: f32, ink: Self::Ink)

A circle’s outline around centre, in continuous coordinates: the unit at (x, y) spans x..x + 1, so (x + 0.5, y + 0.5) is its centre, and a moving shape can sit between units (pixels antialias it; cells round to the nearest cell). Cells are about twice as tall as wide, so in cells the radius counts rows and spans twice as many columns.

Source

fn fill_circle(&mut self, centre: (f32, f32), radius: f32, ink: Self::Ink)

A filled circle (see Shapes::circle).

Source

fn label(&mut self, x: i32, y: i32, text: &str, ink: Self::Ink) -> u32

Text from (x, y), clipped: cells write graphemes; pixels draw the built-in 5x7 font (GLYPH_ADVANCE pixels per character, ASCII; other characters show as a box). Returns the units advanced.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§