[−][src]Struct iced::widget::canvas::Canvas
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
:
clock
, an application that uses theCanvas
widget to draw a clock and its hands to display the current time.game_of_life
, an interactive version of the Game of Life, invented by John Conway.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, 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]
P: Program<Message>,
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]
Message: Debug,
P: Program<Message> + Debug,
impl<Message, P, B> Widget<Message, Renderer<B>> for Canvas<Message, P> where
B: Backend,
P: Program<Message>,
[src]
B: Backend,
P: Program<Message>,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, _renderer: &Renderer<B>, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer<B>,
_clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer<B>,
_clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
_renderer: &mut Renderer<B>,
_defaults: &Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> (Primitive, Interaction)
[src]
&self,
_renderer: &mut Renderer<B>,
_defaults: &Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> (Primitive, Interaction)
fn hash_layout(&self, state: &mut Hasher)
[src]
fn overlay(
&mut self,
_layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
[src]
&mut self,
_layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
Auto Trait Implementations
impl<Message, P> RefUnwindSafe for Canvas<Message, P> where
Message: RefUnwindSafe,
P: RefUnwindSafe,
Message: RefUnwindSafe,
P: RefUnwindSafe,
impl<Message, P> Send for Canvas<Message, P> where
Message: Send,
P: Send,
Message: Send,
P: Send,
impl<Message, P> Sync for Canvas<Message, P> where
Message: Sync,
P: Sync,
Message: Sync,
P: Sync,
impl<Message, P> Unpin for Canvas<Message, P> where
Message: Unpin,
P: Unpin,
Message: Unpin,
P: Unpin,
impl<Message, P> UnwindSafe for Canvas<Message, P> where
Message: UnwindSafe,
P: UnwindSafe,
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]
D: AdaptFrom<S, Swp, Dwp, T>,
Dwp: WhitePoint,
Swp: WhitePoint,
T: Component + Float,
fn adapt_into_using<M>(self, method: M) -> D where
M: TransformMatrix<Swp, Dwp, T>,
[src]
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into(self) -> D
[src]
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, U> ConvertInto<U> for T where
U: ConvertFrom<T>,
[src]
U: ConvertFrom<T>,
fn convert_into(self) -> U
[src]
fn convert_unclamped_into(self) -> U
[src]
fn try_convert_into(self) -> Result<U, OutOfBounds<U>>
[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>,