Skip to content

Commit

Permalink
make advanced layout possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmoulton committed Feb 3, 2025
1 parent 03a9582 commit 6516b22
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl ViewId {
});
}

pub(crate) fn taffy(&self) -> Rc<RefCell<TaffyTree>> {
/// Get access to the taffy tree
pub fn taffy(&self) -> Rc<RefCell<TaffyTree>> {
VIEW_STORAGE.with_borrow(|s| s.taffy.clone())
}

Expand Down Expand Up @@ -99,6 +100,7 @@ impl ViewId {
})
}

/// Get access to the View
pub(crate) fn view(&self) -> Rc<RefCell<Box<dyn View>>> {
VIEW_STORAGE.with_borrow(|s| {
s.views
Expand Down Expand Up @@ -253,6 +255,27 @@ impl ViewId {
Some(layout)
}

/// Get the taffy layout of this id relative to a parent/ancestor ID
pub fn get_layout_relative_to(&self, relative_to: ViewId) -> Option<Layout> {
let taffy = self.taffy();
let target_node = relative_to.state().borrow().node;
let mut node = self.state().borrow().node;
let mut layout = *taffy.borrow().layout(node).ok()?;

loop {
let parent = taffy.borrow().parent(node);
if parent == Some(target_node) {
break;
}

// If we've reached the root without finding the target, return None
node = parent?;
layout.location = layout.location + taffy.borrow().layout(node).ok()?.location;
}

Some(layout)
}

/// Returns true if the computed style for this view is marked as hidden (Display::None)
pub fn style_has_hidden(&self) -> bool {
let state = self.state();
Expand Down

0 comments on commit 6516b22

Please sign in to comment.