mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-14 16:37:14 +00:00
update TUI to new native-core
This commit is contained in:
parent
865c5aa957
commit
c4845d5c8d
9 changed files with 59 additions and 32 deletions
|
@ -240,9 +240,9 @@ let get_child_view = {
|
|||
fn workload_system(type_id: std::any::TypeId, dependants: dioxus_native_core::exports::FxHashSet<std::any::TypeId>, pass_direction: dioxus_native_core::PassDirection) -> dioxus_native_core::exports::shipyard::WorkloadSystem {
|
||||
use dioxus_native_core::exports::shipyard::{IntoWorkloadSystem, Get, AddComponent};
|
||||
use dioxus_native_core::tree::TreeRef;
|
||||
use dioxus_native_core::prelude::{NodeType, NodeView};
|
||||
|
||||
(move |data: #combined_dependencies_quote, run_view: dioxus_native_core::RunPassView #trait_generics| {
|
||||
println!("Running system for {:?}", type_id);
|
||||
let (#(#split_views,)*) = data;
|
||||
let (tree, types, _, _, _) = &run_view;
|
||||
let tree = tree.clone();
|
||||
|
|
|
@ -311,6 +311,16 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
|||
pub fn add_node_watcher(&mut self, watcher: impl NodeWatcher<V> + 'static + Send + Sync) {
|
||||
self.node_watchers.write().unwrap().push(Box::new(watcher));
|
||||
}
|
||||
|
||||
/// Returns a reference to the underlying world. Any changes made to the world will not update the reactive system.
|
||||
pub fn raw_world(&self) -> &World {
|
||||
&self.world
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the underlying world. Any changes made to the world will not update the reactive system.
|
||||
pub fn raw_world_mut(&mut self) -> &mut World {
|
||||
&mut self.world
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ViewEntry<'a, V: Component + Send + Sync> {
|
||||
|
@ -371,7 +381,8 @@ pub trait NodeImmutable<V: FromAnyValue + Send + Sync>: Sized {
|
|||
fn get<'a, T: Component + Sync + Send>(&'a self) -> Option<ViewEntry<'a, T>> {
|
||||
// self.real_dom().tree.get(self.id())
|
||||
let view: View<'a, T> = self.real_dom().borrow_raw().ok()?;
|
||||
Some(ViewEntry::new(view, self.id()))
|
||||
view.contains(self.id())
|
||||
.then(|| ViewEntry::new(view, self.id()))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -17,6 +17,7 @@ dioxus = { path = "../dioxus", version = "^0.3.0", optional = true }
|
|||
dioxus-core = { path = "../core", version = "^0.3.0", features = ["serialize"], optional = true }
|
||||
dioxus-html = { path = "../html", version = "^0.3.0" }
|
||||
dioxus-native-core = { path = "../native-core", version = "^0.2.0" }
|
||||
dioxus-native-core-macro = { path = "../native-core-macro", version = "^0.3.0" }
|
||||
dioxus-hot-reload = { path = "../hot-reload", optional = true }
|
||||
|
||||
tui = "0.17.0"
|
||||
|
@ -29,6 +30,7 @@ smallvec = "1.6"
|
|||
rustc-hash = "1.1.0"
|
||||
anymap = "1.0.0-beta.2"
|
||||
futures-channel = "0.3.25"
|
||||
shipyard = "0.6.2"
|
||||
|
||||
[dev-dependencies]
|
||||
dioxus = { path = "../dioxus" }
|
||||
|
|
|
@ -6,11 +6,15 @@ use dioxus_native_core::{
|
|||
utils::{ElementProduced, PersistantElementIter},
|
||||
Dependancy, NodeId, RealDom, SendAnyMap, State,
|
||||
};
|
||||
use dioxus_native_core_macro::partial_derive_state;
|
||||
use shipyard::Component;
|
||||
use shipyard::{Get, ViewMut};
|
||||
|
||||
use std::{cmp::Ordering, num::NonZeroU16};
|
||||
|
||||
use dioxus_native_core::node_ref::NodeView;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Focused(pub bool);
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
|
@ -58,11 +62,12 @@ impl Default for FocusLevel {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Default)]
|
||||
#[derive(Clone, PartialEq, Debug, Default, Component)]
|
||||
pub(crate) struct Focus {
|
||||
pub level: FocusLevel,
|
||||
}
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for Focus {
|
||||
const NODE_MASK: NodeMaskBuilder<'static> = NodeMaskBuilder::new()
|
||||
.with_attrs(AttributeMaskBuilder::Some(FOCUS_ATTRIBUTES))
|
||||
|
@ -77,7 +82,7 @@ impl State for Focus {
|
|||
node_view: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
let new = Focus {
|
||||
|
@ -126,7 +131,7 @@ impl State for Focus {
|
|||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
|
@ -159,7 +164,7 @@ impl FocusState {
|
|||
/// Returns true if the focus has changed.
|
||||
pub fn progress(&mut self, rdom: &mut RealDom, forward: bool) -> bool {
|
||||
if let Some(last) = self.last_focused_id {
|
||||
if rdom.get(last).unwrap().get::<PreventDefault>().copied()
|
||||
if rdom.get(last).unwrap().get::<PreventDefault>().map(|p| *p)
|
||||
== Some(PreventDefault::KeyDown)
|
||||
{
|
||||
return false;
|
||||
|
@ -257,7 +262,8 @@ impl FocusState {
|
|||
}
|
||||
node.insert(Focused(true));
|
||||
if let Some(old) = self.last_focused_id.replace(id) {
|
||||
let focused = rdom.get_state_mut_raw::<Focused>(old).unwrap();
|
||||
let mut focused_borrow: ViewMut<Focused> = rdom.raw_world().borrow().unwrap();
|
||||
let focused = (&mut focused_borrow).get(old).unwrap();
|
||||
focused.0 = false;
|
||||
}
|
||||
// reset the position to the currently focused element
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use dioxus_native_core::exports::shipyard::Component;
|
||||
use dioxus_native_core::layout_attributes::{
|
||||
apply_layout_attributes_cfg, BorderWidths, LayoutConfigeration,
|
||||
};
|
||||
use dioxus_native_core::node::OwnedAttributeView;
|
||||
use dioxus_native_core::node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView};
|
||||
use dioxus_native_core::{Dependancy, SendAnyMap, State};
|
||||
use dioxus_native_core_macro::partial_derive_state;
|
||||
use taffy::prelude::*;
|
||||
|
||||
use crate::{screen_to_layout_space, unit_to_layout_space};
|
||||
|
@ -36,12 +38,13 @@ impl<T> Default for PossiblyUninitalized<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Default, Debug)]
|
||||
#[derive(Clone, PartialEq, Default, Debug, Component)]
|
||||
pub(crate) struct TaffyLayout {
|
||||
pub style: Style,
|
||||
pub node: PossiblyUninitalized<Node>,
|
||||
}
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for TaffyLayout {
|
||||
type ChildDependencies = (Self,);
|
||||
type ParentDependencies = ();
|
||||
|
@ -56,7 +59,7 @@ impl State for TaffyLayout {
|
|||
node_view: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
ctx: &SendAnyMap,
|
||||
) -> bool {
|
||||
let mut changed = false;
|
||||
|
@ -110,11 +113,9 @@ impl State for TaffyLayout {
|
|||
|
||||
// Set all direct nodes as our children
|
||||
let mut child_layout = vec![];
|
||||
if let Some(children) = children {
|
||||
for (l,) in children {
|
||||
child_layout.push(l.node.unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
fn scale_dimention(d: Dimension) -> Dimension {
|
||||
match d {
|
||||
|
@ -194,7 +195,7 @@ impl State for TaffyLayout {
|
|||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
|
|
|
@ -7,7 +7,7 @@ use crossterm::{
|
|||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
};
|
||||
use dioxus_html::EventData;
|
||||
use dioxus_native_core::{node_ref::NodeMaskBuilder, real_dom::NodeImmutable, State};
|
||||
use dioxus_native_core::{node_ref::NodeMaskBuilder, prelude::AnyState, real_dom::NodeImmutable};
|
||||
use dioxus_native_core::{real_dom::RealDom, FxDashSet, NodeId, SendAnyMap};
|
||||
use focus::FocusState;
|
||||
use futures::{channel::mpsc::UnboundedSender, pin_mut, Future, StreamExt};
|
||||
|
@ -123,7 +123,7 @@ pub fn render<R: Renderer>(
|
|||
let mut any_map = SendAnyMap::new();
|
||||
any_map.insert(taffy.clone());
|
||||
let mut rdom = rdom.write().unwrap();
|
||||
let _ = rdom.update_state(any_map, false);
|
||||
let _ = rdom.update_state(any_map);
|
||||
}
|
||||
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
|
@ -148,7 +148,7 @@ pub fn render<R: Renderer>(
|
|||
}
|
||||
|
||||
let mut to_rerender = FxDashSet::default();
|
||||
to_rerender.insert(NodeId(0));
|
||||
to_rerender.insert(rdom.read().unwrap().root_id());
|
||||
let mut updated = true;
|
||||
|
||||
loop {
|
||||
|
@ -167,7 +167,7 @@ pub fn render<R: Renderer>(
|
|||
let width = screen_to_layout_space(dims.width);
|
||||
let height = screen_to_layout_space(dims.height);
|
||||
let root_node = rdom
|
||||
.get(NodeId(0))
|
||||
.get(rdom.root_id())
|
||||
.unwrap()
|
||||
.get::<TaffyLayout>()
|
||||
.unwrap()
|
||||
|
@ -270,7 +270,7 @@ pub fn render<R: Renderer>(
|
|||
let mut rdom = rdom.write().unwrap();
|
||||
let mut any_map = SendAnyMap::new();
|
||||
any_map.insert(taffy.clone());
|
||||
let (new_to_rerender, dirty) = rdom.update_state(any_map, false);
|
||||
let (new_to_rerender, dirty) = rdom.update_state(any_map);
|
||||
to_rerender = new_to_rerender;
|
||||
let text_mask = NodeMaskBuilder::new().with_text().build();
|
||||
for (id, mask) in dirty {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use dioxus_native_core::{node_ref::NodeView, Dependancy, SendAnyMap, State};
|
||||
use dioxus_native_core_macro::partial_derive_state;
|
||||
use shipyard::Component;
|
||||
|
||||
#[derive(PartialEq, Debug, Clone, Copy)]
|
||||
#[derive(PartialEq, Debug, Clone, Copy, Component)]
|
||||
pub(crate) enum PreventDefault {
|
||||
Focus,
|
||||
KeyPress,
|
||||
|
@ -25,6 +27,7 @@ impl Default for PreventDefault {
|
|||
}
|
||||
}
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for PreventDefault {
|
||||
type ParentDependencies = ();
|
||||
type ChildDependencies = ();
|
||||
|
@ -42,7 +45,7 @@ impl State for PreventDefault {
|
|||
node_view: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
_: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
let new = match node_view.attributes().and_then(|mut attrs| {
|
||||
|
@ -78,7 +81,7 @@ impl State for PreventDefault {
|
|||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
|
|
|
@ -28,7 +28,7 @@ pub(crate) fn render_vnode(
|
|||
) {
|
||||
use dioxus_native_core::node::NodeType;
|
||||
|
||||
if let NodeType::Placeholder = &node.node_type() {
|
||||
if let NodeType::Placeholder = &*node.node_type() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ pub(crate) fn render_vnode(
|
|||
let width = layout_to_screen_space(fx + width).round() as u16 - x;
|
||||
let height = layout_to_screen_space(fy + height).round() as u16 - y;
|
||||
|
||||
match node.node_type() {
|
||||
match &*node.node_type() {
|
||||
NodeType::Text(text) => {
|
||||
#[derive(Default)]
|
||||
struct Label<'a> {
|
||||
|
@ -272,11 +272,12 @@ impl RinkWidget for NodeRef<'_> {
|
|||
if let Some(c) = self.get::<StyleModifier>().unwrap().core.bg {
|
||||
new_cell.bg = c;
|
||||
}
|
||||
let focused = self.get::<Focused>();
|
||||
if focused.is_some() && focused.unwrap().0 {
|
||||
if let Some(focused) = self.get::<Focused>() {
|
||||
if focused.0 {
|
||||
new_cell.bg.alpha = 100;
|
||||
new_cell.bg.color = new_cell.bg.blend(Color::White);
|
||||
}
|
||||
}
|
||||
buf.set(x, y, new_cell);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,16 +35,19 @@ use dioxus_native_core::{
|
|||
node_ref::{AttributeMaskBuilder, NodeMaskBuilder, NodeView},
|
||||
Dependancy, SendAnyMap, State,
|
||||
};
|
||||
use dioxus_native_core_macro::partial_derive_state;
|
||||
use shipyard::Component;
|
||||
use taffy::prelude::*;
|
||||
|
||||
use crate::style::{RinkColor, RinkStyle};
|
||||
|
||||
#[derive(Default, Clone, PartialEq, Debug)]
|
||||
#[derive(Default, Clone, PartialEq, Debug, Component)]
|
||||
pub struct StyleModifier {
|
||||
pub core: RinkStyle,
|
||||
pub modifier: TuiModifier,
|
||||
}
|
||||
|
||||
#[partial_derive_state]
|
||||
impl State for StyleModifier {
|
||||
type ParentDependencies = (Self,);
|
||||
type ChildDependencies = ();
|
||||
|
@ -60,7 +63,7 @@ impl State for StyleModifier {
|
|||
node_view: NodeView,
|
||||
_: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
_: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
_: &SendAnyMap,
|
||||
) -> bool {
|
||||
let mut new = StyleModifier::default();
|
||||
|
@ -117,7 +120,7 @@ impl State for StyleModifier {
|
|||
node_view: NodeView<()>,
|
||||
node: <Self::NodeDependencies as Dependancy>::ElementBorrowed<'a>,
|
||||
parent: Option<<Self::ParentDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
children: Option<Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>>,
|
||||
children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
|
||||
context: &SendAnyMap,
|
||||
) -> Self {
|
||||
let mut myself = Self::default();
|
||||
|
|
Loading…
Reference in a new issue