feather_ui/component/
domain_line.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2025 Fundament Research Institute <https://fundament.institute>
3
4use crate::color::sRGB;
5use crate::layout::{Layout, base};
6use crate::{CrossReferenceDomain, SourceID, layout, render};
7use derive_where::derive_where;
8use std::rc::Rc;
9use std::sync::Arc;
10
11// This draws a line between two points that were previously stored in a
12// Cross-reference Domain
13#[derive(feather_macro::StateMachineChild)]
14#[derive_where(Clone)]
15pub struct DomainLine<T> {
16    pub id: Arc<SourceID>,
17    pub domain: Arc<CrossReferenceDomain>,
18    pub start: Arc<SourceID>,
19    pub end: Arc<SourceID>,
20    pub props: Rc<T>,
21    pub fill: sRGB,
22}
23
24impl<T: base::Empty + 'static> super::Component for DomainLine<T>
25where
26    for<'a> &'a T: Into<&'a (dyn base::Empty + 'static)>,
27{
28    type Props = T;
29
30    fn layout(
31        &self,
32        _: &mut crate::StateManager,
33        _: &crate::graphics::Driver,
34        _: &Arc<SourceID>,
35    ) -> Box<dyn Layout<T>> {
36        Box::new(layout::Node::<T, dyn base::Empty> {
37            props: self.props.clone(),
38            children: Default::default(),
39            id: Arc::downgrade(&self.id),
40            renderable: Some(Rc::new(render::domain::line::Instance {
41                domain: self.domain.clone(),
42                start: self.start.clone(),
43                end: self.end.clone(),
44                color: self.fill,
45            })),
46            layer: None,
47        })
48    }
49}