diff --git a/Cargo.toml b/Cargo.toml index d4df4c07..f8d42572 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ parley = { git = "https://github.com/nicoburns/parley", rev = "a80765f070ab41132 dioxus = { git = "https://github.com/dioxuslabs/dioxus", rev = "a3aa6ae771a2d0a4d8cb6055c41efc0193b817ef"} dioxus-ssr = { git = "https://github.com/dioxuslabs/dioxus", rev = "a3aa6ae771a2d0a4d8cb6055c41efc0193b817ef" } tokio = { version = "1.25.0", features = ["full"] } +tracing = "0.1.40" vello = { version = "0.1", features = ["wgpu"] } peniko = { version = "0.1" } # fello = { git = "https://github.com/linebender/vello" } @@ -50,6 +51,7 @@ dioxus = { workspace = true } euclid = { version = "0.22", features = ["serde"] } reqwest = "0.11.24" tokio = { version = "1.36.0", features = ["full"] } +tracing-subscriber = "0.3" ureq = "2.9" # [patch.crates-io] diff --git a/examples/text.rs b/examples/text.rs index 8a085d2a..bb3b38c5 100644 --- a/examples/text.rs +++ b/examples/text.rs @@ -1,6 +1,8 @@ use dioxus::prelude::*; fn main() { + tracing_subscriber::fmt::init(); + dioxus_blitz::launch(app); } diff --git a/packages/blitz/Cargo.toml b/packages/blitz/Cargo.toml index 2235901b..c1fb7f60 100644 --- a/packages/blitz/Cargo.toml +++ b/packages/blitz/Cargo.toml @@ -3,6 +3,10 @@ name = "blitz" version = "0.1.0" edition = "2021" +[features] +default = ["tracing"] +tracing = ["dep:tracing"] + [dependencies] slab = "0.4.9" style = { workspace = true, features = ["servo"] } @@ -11,6 +15,7 @@ selectors = { workspace = true } taffy = { workspace = true } parley = { workspace = true } tokio = { workspace = true, features = ["full"] } +tracing = { workspace = true, optional = true } vello = { workspace = true } wgpu = { workspace = true } diff --git a/packages/blitz/src/render.rs b/packages/blitz/src/render.rs index 705201dd..99f45b24 100644 --- a/packages/blitz/src/render.rs +++ b/packages/blitz/src/render.rs @@ -285,8 +285,11 @@ where } } - dbg!(&node.final_layout); - dbg!(&node.style); + #[cfg(feature = "tracing")] + { + tracing::info!("Layout: {:?}", &node.final_layout); + tracing::info!("Style: {:?}", &node.style); + } println!("Node {} {}", node.id, node.node_debug_str()); if node.is_inline_root { @@ -655,8 +658,7 @@ where .inline_layout .as_ref() .unwrap_or_else(|| { - dbg!(&element); - panic!("Tried to render node marked as inline root that does not have an inline layout"); + panic!("Tried to render node marked as inline root that does not have an inline layout: {:?}", element); }); // Apply padding/border offset to inline root @@ -1135,9 +1137,11 @@ impl ElementCx<'_> { + multiplier * (color.a as f32 - last_stop.color.a as f32)) as u8, ); - gradient.stops.push( - dbg! {peniko::ColorStop { color: mid_color, offset: mid_offset }}, - ); + tracing::info!("Gradient stop {:?}", mid_color); + gradient.stops.push(peniko::ColorStop { + color: mid_color, + offset: mid_offset, + }); gradient.stops.push(peniko::ColorStop { color, offset }); } } diff --git a/packages/dioxus-blitz/Cargo.toml b/packages/dioxus-blitz/Cargo.toml index 90ee37c8..badf1515 100644 --- a/packages/dioxus-blitz/Cargo.toml +++ b/packages/dioxus-blitz/Cargo.toml @@ -7,7 +7,8 @@ edition = "2021" accessibility = ["dep:accesskit", "dep:accesskit_winit"] hot-reload = ["dep:dioxus-cli-config", "dep:dioxus-hot-reload"] menu = ["dep:muda"] -default = ["accessibility", "menu"] +tracing = ["dep:tracing"] +default = ["accessibility", "hot-reload", "menu", "tracing"] [dependencies] accesskit = { version = "0.15.0", optional = true } @@ -22,6 +23,7 @@ futures-util = "0.3.30" vello = { workspace = true } wgpu = { workspace = true } style = { workspace = true } +tracing = { workspace = true, optional = true } blitz = { path = "../blitz" } blitz-dom = { path = "../dom" } url = { version = "2.5.0", features = ["serde"] } diff --git a/packages/dioxus-blitz/src/documents/dioxus_document.rs b/packages/dioxus-blitz/src/documents/dioxus_document.rs index feb2f0f3..896f8d89 100644 --- a/packages/dioxus-blitz/src/documents/dioxus_document.rs +++ b/packages/dioxus-blitz/src/documents/dioxus_document.rs @@ -97,11 +97,13 @@ impl DocumentLike for DioxusDocument { // todo: we might need to walk upwards to find the first element with a data-dioxus-id attribute for node in chain.iter() { let Some(element) = self.inner.tree()[*node].element_data() else { - println!( + #[cfg(feature = "tracing")] + tracing::info!( "No element data found for node {}: {:?}", node, self.inner.tree()[*node] ); + continue; }; @@ -196,11 +198,12 @@ impl DioxusState { pub fn create(doc: &mut Document) -> Self { let root = doc.root_node(); let root_id = root.id; - dbg!(Self { + + Self { templates: FxHashMap::default(), stack: vec![root_id], node_id_mapping: vec![Some(root_id)], - }) + } } /// Convert an ElementId to a NodeId @@ -254,20 +257,28 @@ impl MutationWriter<'_> { impl WriteMutations for MutationWriter<'_> { fn register_template(&mut self, template: Template) { - println!("register_template name:{}", template.name); let template_root_ids: Vec = template .roots .iter() .map(|root| create_template_node(self.doc, root)) .collect(); - dbg!(&template_root_ids); + + #[cfg(feature = "tracing")] + tracing::info!( + "Registered template: {:?} with root IDs {:?}", + &template.name, + &template_root_ids + ); + self.state .templates .insert(template.name.to_string(), template_root_ids); } fn append_children(&mut self, id: ElementId, m: usize) { - println!("append_children id:{} m:{}", id.0, m); + #[cfg(feature = "tracing")] + tracing::info!("append_children id:{} m:{}", id.0, m); + let children = self.state.stack.split_off(self.state.stack.len() - m); let parent = self.state.element_to_node_id(id); for child in children { @@ -277,20 +288,26 @@ impl WriteMutations for MutationWriter<'_> { } fn assign_node_id(&mut self, path: &'static [u8], id: ElementId) { - println!("assign_node_id path:{:?} id:{}", path, id.0); + #[cfg(feature = "tracing")] + tracing::info!("assign_node_id path:{:?} id:{}", path, id.0); + let node_id = self.load_child(path); self.set_id_mapping(node_id, id); } fn create_placeholder(&mut self, id: ElementId) { - println!("create_placeholder id:{}", id.0); + #[cfg(feature = "tracing")] + tracing::info!("create_placeholder id:{}", id.0); + let node_id = self.doc.create_node(NodeData::Comment); self.set_id_mapping(node_id, id); self.state.stack.push(node_id); } fn create_text_node(&mut self, value: &str, id: ElementId) { - println!("create_text_node id:{} text:{}", id.0, value); + #[cfg(feature = "tracing")] + tracing::info!("create_text_node id:{} text:{}", id.0, value); + let node_id = self.doc.create_text_node(value); self.set_id_mapping(node_id, id); self.state.stack.push(node_id); @@ -302,10 +319,15 @@ impl WriteMutations for MutationWriter<'_> { } else { value }; - println!( + + #[cfg(feature = "tracing")] + tracing::info!( "hydrate_text_node id:{} path: {:?} text:{}", - id.0, path, value_trunc + id.0, + path, + value_trunc ); + let node_id = self.load_child(path); self.set_id_mapping(node_id, id); let node = self.doc.get_node_mut(node_id).unwrap(); @@ -329,7 +351,9 @@ impl WriteMutations for MutationWriter<'_> { } fn load_template(&mut self, name: &'static str, index: usize, id: ElementId) { - println!("load_template name:{} index: {} id:{}", name, index, id.0); + #[cfg(feature = "tracing")] + tracing::info!("load_template name:{} index: {} id:{}", name, index, id.0); + let template_node_id = self.state.templates[name][index]; let clone_id = self.doc.deep_clone_node(template_node_id); self.set_id_mapping(clone_id, id); @@ -337,7 +361,9 @@ impl WriteMutations for MutationWriter<'_> { } fn replace_node_with(&mut self, id: ElementId, m: usize) { - println!("replace_node_with id:{} m:{}", id.0, m); + #[cfg(feature = "tracing")] + tracing::info!("replace_node_with id:{} m:{}", id.0, m); + let new_nodes = self.state.stack.split_off(self.state.stack.len() - m); let anchor_node_id = self.state.element_to_node_id(id); self.doc.insert_before(anchor_node_id, &new_nodes); @@ -345,7 +371,9 @@ impl WriteMutations for MutationWriter<'_> { } fn replace_placeholder_with_nodes(&mut self, path: &'static [u8], m: usize) { - println!("replace_placeholder_with_nodes path:{:?} m:{}", path, m); + #[cfg(feature = "tracing")] + tracing::info!("replace_placeholder_with_nodes path:{:?} m:{}", path, m); + let new_nodes = self.state.stack.split_off(self.state.stack.len() - m); let anchor_node_id = self.load_child(path); self.doc.insert_before(anchor_node_id, &new_nodes); @@ -353,7 +381,9 @@ impl WriteMutations for MutationWriter<'_> { } fn insert_nodes_after(&mut self, id: ElementId, m: usize) { - println!("insert_nodes_after id:{} m:{}", id.0, m); + #[cfg(feature = "tracing")] + tracing::info!("insert_nodes_after id:{} m:{}", id.0, m); + let new_nodes = self.state.stack.split_off(self.state.stack.len() - m); let anchor_node_id = self.state.element_to_node_id(id); let next_sibling_id = self @@ -372,7 +402,9 @@ impl WriteMutations for MutationWriter<'_> { } fn insert_nodes_before(&mut self, id: ElementId, m: usize) { - println!("insert_nodes_before id:{} m:{}", id.0, m); + #[cfg(feature = "tracing")] + tracing::info!("insert_nodes_before id:{} m:{}", id.0, m); + let new_nodes = self.state.stack.split_off(self.state.stack.len() - m); let anchor_node_id = self.state.element_to_node_id(id); self.doc.insert_before(anchor_node_id, &new_nodes); @@ -479,13 +511,17 @@ impl WriteMutations for MutationWriter<'_> { } fn remove_node(&mut self, id: ElementId) { - println!("remove_node id:{}", id.0); + #[cfg(feature = "tracing")] + tracing::info!("remove_node id:{}", id.0); + let node_id = self.state.element_to_node_id(id); self.doc.remove_node(node_id); } fn push_root(&mut self, id: ElementId) { - println!("push_root id:{}", id.0,); + #[cfg(feature = "tracing")] + tracing::info!("push_root id:{}", id.0,); + let node_id = self.state.element_to_node_id(id); self.state.stack.push(node_id); } diff --git a/packages/dioxus-blitz/src/lib.rs b/packages/dioxus-blitz/src/lib.rs index c137b56d..a9404719 100644 --- a/packages/dioxus-blitz/src/lib.rs +++ b/packages/dioxus-blitz/src/lib.rs @@ -172,6 +172,9 @@ fn launch_with_window(window: View<'static, Doc>) { initial = false; } + #[cfg(feature = "tracing")] + tracing::trace!("Received event: {:?}", event); + match event { // Exit the app when close is request // Not always necessary @@ -231,9 +234,8 @@ fn launch_with_window(window: View<'static, Doc>) { } } dioxus_hot_reload::HotReloadMsg::Shutdown => event_loop.exit(), - dioxus_hot_reload::HotReloadMsg::UpdateAsset(asset) => { + dioxus_hot_reload::HotReloadMsg::UpdateAsset(_asset) => { // TODO dioxus-desktop seems to handle this by forcing a reload of all stylesheets. - dbg!("Update asset {:?}", asset); } }, }, diff --git a/packages/dioxus-blitz/src/window.rs b/packages/dioxus-blitz/src/window.rs index 29add76a..c5fbd97d 100644 --- a/packages/dioxus-blitz/src/window.rs +++ b/packages/dioxus-blitz/src/window.rs @@ -117,8 +117,6 @@ impl<'a, Doc: DocumentLike> View<'a, Doc> { // todo: if there's an active text input, we want to direct input towards it and translate system emi text WindowEvent::KeyboardInput { event, .. } => { - dbg!(&event); - match event.physical_key { PhysicalKey::Code(key_code) => { match key_code { diff --git a/packages/dom/Cargo.toml b/packages/dom/Cargo.toml index 6cdad1b1..95703aad 100644 --- a/packages/dom/Cargo.toml +++ b/packages/dom/Cargo.toml @@ -3,6 +3,10 @@ name = "blitz-dom" version = "0.0.0" edition = "2021" +[features] +default = ["tracing"] +tracing = ["dep:tracing"] + [dependencies] style = { workspace = true, features = ["servo"] } selectors = { workspace = true } @@ -11,6 +15,7 @@ style_traits = { workspace = true } taffy = { workspace = true } parley = { workspace = true } peniko = { workspace = true } +tracing = { workspace = true, optional = true } slab = "0.4.9" app_units = "0.7.5" euclid = { version = "0.22", features = ["serde"] }