Update custom renderer guide
This commit is contained in:
1 parent
ae1300b015
commit
4b81cdbf1b
8 files changed
+870
-212
No files matched your search
@@ -20,6 +20,18 @@ pub struct ElementNode<V: FromAnyValue = ()> {
|
||||
pub listeners: FxHashSet<String>,
|
||||
}
|
||||
|
||||
impl ElementNode {
|
||||
/// Create a new element node
|
||||
pub fn new(tag: impl Into<String>, namespace: impl Into<Option<String>>) -> Self {
|
||||
Self {
|
||||
tag: tag.into(),
|
||||
namespace: namespace.into(),
|
||||
attributes: Default::default(),
|
||||
listeners: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A text node in the RealDom
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct TextNode {
|
||||
@@ -50,6 +62,24 @@ pub enum NodeType<V: FromAnyValue = ()> {
|
||||
Placeholder,
|
||||
}
|
||||
|
||||
impl<S: Into<String>> From<S> for NodeType {
|
||||
fn from(text: S) -> Self {
|
||||
Self::Text(TextNode::new(text.into()))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TextNode> for NodeType {
|
||||
fn from(text: TextNode) -> Self {
|
||||
Self::Text(text)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: FromAnyValue> From<ElementNode<V>> for NodeType<V> {
|
||||
fn from(element: ElementNode<V>) -> Self {
|
||||
Self::Element(element)
|
||||
}
|
||||
}
|
||||
|
||||
/// A discription of an attribute on a DOM node, such as `id` or `href`.
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
||||
pub struct OwnedAttributeDiscription {
|
||||
@@ -158,14 +188,14 @@ impl<V: FromAnyValue> Debug for OwnedAttributeValue<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: FromAnyValue + Display> Display for OwnedAttributeValue<V> {
|
||||
impl<V: FromAnyValue> Display for OwnedAttributeValue<V> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Text(arg0) => f.write_str(arg0),
|
||||
Self::Float(arg0) => f.write_str(&arg0.to_string()),
|
||||
Self::Int(arg0) => f.write_str(&arg0.to_string()),
|
||||
Self::Bool(arg0) => f.write_str(&arg0.to_string()),
|
||||
Self::Custom(arg0) => f.write_str(&arg0.to_string()),
|
||||
Self::Custom(_) => f.write_str("custom"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,13 +105,13 @@ impl DirtyNodeStates {
|
||||
|
||||
/// A state that is automatically inserted in a node with dependencies.
|
||||
pub trait State<V: FromAnyValue + Send + Sync = ()>: Any + Send + Sync {
|
||||
/// This is a tuple of (T: State, ..) of states read from the parent required to run this pass
|
||||
/// This is a tuple of (T: State, ..) of states read from the parent required to update this state
|
||||
type ParentDependencies: Dependancy;
|
||||
/// This is a tuple of (T: State, ..) of states read from the children required to run this pass
|
||||
/// This is a tuple of (T: State, ..) of states read from the children required to update this state
|
||||
type ChildDependencies: Dependancy;
|
||||
/// This is a tuple of (T: State, ..) of states read from the node required to run this pass
|
||||
/// This is a tuple of (T: State, ..) of states read from the node required to update this state
|
||||
type NodeDependencies: Dependancy;
|
||||
/// This is a mask of what aspects of the node are required to run this pass
|
||||
/// This is a mask of what aspects of the node are required to update this state
|
||||
const NODE_MASK: NodeMaskBuilder<'static>;
|
||||
|
||||
/// Update this state in a node, returns if the state was updated
|
||||
|
||||
@@ -113,7 +113,8 @@ pub struct RealDom<V: FromAnyValue + Send + Sync = ()> {
|
||||
|
||||
impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
||||
/// Create a new RealDom with the given states that will be inserted and updated when needed
|
||||
pub fn new(mut tracked_states: Box<[TypeErasedState<V>]>) -> RealDom<V> {
|
||||
pub fn new(tracked_states: impl Into<Box<[TypeErasedState<V>]>>) -> RealDom<V> {
|
||||
let mut tracked_states = tracked_states.into();
|
||||
// resolve dependants for each pass
|
||||
for i in 1..tracked_states.len() {
|
||||
let (before, after) = tracked_states.split_at_mut(i);
|
||||
@@ -177,8 +178,8 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
||||
}
|
||||
|
||||
/// Create a new node of the given type in the dom and return a mutable reference to it.
|
||||
pub fn create_node(&mut self, node: NodeType<V>) -> NodeMut<'_, V> {
|
||||
let id = self.world.add_entity(node);
|
||||
pub fn create_node(&mut self, node: impl Into<NodeType<V>>) -> NodeMut<'_, V> {
|
||||
let id = self.world.add_entity(node.into());
|
||||
self.tree_mut().create_node(id);
|
||||
self.dirty_nodes
|
||||
.passes_updated
|
||||
|
||||
Reference in new issue
Block a user