Enum usvg::Node

source ·
pub enum Node {
    Group(Box<Group>),
    Path(Box<Path>),
    Image(Box<Image>),
    Text(Box<Text>),
}
Expand description

Node’s kind.

Variants§

§

Group(Box<Group>)

§

Path(Box<Path>)

§

Image(Box<Image>)

§

Text(Box<Text>)

Implementations§

source§

impl Node

source

pub fn id(&self) -> &str

Returns node’s ID.

source

pub fn abs_transform(&self) -> Transform

Returns node’s absolute transform.

This method is cheap since absolute transforms are already resolved.

source

pub fn bounding_box(&self) -> Rect

Returns node’s bounding box in object coordinates, if any.

source

pub fn abs_bounding_box(&self) -> Rect

Returns node’s bounding box in canvas coordinates, if any.

source

pub fn stroke_bounding_box(&self) -> Rect

Returns node’s bounding box, including stroke, in object coordinates, if any.

source

pub fn abs_stroke_bounding_box(&self) -> Rect

Returns node’s bounding box, including stroke, in canvas coordinates, if any.

source

pub fn abs_layer_bounding_box(&self) -> Option<NonZeroRect>

Element’s “layer” bounding box in canvas units, if any.

For most nodes this is just abs_bounding_box, but for groups this is abs_layer_bounding_box.

See Group::layer_bounding_box for details.

source

pub fn subroots<F: FnMut(&Group)>(&self, f: F)

Calls a closure for each subroot this Node has.

The Tree::root field contain only render-able SVG elements. But some elements, specifically clip paths, masks, patterns and feImage can store their own SVG subtrees. And while one can access them manually, it’s pretty verbose. This methods allows looping over all SVG elements present in the Tree.

§Example
fn all_nodes(parent: &usvg::Group) {
    for node in parent.children() {
        // do stuff...

        if let usvg::Node::Group(ref g) = node {
            all_nodes(g);
        }

        // handle subroots as well
        node.subroots(|subroot| all_nodes(subroot));
    }
}

Trait Implementations§

source§

impl Clone for Node

source§

fn clone(&self) -> Node

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 Node

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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> ToOwned for T
where 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 T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.