Trait lux::modifiers::Colored [] [src]

pub trait Colored {
    fn get_color(&self) -> [Float; 4];
    fn color<C: Color>(&mut self, color: C) -> &mut Self;

    fn with_color<F, C: Color>(&mut self, color: C, f: F) where F: FnOnce(&mut Self) { ... }
}

A trait representing objects that can be colored with seperate fill colors and stroke colors.

The basic representation of a color is an array of 4 floats where each value goes from 0.0 to 1.0 and is of the form [r, b, b, a].

Required Methods

fn get_color(&self) -> [Float; 4]

Returns the current color.

fn color<C: Color>(&mut self, color: C) -> &mut Self

Sets the color.

Provided Methods

fn with_color<F, C: Color>(&mut self, color: C, f: F) where F: FnOnce(&mut Self)

Executes a closure with the given color, then resets it to what it was before.

Example

frame.with_color(rgb(255, 0, 0), |frame| {
    frame.rect(0.0, 0.0, 50.0, 50.0).fill();
    frame.rect(0.0, 51.0, 50.0, 50.0).fill();
    frame.rect(51.0, 0.0, 50.0, 50.0).fill();
});

Implementors