Struct dessin::Drawing

source ·
pub struct Drawing { /* private fields */ }
Expand description

Drawing is a collection of shapes.


let mut drawing = Drawing::empty().with_canvas_size(vec2(100., 100.));

drawing.add(
        Text::new("Hello World".to_owned())
            .at(vec2(50., 50.))
    )
    .add(
        Line::from(vec2(0., 0.)).to(vec2(100., 100.))
    )
    .add(
        Circle::new()
            .at(vec2(50., 50.)).with_radius(10.)
    )
    .add(
        Image::new(ImageFormat::PNG(include_bytes!("../rustacean-flat-happy.png").to_vec()))
            .at(vec2(50., 50.))
            .with_size(vec2(10., 10.))
    );
     
let other_drawing = Drawing::empty()
    .with_canvas_size(vec2(210., 297.))
    .add(
        EmbeddedDrawing::new(drawing)
            .at(vec2(100., 100.))
            .with_size(vec2(10., 10.))
    );

Implementations§

source§

impl Drawing

source

pub const fn empty() -> Self

Default constructor, creates an empty drawing.

source

pub fn new<T>(shape: T) -> Selfwhere T: Into<Shape>,

Construct a drawing with a shape.

source

pub const fn with_canvas_size(self, canvas_size: Vec2) -> Self

source

pub const fn canvas_size(&self) -> Vec2

source

pub fn add<T>(&mut self, shape: T) -> &mut Selfwhere T: Into<Shape>,

source

pub fn into_embedded(self) -> EmbeddedDrawing

source

pub fn shapes(&self) -> &Vec<Shape>

Get access to this drawing’s shapes.


let mut drawing = Drawing::empty().with_canvas_size(vec2(100., 100.));

drawing.add(
        Text::new("Hello World".to_owned())
            .at(vec2(50., 50.))
    )
    .add(
        Line::from(vec2(0., 0.)).to(vec2(100., 100.))
    );

let shapes = drawing.shapes();
dbg!("{:?}", shapes);

Trait Implementations§

source§

impl Clone for Drawing

source§

fn clone(&self) -> Drawing

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Drawing

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Into<Shape> for Drawing

source§

fn into(self) -> Shape

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ShapeGrouping for Twhere T: Into<Shape>,

source§

impl<T, U> ShapeInteraction<U> for Twhere T: Into<Shape>, U: Into<Shape>,

source§

fn children_of(self, parent: U) -> Drawing

source§

fn parent_of(self, children: U) -> Drawing

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.