Commit 418e6749 authored by Federico Mena Quintero's avatar Federico Mena Quintero

Merge branch 'node' into 'master'

node: move Display trait impl on NodeData

See merge request !220
parents ca9d028e 51af0b1f
Pipeline #87168 failed with stages
in 36 minutes and 32 seconds
......@@ -69,6 +69,22 @@ impl NodeData {
(&self.node_impl).downcast_ref::<T>()
}
pub fn get_type(&self) -> NodeType {
self.node_type
}
pub fn element_name(&self) -> &str {
self.element_name.as_ref()
}
pub fn get_id(&self) -> Option<&str> {
self.id.as_ref().map(String::as_str)
}
pub fn get_class(&self) -> Option<&str> {
self.class.as_ref().map(String::as_str)
}
pub fn set_atts(&self, node: &RsvgNode, pbag: &PropertyBag<'_>, locale: &Locale) {
if self.node_impl.overflow_hidden() {
let mut specified_values = self.specified_values.borrow_mut();
......@@ -232,6 +248,17 @@ impl NodeData {
}
}
impl fmt::Display for NodeData {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{:?} id={}",
self.get_type(),
self.get_id().unwrap_or("None")
)
}
}
/// Can obtain computed values from a node
///
/// In our tree of SVG elements (Node in our parlance), each node stores a `ComputedValues` that
......@@ -426,19 +453,19 @@ pub enum NodeType {
impl RsvgNode {
pub fn get_type(&self) -> NodeType {
self.borrow().node_type
self.borrow().get_type()
}
pub fn element_name(&self) -> &str {
self.borrow().element_name.as_ref()
self.borrow().element_name()
}
pub fn get_id(&self) -> Option<&str> {
self.borrow().id.as_ref().map(String::as_str)
self.borrow().get_id()
}
pub fn get_class(&self) -> Option<&str> {
self.borrow().class.as_ref().map(String::as_str)
self.borrow().get_class()
}
pub fn get_transform(&self) -> Matrix {
......@@ -527,14 +554,3 @@ impl RsvgNode {
self.borrow().specified_values.borrow().is_overflow()
}
}
impl fmt::Display for RsvgNode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{:?} id={}",
self.get_type(),
self.get_id().unwrap_or("None")
)
}
}
use std::cell::RefCell;
use std::fmt;
use std::ops::Deref;
use std::rc::{Rc, Weak};
......@@ -48,6 +49,12 @@ impl<T> PartialEq for NodeRef<T> {
}
}
impl<T: fmt::Display> fmt::Display for NodeRef<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.0.data, f)
}
}
pub struct Node<T> {
parent: Option<NodeWeakRef<T>>,
first_child: RefCell<Option<NodeRef<T>>>,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment