[−][src]Struct iced::widget::canvas::Canvas
This is supported on
feature="canvas"
only.A widget capable of drawing 2D graphics.
A Canvas
may contain multiple layers. A Layer
is drawn using the
painter's algorithm. In other words, layers will be drawn on top of each
other in the same order they are pushed into the Canvas
.
Examples
The repository has a couple of examples showcasing how to use a
Canvas
:
clock
, an application that uses theCanvas
widget to draw a clock and its hands to display the current time.solar_system
, an animated solar system drawn using theCanvas
widget and showcasing how to compose different transforms.
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, layer, Canvas, Drawable, Fill, Frame, Path}; use iced::Color; // First, we define the data we need for drawing #[derive(Debug)] struct Circle { radius: f32, } // Then, we implement the `Drawable` trait impl Drawable for Circle { fn draw(&self, frame: &mut Frame) { // We create a `Path` representing a simple circle let circle = Path::new(|p| p.circle(frame.center(), self.radius)); // And fill it with some color frame.fill(&circle, Fill::Color(Color::BLACK)); } } // We can use a `Cache` to avoid unnecessary re-tessellation let cache: layer::Cache<Circle> = layer::Cache::new(); // Finally, we simply provide the data to our `Cache` and push the resulting // layer into a `Canvas` let canvas = Canvas::new() .push(cache.with(&Circle { radius: 50.0 }));
Methods
impl<'a> Canvas<'a>
[src]
pub fn new() -> Canvas<'a>
[src]
This is supported on
feature="canvas"
only.Creates a new Canvas
with no layers.
pub fn width(self, width: Length) -> Canvas<'a>
[src]
This is supported on
feature="canvas"
only.Sets the width of the Canvas
.
pub fn height(self, height: Length) -> Canvas<'a>
[src]
This is supported on
feature="canvas"
only.Sets the height of the Canvas
.
pub fn push(self, layer: impl Layer + 'a) -> Canvas<'a>
[src]
This is supported on
feature="canvas"
only.Trait Implementations
impl<'a> Debug for Canvas<'a>
[src]
impl<'a, Message> Widget<Message, Renderer> for Canvas<'a>
[src]
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, _renderer: &Renderer, limits: &Limits) -> Node
[src]
fn draw(
&self,
_renderer: &mut Renderer,
_defaults: &Defaults,
layout: Layout,
_cursor_position: Point
) -> (Primitive, MouseCursor)
[src]
&self,
_renderer: &mut Renderer,
_defaults: &Defaults,
layout: Layout,
_cursor_position: Point
) -> (Primitive, MouseCursor)
fn hash_layout(&self, state: &mut Hasher)
[src]
fn on_event(
&mut self,
_event: Event,
_layout: Layout,
_cursor_position: Point,
_messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
&mut self,
_event: Event,
_layout: Layout,
_cursor_position: Point,
_messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Canvas<'a>
impl<'a> !Send for Canvas<'a>
impl<'a> !Sync for Canvas<'a>
impl<'a> Unpin for Canvas<'a>
impl<'a> !UnwindSafe for Canvas<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,