ferroui_base/
visual_tree_attachment_event_args.rs1use crate::rendering::IPresentationSource;
2use crate::{Ref, Visual};
3use std::rc::Rc;
4
5#[derive(Clone)]
8pub struct VisualTreeAttachmentEventArgs {
9 attachment_point: Option<Ref<Visual>>,
10 presentation_source: Rc<dyn IPresentationSource>,
11 root_visual: Ref<Visual>,
12}
13
14impl VisualTreeAttachmentEventArgs {
15 pub fn new(attachment_point: Option<Ref<Visual>>, presentation_source: Rc<dyn IPresentationSource>) -> Self {
17 let root_visual =
18 presentation_source.root_visual().expect("PresentationSource must have a non-null RootVisual.");
19 Self { attachment_point, presentation_source, root_visual }
20 }
21
22 pub fn attachment_point(&self) -> Option<&Ref<Visual>> {
26 self.attachment_point.as_ref()
27 }
28
29 #[deprecated(note = "Use attachment_point")]
32 pub fn parent(&self) -> Option<&Ref<Visual>> {
33 self.attachment_point()
34 }
35
36 pub fn presentation_source(&self) -> &Rc<dyn IPresentationSource> {
39 &self.presentation_source
40 }
41
42 #[deprecated(
44 note = "This was previously always returning TopLevel. This is no longer guaranteed. Use TopLevel::get_top_level(visual) if you need a TopLevel or root_visual if you are interested in the root of the visual tree."
45 )]
46 pub fn root(&self) -> &Ref<Visual> {
47 &self.root_visual
48 }
49
50 pub fn root_visual(&self) -> &Ref<Visual> {
53 &self.root_visual
54 }
55
56 pub fn set_root_visual(&mut self, value: Ref<Visual>) {
57 self.root_visual = value;
58 }
59}
60
61impl PartialEq for VisualTreeAttachmentEventArgs {
64 fn eq(&self, other: &Self) -> bool {
65 self.attachment_point == other.attachment_point
66 && self.root_visual == other.root_visual
67 && std::ptr::addr_eq(Rc::as_ptr(&self.presentation_source), Rc::as_ptr(&other.presentation_source))
68 }
69}