Skip to content

Commit

Permalink
refactor(core): 💡 remove RenderNodeFlag
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo committed Sep 7, 2023
1 parent 3c88f47 commit 54009ab
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
9 changes: 1 addition & 8 deletions core/src/context/build_context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
prelude::*,
widget::{widget_id::new_node, TreeArena, WidgetTree},
widget::{widget_id::new_node, WidgetTree},
window::{DelayEvent, WindowId},
};
use std::{
Expand Down Expand Up @@ -117,8 +117,6 @@ impl<'a> BuildCtx<'a> {
tree
.window()
.add_delay_event(DelayEvent::Disposed { id, parent });
let (arena1, arena2) = unsafe { split_arena(&mut tree.arena) };
id.descendants(arena1).for_each(|id| id.mark_drop(arena2))
}

pub(crate) fn mark_dirty(&mut self, id: WidgetId) { self.tree.borrow_mut().mark_dirty(id); }
Expand Down Expand Up @@ -174,11 +172,6 @@ impl BuildCtxHandle {
}
}

pub(crate) unsafe fn split_arena(tree: &mut TreeArena) -> (&mut TreeArena, &mut TreeArena) {
let ptr = tree as *mut TreeArena;
(&mut *ptr, &mut *ptr)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
3 changes: 1 addition & 2 deletions core/src/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,7 @@ mod tests {

c_child.state_ref().take();
wnd.draw_frame();
assert!(grandson_id.is_dropped(&tree_arena(&wnd)));
assert!(!grandson_id.0.is_removed(&tree_arena(&wnd)));
assert!(!grandson_id.is_dropped(&tree_arena(&wnd)));

*c_child_destroy_until.state_ref() = true;
wnd.draw_frame();
Expand Down
29 changes: 2 additions & 27 deletions core/src/widget_tree/widget_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ pub struct WidgetId(pub(crate) NodeId);

pub(crate) type TreeArena = Arena<RenderNode>;

bitflags! {
#[derive(Default, PartialEq, Eq, Clone, Copy, Hash, Debug)]
pub(crate) struct RenderNodeFlag: u8 {
const NONE = 0;
const DROPPED = 0b0001;
}
}
pub(crate) struct RenderNode {
flags: RenderNodeFlag,
data: Box<dyn Render>,
}

Expand All @@ -47,21 +39,8 @@ impl WidgetId {
tree.get_mut(self.0).map(|n| n.get_mut())
}

/// Mark the widget dropped but not release the node, caller has the
/// responsibility to release it.
pub(crate) fn mark_drop(self, tree: &mut TreeArena) {
if let Some(node) = self.get_node_mut(tree) {
node.flags.insert(RenderNodeFlag::DROPPED);
}
}

/// detect if the widget of this id point to is dropped.
pub(crate) fn is_dropped(self, tree: &TreeArena) -> bool {
self.0.is_removed(tree)
|| self
.get_node(tree)
.map_or(true, |n| n.flags.contains(RenderNodeFlag::DROPPED))
}
pub(crate) fn is_dropped(self, tree: &TreeArena) -> bool { self.0.is_removed(tree) }

#[allow(clippy::needless_collect)]
pub(crate) fn lowest_common_ancestor(
Expand Down Expand Up @@ -229,12 +208,8 @@ impl WidgetId {
}
}


pub(crate) fn new_node(arena: &mut TreeArena, node: Box<dyn Render>) -> WidgetId {
WidgetId(arena.new_node(RenderNode {
flags: RenderNodeFlag::NONE,
data: node,
}))
WidgetId(arena.new_node(RenderNode { data: node }))
}

pub(crate) fn empty_node(arena: &mut TreeArena) -> WidgetId { new_node(arena, Box::new(Void)) }
Expand Down

0 comments on commit 54009ab

Please sign in to comment.