Enum usvg_tree::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.

If a current node doesn’t support transformation - a default transform will be returned.

This method is cheap since absolute transforms are already resolved.

source

pub fn bounding_box(&self) -> Option<Rect>

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

This method is cheap since bounding boxes are already calculated.

source

pub fn abs_bounding_box(&self) -> Option<Rect>

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

This method is cheap since bounding boxes are already calculated.

source

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

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

This method is cheap since bounding boxes are already calculated.

source

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

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

This method is cheap since bounding boxes are already calculated.

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_tree::Group) {
    for node in &parent.children {
        // do stuff...

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

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

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

Calls a closure for each subroot this Node has.

A mutable version of subroots().

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 !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.