[][src]Struct iced::widget::canvas::Canvas

pub struct Canvas<Message, P> where
    P: Program<Message>, 
{ /* fields omitted */ }
This is supported on feature="canvas" or feature="glow_canvas" only.

A widget capable of drawing 2D graphics.

Examples

The repository has a couple of examples showcasing how to use a Canvas:

Drawing a simple circle

If you want to get a quick overview, here's how we can draw a simple circle:

use iced::canvas::{self, Canvas, Cursor, Fill, Frame, Geometry, Path, Program};
use iced::{Color, Rectangle};

// First, we define the data we need for drawing
#[derive(Debug)]
struct Circle {
    radius: f32,
}

// Then, we implement the `Program` trait
impl Program<()> for Circle {
    fn draw(&self, bounds: Rectangle, _cursor: Cursor) -> Vec<Geometry>{
        // We prepare a new `Frame`
        let mut frame = Frame::new(bounds.size());

        // We create a `Path` representing a simple circle
        let circle = Path::circle(frame.center(), self.radius);

        // And fill it with some color
        frame.fill(&circle, Color::BLACK);

        // Finally, we produce the geometry
        vec![frame.into_geometry()]
    }
}

// Finally, we simply use our `Circle` to create the `Canvas`!
let canvas = Canvas::new(Circle { radius: 50.0 });

Implementations

impl<Message, P> Canvas<Message, P> where
    P: Program<Message>, 
[src]

pub fn new(program: P) -> Canvas<Message, P>[src]

This is supported on feature="canvas" or feature="glow_canvas" only.

Creates a new Canvas.

pub fn width(self, width: Length) -> Canvas<Message, P>[src]

This is supported on feature="canvas" or feature="glow_canvas" only.

Sets the width of the Canvas.

pub fn height(self, height: Length) -> Canvas<Message, P>[src]

This is supported on feature="canvas" or feature="glow_canvas" only.

Sets the height of the Canvas.

Trait Implementations

impl<Message, P> Debug for Canvas<Message, P> where
    Message: Debug,
    P: Program<Message> + Debug
[src]

impl<Message, P, B> Widget<Message, Renderer<B>> for Canvas<Message, P> where
    B: Backend,
    P: Program<Message>, 
[src]

Auto Trait Implementations

impl<Message, P> RefUnwindSafe for Canvas<Message, P> where
    Message: RefUnwindSafe,
    P: RefUnwindSafe

impl<Message, P> Send for Canvas<Message, P> where
    Message: Send,
    P: Send

impl<Message, P> Sync for Canvas<Message, P> where
    Message: Sync,
    P: Sync

impl<Message, P> Unpin for Canvas<Message, P> where
    Message: Unpin,
    P: Unpin

impl<Message, P> UnwindSafe for Canvas<Message, P> where
    Message: UnwindSafe,
    P: UnwindSafe

Blanket Implementations

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
    D: AdaptFrom<S, Swp, Dwp, T>,
    Dwp: WhitePoint,
    Swp: WhitePoint,
    T: Component + Float
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> ConvertInto<U> for T where
    U: ConvertFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SetParameter for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,