feather_ui/component/
domain_point.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2025 Fundament Research Institute <https://fundament.institute>
3
4use crate::SourceID;
5use crate::layout::domain_write;
6use derive_where::derive_where;
7use std::rc::Rc;
8use std::sync::Arc;
9
10// This simply writes it's area to the given cross-reference domain during the
11// layout phase
12#[derive(feather_macro::StateMachineChild)]
13#[derive_where(Clone)]
14pub struct DomainPoint<T> {
15    pub id: Arc<SourceID>,
16    props: Rc<T>,
17}
18
19impl<T: domain_write::Prop + 'static> DomainPoint<T> {
20    pub fn new(id: Arc<SourceID>, props: T) -> Self {
21        Self {
22            id,
23            props: props.into(),
24        }
25    }
26}
27
28impl<T: domain_write::Prop + 'static> super::Component for DomainPoint<T>
29where
30    for<'a> &'a T: Into<&'a (dyn domain_write::Prop + 'static)>,
31{
32    type Props = T;
33
34    fn layout(
35        &self,
36        _: &mut crate::StateManager,
37        _: &crate::graphics::Driver,
38        _: &Arc<SourceID>,
39    ) -> Box<dyn crate::layout::Layout<T>> {
40        Box::new(crate::layout::Node::<T, dyn domain_write::Prop> {
41            props: self.props.clone(),
42            children: Default::default(),
43            id: Arc::downgrade(&self.id),
44            renderable: None,
45            layer: None,
46        })
47    }
48}