pub trait NodeExt {
// Required methods
fn id(&self) -> Ref<'_, str>;
fn abs_transform(&self) -> Transform;
fn append_kind(&self, kind: NodeKind) -> Node;
fn calculate_bbox(&self) -> Option<Rect>;
fn subroots<F: FnMut(Node)>(&self, f: F);
}
Expand description
Additional Node
methods.
Required Methods§
sourcefn id(&self) -> Ref<'_, str>
fn id(&self) -> Ref<'_, str>
Returns node’s ID.
If a current node doesn’t support ID - an empty string will be returned.
sourcefn abs_transform(&self) -> Transform
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 an absolute transform is already stored in
Group::abs_transform
.
sourcefn append_kind(&self, kind: NodeKind) -> Node
fn append_kind(&self, kind: NodeKind) -> Node
Appends kind
as a node child.
sourcefn calculate_bbox(&self) -> Option<Rect>
fn calculate_bbox(&self) -> Option<Rect>
Calculates node’s absolute bounding box.
Returns None
for NodeKind::Text
unless it was flattened already.
sourcefn subroots<F: FnMut(Node)>(&self, f: F)
fn subroots<F: FnMut(Node)>(&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
use usvg_tree::NodeExt;
fn all_nodes(root: &usvg_tree::Node) {
for node in root.descendants() {
// do stuff...
// hand subroots as well
node.subroots(|subroot| all_nodes(&subroot));
}
}