[][src]Trait embedded_graphics::drawable::Drawable

pub trait Drawable<C> where
    C: PixelColor
{ fn draw<T: DrawTarget<C>>(self, display: &mut T); }

Marks an object as "drawable". Must be implemented for all graphics objects

The Drawable trait describes how a particular graphical object is drawn. A Drawable object can define its draw method as a collection of graphical primitives or as an iterator over pixels being rendered with DrawTarget's draw_iter method.

use embedded_graphics::{
    egrectangle, egtext,
    fonts::Font6x8,
    geometry::Point,
    pixelcolor::{BinaryColor, PixelColor, Rgb888},
    prelude::*,
    primitive_style, text_style,
};

struct Button<'a, C: PixelColor> {
    top_left: Point,
    bottom_right: Point,
    bg_color: C,
    fg_color: C,
    text: &'a str,
}

impl<'a, C: 'a> Drawable<C> for &Button<'a, C>
where
    C: PixelColor + From<BinaryColor>,
{
    fn draw<D: DrawTarget<C>>(self, display: &mut D) {
        egrectangle!(
            top_left = self.top_left,
            bottom_right = self.bottom_right,
            style = primitive_style!(fill_color = self.bg_color)
        )
        .draw(display);
        egtext!(
            text = self.text,
            top_left = (20, 20),
            style = text_style!(font = Font6x8, text_color = self.fg_color)
        )
        .draw(display);
    }
}

fn main() {
    let mut button = Button {
        top_left: Point::zero(),
        bottom_right: Point::new(100, 50),
        bg_color: Rgb888::RED,
        fg_color: Rgb888::BLUE,
        text: "Click me!",
    };
    button.draw(&mut display);
}

Required methods

fn draw<T: DrawTarget<C>>(self, display: &mut T)

Draw the graphics object using the supplied DrawTarget.

Loading content...

Implementors

impl<'_, '_, C, F> Drawable<C> for &'_ Styled<Text<'_>, TextStyle<C, F>> where
    C: PixelColor,
    F: Font + Copy
[src]

impl<'_, C> Drawable<C> for &'_ Styled<Rectangle, PrimitiveStyle<C>> where
    C: PixelColor
[src]

impl<'_, C, T> Drawable<C> for &'_ mut T where
    C: PixelColor,
    T: Iterator<Item = Pixel<C>>, 
[src]

impl<'a, '_, C: 'a> Drawable<C> for &'_ ImageBmp<'a, C> where
    C: PixelColor + From<<C as PixelColor>::Raw>, 
[src]

impl<'a, '_, C: 'a> Drawable<C> for &'_ Styled<Circle, PrimitiveStyle<C>> where
    C: PixelColor
[src]

impl<'a, '_, C: 'a> Drawable<C> for &'_ Styled<Line, PrimitiveStyle<C>> where
    C: PixelColor
[src]

impl<'a, '_, C: 'a> Drawable<C> for &'_ Styled<Triangle, PrimitiveStyle<C>> where
    C: PixelColor
[src]

impl<'a, C: 'a> Drawable<C> for &'a ImageTga<'a, C> where
    C: PixelColor + From<<C as PixelColor>::Raw>, 
[src]

impl<'a, C: 'a, BO: 'a> Drawable<C> for &'a Image<'a, C, BO> where
    C: PixelColor + From<<C as PixelColor>::Raw>,
    BO: ByteOrder,
    RawDataIter<'a, C::Raw, BO>: Iterator<Item = C::Raw>, 
[src]

impl<C> Drawable<C> for Pixel<C> where
    C: PixelColor
[src]

Loading content...