mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-27 06:30:20 +00:00
some basic tui examples working
This commit is contained in:
parent
11b37ee141
commit
1587056a4b
5 changed files with 21 additions and 14 deletions
|
@ -215,8 +215,10 @@ fn resolve_downward_pass<T, P: DownwardPass<T> + ?Sized>(
|
|||
while let Some(id) = dirty.pop_front() {
|
||||
let (node, parent) = tree.node_parent_mut(id).unwrap();
|
||||
let result = pass.pass(node, parent, ctx);
|
||||
if result.mark_dirty || result.progress {
|
||||
if result.mark_dirty {
|
||||
nodes_updated.insert(id);
|
||||
}
|
||||
if result.mark_dirty || result.progress {
|
||||
for id in tree.children_ids(id).unwrap() {
|
||||
if result.mark_dirty {
|
||||
for dependant in pass.dependants() {
|
||||
|
|
|
@ -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.
|
||||
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();
|
||||
for template in mutations.templates {
|
||||
let mut template_root_ids = Vec::new();
|
||||
|
@ -348,7 +351,7 @@ impl<S: State> RealDom<S> {
|
|||
}
|
||||
|
||||
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
|
||||
if self.tree.contains(n) {
|
||||
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.
|
||||
|
|
|
@ -221,10 +221,8 @@ pub trait State: Default + Clone + 'static {
|
|||
tree: &mut T,
|
||||
ctx: SendAnyMap,
|
||||
) -> FxDashSet<RealNodeId> {
|
||||
let set = FxDashSet::default();
|
||||
let passes = Self::PASSES.iter().collect();
|
||||
resolve_passes(tree, dirty, passes, ctx);
|
||||
set
|
||||
resolve_passes(tree, dirty, passes, ctx)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use crossterm::{
|
|||
};
|
||||
use futures_channel::mpsc::unbounded;
|
||||
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 futures::{
|
||||
channel::mpsc::{UnboundedReceiver, UnboundedSender},
|
||||
|
@ -90,7 +90,7 @@ pub fn launch_cfg(app: Component<()>, cfg: Config) {
|
|||
{
|
||||
let mut rdom = rdom.borrow_mut();
|
||||
let mutations = dom.rebuild();
|
||||
let to_update = rdom.apply_mutations(mutations);
|
||||
let (to_update,_) = rdom.apply_mutations(mutations);
|
||||
let mut any_map = SendAnyMap::new();
|
||||
any_map.insert(taffy.clone());
|
||||
let _to_rerender = rdom.update_state(to_update, any_map);
|
||||
|
@ -135,16 +135,14 @@ fn render_vdom(
|
|||
let mut to_rerender =FxDashSet::default();
|
||||
to_rerender.insert(NodeId(0));
|
||||
let mut updated = true;
|
||||
|
||||
|
||||
loop {
|
||||
/*
|
||||
-> render the nodes in the right place with tui/crossterm
|
||||
-> wait for changes
|
||||
-> resolve events
|
||||
-> lazily update the layout and style based on nodes changed
|
||||
|
||||
use simd to compare lines for diffing?
|
||||
|
||||
todo: lazy re-rendering
|
||||
*/
|
||||
|
||||
|
@ -244,11 +242,16 @@ fn render_vdom(
|
|||
let mutations = vdom.render_immediate();
|
||||
handler.prune(&mutations, &rdom);
|
||||
// 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
|
||||
let mut any_map = SendAnyMap::new();
|
||||
any_map.insert(taffy.clone());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,8 @@ impl NodeDepState for PreventDefault {
|
|||
dioxus_native_core::node_ref::AttributeMask::Static(&sorted_str_slice!([
|
||||
"dioxus-prevent-default"
|
||||
])),
|
||||
);
|
||||
)
|
||||
.with_listeners();
|
||||
|
||||
fn reduce(
|
||||
&mut self,
|
||||
|
|
Loading…
Reference in a new issue