Skip to main content

ferroui_base/logical_tree/
logical_tree_attachment_event_args.rs

1use crate::{Ref, StyledElement};
2
3/// Holds the event arguments for the `attached_to_logical_tree` and
4/// `detached_from_logical_tree` events.
5/// The args are immutable: copies compare equal when they describe the same
6/// attachment (the same elements).
7#[derive(Clone, PartialEq)]
8pub struct LogicalTreeAttachmentEventArgs {
9    root: Ref<StyledElement>,
10    source: Ref<StyledElement>,
11    parent: Option<Ref<StyledElement>>,
12}
13
14impl LogicalTreeAttachmentEventArgs {
15    pub fn new(root: Ref<StyledElement>, source: Ref<StyledElement>, parent: Option<Ref<StyledElement>>) -> Self {
16        Self { root, source, parent }
17    }
18
19    /// The root of the logical tree that the control is being attached to or
20    /// detached from.
21    pub fn root(&self) -> &Ref<StyledElement> {
22        &self.root
23    }
24
25    /// The control that was attached or detached from the logical tree.
26    ///
27    /// Logical tree attachment events travel down the tree, so this is the
28    /// control at the top of the subtree that was attached or detached.
29    pub fn source(&self) -> &Ref<StyledElement> {
30        &self.source
31    }
32
33    /// The control that the source is being attached to or detached from.
34    /// For a detachment this is the old parent; `None` when the source is a
35    /// logical root.
36    pub fn parent(&self) -> Option<&Ref<StyledElement>> {
37        self.parent.as_ref()
38    }
39}