pub struct Canvas<Message, Theme, P>where
P: Program<Message, Theme>,{ /* private fields */ }
Available on crate feature
canvas
only.Expand description
A widget capable of drawing 2D graphics.
Drawing a simple circle
If you want to get a quick overview, here’s how we can draw a simple circle:
use iced::widget::canvas::{self, Canvas, Cursor, Fill, Frame, Geometry, Path, Program};
use iced::{Color, Rectangle, Theme};
// 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 {
type State = ();
fn draw(&self, _state: &(), _theme: &Theme, 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
Trait Implementations
sourceimpl<Message, Theme, P> Debug for Canvas<Message, Theme, P>where
Message: Debug,
Theme: Debug,
P: Debug + Program<Message, Theme>,
impl<Message, Theme, P> Debug for Canvas<Message, Theme, P>where
Message: Debug,
Theme: Debug,
P: Debug + Program<Message, Theme>,
sourceimpl<Message, P, B, T> Widget<Message, Renderer<B, T>> for Canvas<Message, T, P>where
P: Program<Message, T>,
B: Backend,
impl<Message, P, B, T> Widget<Message, Renderer<B, T>> for Canvas<Message, T, P>where
P: Program<Message, T>,
B: Backend,
sourcefn on_event(
&mut self,
tree: &mut Tree,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
_renderer: &Renderer<B, T>,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>
) -> Status
fn on_event(
&mut self,
tree: &mut Tree,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
_renderer: &Renderer<B, T>,
_clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>
) -> Status
sourcefn mouse_interaction(
&self,
tree: &Tree,
layout: Layout<'_>,
cursor_position: Point,
_viewport: &Rectangle<f32>,
_renderer: &Renderer<B, T>
) -> Interaction
fn mouse_interaction(
&self,
tree: &Tree,
layout: Layout<'_>,
cursor_position: Point,
_viewport: &Rectangle<f32>,
_renderer: &Renderer<B, T>
) -> Interaction
sourcefn draw(
&self,
tree: &Tree,
renderer: &mut Renderer<B, T>,
theme: &T,
_style: &Style,
layout: Layout<'_>,
cursor_position: Point,
_viewport: &Rectangle<f32>
)
fn draw(
&self,
tree: &Tree,
renderer: &mut Renderer<B, T>,
theme: &T,
_style: &Style,
layout: Layout<'_>,
cursor_position: Point,
_viewport: &Rectangle<f32>
)
Draws the
Widget
using the associated Renderer
.sourcefn children(&self) -> Vec<Tree, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
fn children(&self) -> Vec<Tree, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Auto Trait Implementations
impl<Message, Theme, P> RefUnwindSafe for Canvas<Message, Theme, P>where
Message: RefUnwindSafe,
P: RefUnwindSafe,
Theme: RefUnwindSafe,
impl<Message, Theme, P> Send for Canvas<Message, Theme, P>where
Message: Send,
P: Send,
Theme: Send,
impl<Message, Theme, P> Sync for Canvas<Message, Theme, P>where
Message: Sync,
P: Sync,
Theme: Sync,
impl<Message, Theme, P> Unpin for Canvas<Message, Theme, P>where
Message: Unpin,
P: Unpin,
Theme: Unpin,
impl<Message, Theme, P> UnwindSafe for Canvas<Message, Theme, P>where
Message: UnwindSafe,
P: UnwindSafe,
Theme: UnwindSafe,
Blanket Implementations
sourceimpl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: FloatComponent,
Swp: WhitePoint,
Dwp: WhitePoint,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: FloatComponent,
Swp: WhitePoint,
Dwp: WhitePoint,
D: AdaptFrom<S, Swp, Dwp, T>,
sourcefn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<Swp, Dwp, T>,
Convert the source color to the destination color using the specified
method Read more
sourcefn adapt_into(self) -> D
fn adapt_into(self) -> D
Convert the source color to the destination color using the bradford
method by default Read more
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
sourcefn into_color(self) -> U
fn into_color(self) -> U
Convert into T with values clamped to the color defined bounds Read more
sourceimpl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
sourcefn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Convert into T. The resulting color might be invalid in its color space Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
sourcefn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
Convert into T, returning ok if the color is inside of its defined
range, otherwise an
OutOfBounds
error is returned which contains
the unclamped color. Read more