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§
§impl<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>,
§impl<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,
§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
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
§fn 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
§fn 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
.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§
source§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>,
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>,
source§fn 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
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Convert the source color to the destination color using the bradford
method by default
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere U: FromColor<T>,
source§fn into_color(self) -> U
fn into_color(self) -> U
Convert into T with values clamped to the color defined bounds Read more
source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere U: FromColorUnclamped<T>,
source§fn 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
source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere U: TryFromColor<T>,
source§fn 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