TUI rendering mostly working

This commit is contained in:
Evan Almloff 2023-02-01 14:36:56 -06:00
parent 39a3db68bd
commit 71a0bdf71d
8 changed files with 20 additions and 44 deletions

View file

@ -160,36 +160,6 @@ pub struct NodeMask {
}
impl NodeMask {
pub fn from_node(node: &NodeType) -> Self {
match node {
NodeType::Text { .. } => NodeMaskBuilder::new().with_text().build(),
NodeType::Element(ElementNode {
tag: _,
namespace: _,
attributes,
listeners,
}) => Self {
attritutes: AttributeMask::Some(
attributes
.keys()
.map(|key| key.name.as_str().into())
.collect(),
),
namespace: true,
tag: true,
text: false,
listeners: !listeners.is_empty(),
},
NodeType::Placeholder => Self {
attritutes: AttributeMask::default(),
tag: true,
namespace: true,
text: false,
listeners: false,
},
}
}
/// Check if two masks overlap
pub fn overlaps(&self, other: &Self) -> bool {
(self.tag && other.tag)

View file

@ -191,7 +191,6 @@ pub trait Pass<V: FromAnyValue + Send + Sync = ()>: Any + Send + Sync {
debug_assert!(!Self::NodeDependencies::type_ids()
.iter()
.any(|id| *id == TypeId::of::<Self>()));
println!("passing: {node_id:?}");
// get all of the states from the tree view
// Safety: No node has itself as a parent or child.
let myself: SlabEntry<'static, Self> = unsafe {

View file

@ -610,6 +610,7 @@ pub trait NodeImmutable<V: FromAnyValue + Send + Sync>: Sized {
pub trait NodeMutable<V: FromAnyValue + Send + Sync>: Sized + NodeImmutable<V> {
fn get_mut<T: Any + Sync + Send>(&mut self) -> Option<&mut T>;
fn insert<T: Any + Sync + Send>(&mut self, value: T);
}
#[derive(Clone, Copy)]
@ -648,6 +649,10 @@ impl<'a, V: FromAnyValue + Send + Sync> NodeMutable<V> for NodeMut<'a, V> {
fn get_mut<T: Any + Sync + Send>(&mut self) -> Option<&mut T> {
todo!("get_mut with mark as dirty")
}
fn insert<T: Any + Sync + Send>(&mut self, _: T) {
todo!("insert with mark as dirty")
}
}
impl<'a, V: FromAnyValue + Send + Sync> NodeMut<'a, V> {
@ -777,4 +782,8 @@ impl<'a, V: FromAnyValue + Send + Sync> NodeMutable<V> for NodeMutRaw<'a, V> {
fn get_mut<T: Any + Sync + Send>(&mut self) -> Option<&mut T> {
self.dom.tree.get_mut::<T>(self.id)
}
fn insert<T: Any + Sync + Send>(&mut self, value: T) {
self.dom.tree.insert(self.id, value);
}
}

View file

@ -173,15 +173,17 @@ impl Tree {
}
pub fn get<T: Any + Sync + Send>(&self, id: NodeId) -> Option<&T> {
self.nodes.read_slab().get(id)
self.nodes.try_read_slab().and_then(|slab| slab.get(id))
}
pub fn get_mut<T: Any + Sync + Send>(&mut self, id: NodeId) -> Option<&mut T> {
self.nodes.write_slab().get_mut(id)
self.nodes
.try_write_slab()
.and_then(|slab| slab.get_mut(id))
}
pub fn insert<T: Any + Sync + Send>(&mut self, id: NodeId, value: T) {
self.nodes.write_slab().insert(id, value);
self.nodes.get_or_insert_slab_mut().insert(id, value);
}
pub fn contains(&self, id: NodeId) -> bool {
@ -218,11 +220,9 @@ impl<'a> DynamicallyBorrowedTree<'a> {
let nodes_data = self.node_slab();
let mut nodes = FxHashMap::default();
for id in immutable {
println!("reading {id:?}");
nodes.insert(id, MaybeRead::Read(self.nodes.get_slab(id).unwrap()));
}
for id in mutable {
println!("writing {id:?}");
nodes.insert(id, MaybeRead::Write(self.nodes.get_slab_mut(id).unwrap()));
}

View file

@ -246,8 +246,7 @@ impl FocusState {
if !node.get::<Focus>().unwrap().level.focusable() {
panic!()
}
let focused = node.get_mut::<Focused>().unwrap();
focused.0 = true;
node.insert(Focused(true));
if let Some(old) = self.last_focused_id.replace(id) {
let mut old = rdom.get_mut_raw(old).unwrap();
let focused = old.get_mut::<Focused>().unwrap();
@ -304,7 +303,7 @@ impl FocusState {
node.get_mut::<Focused>().unwrap().0 = false;
}
let mut node = rdom.get_mut_raw(id).unwrap();
node.get_mut::<Focused>().unwrap().0 = true;
node.insert(Focused(true));
self.focus_level = node.get::<Focus>().unwrap().level;
// reset the position to the currently focused element
while self.focus_iter.next(rdom).id() != id {}

View file

@ -688,7 +688,8 @@ impl RinkInputHandler {
for (event, datas) in hm {
for node in dom.get_listening_sorted(event) {
for data in &datas {
if node.get::<Focused>().unwrap().0 {
let focused = node.get::<Focused>();
if focused.is_some() && focused.unwrap().0 {
if let Some(id) = node.mounted_id() {
resolved_events.push(Event {
name: event,

View file

@ -91,9 +91,6 @@ impl Pass for TaffyLayout {
attribute, value, ..
} in attributes
{
assert!(SORTED_LAYOUT_ATTRS
.binary_search(&attribute.name.as_ref())
.is_ok());
if let Some(text) = value.as_text() {
apply_layout_attributes_cfg(
&attribute.name,

View file

@ -272,7 +272,8 @@ impl RinkWidget for NodeRef<'_> {
if let Some(c) = self.get::<StyleModifier>().unwrap().core.bg {
new_cell.bg = c;
}
if self.get::<Focused>().unwrap().0 {
let focused = self.get::<Focused>();
if focused.is_some() && focused.unwrap().0 {
new_cell.bg.alpha = 100;
new_cell.bg.color = new_cell.bg.blend(Color::White);
}