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