some basic tui examples working

This commit is contained in:
Evan Almloff 2022-12-05 13:30:13 -06:00
parent 11b37ee141
commit 1587056a4b
5 changed files with 21 additions and 14 deletions

View file

@ -215,8 +215,10 @@ fn resolve_downward_pass<T, P: DownwardPass<T> + ?Sized>(
while let Some(id) = dirty.pop_front() { while let Some(id) = dirty.pop_front() {
let (node, parent) = tree.node_parent_mut(id).unwrap(); let (node, parent) = tree.node_parent_mut(id).unwrap();
let result = pass.pass(node, parent, ctx); let result = pass.pass(node, parent, ctx);
if result.mark_dirty || result.progress { if result.mark_dirty {
nodes_updated.insert(id); nodes_updated.insert(id);
}
if result.mark_dirty || result.progress {
for id in tree.children_ids(id).unwrap() { for id in tree.children_ids(id).unwrap() {
if result.mark_dirty { if result.mark_dirty {
for dependant in pass.dependants() { for dependant in pass.dependants() {

View file

@ -164,7 +164,10 @@ impl<S: State> RealDom<S> {
} }
/// Updates the dom with some mutations and return a set of nodes that were updated. Pass the dirty nodes to update_state. /// Updates the dom with some mutations and return a set of nodes that were updated. Pass the dirty nodes to update_state.
pub fn apply_mutations(&mut self, mutations: Mutations) -> DirtyNodeStates { pub fn apply_mutations(
&mut self,
mutations: Mutations,
) -> (DirtyNodeStates, FxHashMap<RealNodeId, NodeMask>) {
let mut nodes_updated: FxHashMap<RealNodeId, NodeMask> = FxHashMap::default(); let mut nodes_updated: FxHashMap<RealNodeId, NodeMask> = FxHashMap::default();
for template in mutations.templates { for template in mutations.templates {
let mut template_root_ids = Vec::new(); let mut template_root_ids = Vec::new();
@ -348,7 +351,7 @@ impl<S: State> RealDom<S> {
} }
let dirty_nodes = DirtyNodeStates::default(); let dirty_nodes = DirtyNodeStates::default();
for (n, mask) in nodes_updated { for (&n, mask) in &nodes_updated {
// remove any nodes that were created and then removed in the same mutations from the dirty nodes list // remove any nodes that were created and then removed in the same mutations from the dirty nodes list
if self.tree.contains(n) { if self.tree.contains(n) {
for (m, p) in S::MASKS.iter().zip(S::PASSES.iter()) { for (m, p) in S::MASKS.iter().zip(S::PASSES.iter()) {
@ -359,7 +362,7 @@ impl<S: State> RealDom<S> {
} }
} }
dirty_nodes (dirty_nodes, nodes_updated)
} }
/// Update the state of the dom, after appling some mutations. This will keep the nodes in the dom up to date with their VNode counterparts. /// Update the state of the dom, after appling some mutations. This will keep the nodes in the dom up to date with their VNode counterparts.

View file

@ -221,10 +221,8 @@ pub trait State: Default + Clone + 'static {
tree: &mut T, tree: &mut T,
ctx: SendAnyMap, ctx: SendAnyMap,
) -> FxDashSet<RealNodeId> { ) -> FxDashSet<RealNodeId> {
let set = FxDashSet::default();
let passes = Self::PASSES.iter().collect(); let passes = Self::PASSES.iter().collect();
resolve_passes(tree, dirty, passes, ctx); resolve_passes(tree, dirty, passes, ctx)
set
} }
} }

View file

@ -6,7 +6,7 @@ use crossterm::{
}; };
use futures_channel::mpsc::unbounded; use futures_channel::mpsc::unbounded;
use dioxus_core::*; use dioxus_core::*;
use dioxus_native_core::{real_dom::RealDom, NodeId, SendAnyMap, FxDashSet}; use dioxus_native_core::{real_dom::RealDom, NodeId, SendAnyMap, FxDashSet, NodeMask};
use focus::FocusState; use focus::FocusState;
use futures::{ use futures::{
channel::mpsc::{UnboundedReceiver, UnboundedSender}, channel::mpsc::{UnboundedReceiver, UnboundedSender},
@ -90,7 +90,7 @@ pub fn launch_cfg(app: Component<()>, cfg: Config) {
{ {
let mut rdom = rdom.borrow_mut(); let mut rdom = rdom.borrow_mut();
let mutations = dom.rebuild(); let mutations = dom.rebuild();
let to_update = rdom.apply_mutations(mutations); let (to_update,_) = rdom.apply_mutations(mutations);
let mut any_map = SendAnyMap::new(); let mut any_map = SendAnyMap::new();
any_map.insert(taffy.clone()); any_map.insert(taffy.clone());
let _to_rerender = rdom.update_state(to_update, any_map); let _to_rerender = rdom.update_state(to_update, any_map);
@ -142,9 +142,7 @@ fn render_vdom(
-> wait for changes -> wait for changes
-> resolve events -> resolve events
-> lazily update the layout and style based on nodes changed -> lazily update the layout and style based on nodes changed
use simd to compare lines for diffing? use simd to compare lines for diffing?
todo: lazy re-rendering todo: lazy re-rendering
*/ */
@ -244,11 +242,16 @@ fn render_vdom(
let mutations = vdom.render_immediate(); let mutations = vdom.render_immediate();
handler.prune(&mutations, &rdom); handler.prune(&mutations, &rdom);
// updates the dom's nodes // updates the dom's nodes
let to_update = rdom.apply_mutations(mutations); let (to_update, dirty) = rdom.apply_mutations(mutations);
// update the style and layout // update the style and layout
let mut any_map = SendAnyMap::new(); let mut any_map = SendAnyMap::new();
any_map.insert(taffy.clone()); any_map.insert(taffy.clone());
to_rerender = rdom.update_state(to_update, any_map); to_rerender = rdom.update_state(to_update, any_map);
for (id, mask) in dirty {
if mask.overlaps(&NodeMask::new().with_text()) {
to_rerender.insert(id);
}
}
} }
} }

View file

@ -54,7 +54,8 @@ impl NodeDepState for PreventDefault {
dioxus_native_core::node_ref::AttributeMask::Static(&sorted_str_slice!([ dioxus_native_core::node_ref::AttributeMask::Static(&sorted_str_slice!([
"dioxus-prevent-default" "dioxus-prevent-default"
])), ])),
); )
.with_listeners();
fn reduce( fn reduce(
&mut self, &mut self,