feather_ui/layout/
root.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2025 Fundament Research Institute <https://fundament.institute>
3
4use super::{Desc, Layout, Renderable, Staged, base};
5use crate::{PxDim, PxRect};
6use std::rc::Rc;
7
8// The root node represents some area on the screen that contains a feather
9// layout. Later this will turn into an absolute bounding volume. There can be
10// multiple root nodes, each mapping to a different window.
11pub trait Prop {
12    fn dim(&self) -> &PxDim;
13}
14
15crate::gen_from_to_dyn!(Prop);
16
17impl Prop for PxDim {
18    fn dim(&self) -> &PxDim {
19        self
20    }
21}
22
23impl Desc for dyn Prop {
24    type Props = dyn Prop;
25    type Child = dyn base::Empty;
26    type Children = Box<dyn Layout<Self::Child>>;
27
28    fn stage<'a>(
29        props: &Self::Props,
30        _: PxRect,
31        _: crate::PxLimits,
32        child: &Self::Children,
33        _: std::sync::Weak<crate::SourceID>,
34        _: Option<Rc<dyn Renderable>>,
35        window: &mut crate::component::window::WindowState,
36    ) -> Box<dyn Staged + 'a> {
37        // We bypass creating our own node here because we can never have a nonzero
38        // topleft corner, so our node would be redundant.
39        child.stage(
40            (*props.dim()).cast_unit().into(),
41            Default::default(),
42            window,
43        )
44    }
45}