pub enum Node {
Group(Box<Group>),
Path(Box<Path>),
Image(Box<Image>),
Text(Box<Text>),
}
Expand description
Node’s kind.
Variants§
Implementations§
source§impl Node
impl Node
sourcepub fn abs_transform(&self) -> Transform
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.
sourcepub fn bounding_box(&self) -> Option<Rect>
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.
sourcepub fn abs_bounding_box(&self) -> Option<Rect>
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.
sourcepub fn stroke_bounding_box(&self) -> Option<NonZeroRect>
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.
sourcepub fn abs_stroke_bounding_box(&self) -> Option<NonZeroRect>
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.
sourcepub fn subroots<F: FnMut(&Group)>(&self, f: F)
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));
}
}
sourcepub fn subroots_mut<F: FnMut(&mut Group)>(&mut self, f: F)
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()
.