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 layout. Later this will turn
9// into an absolute bounding volume. There can be multiple root nodes, each mapping to a different window.
10pub trait Prop {
11    fn dim(&self) -> &PxDim;
12}
13
14crate::gen_from_to_dyn!(Prop);
15
16impl Prop for PxDim {
17    fn dim(&self) -> &PxDim {
18        self
19    }
20}
21
22impl Desc for dyn Prop {
23    type Props = dyn Prop;
24    type Child = dyn base::Empty;
25    type Children = Box<dyn Layout<Self::Child>>;
26
27    fn stage<'a>(
28        props: &Self::Props,
29        _: PxRect,
30        _: crate::PxLimits,
31        child: &Self::Children,
32        _: std::sync::Weak<crate::SourceID>,
33        _: Option<Rc<dyn Renderable>>,
34        window: &mut crate::component::window::WindowState,
35    ) -> Box<dyn Staged + 'a> {
36        // We bypass creating our own node here because we can never have a nonzero topleft corner, so our node would be redundant.
37        child.stage(
38            (*props.dim()).cast_unit().into(),
39            Default::default(),
40            window,
41        )
42    }
43}