Skip to main content

fret_ui_kit/
ui_builder_impls.rs

1use fret_ui::element::AnyElement;
2use fret_ui::{ElementContext, UiHost};
3
4use crate::primitives::aspect_ratio::AspectRatio;
5use crate::primitives::label::Label;
6use crate::primitives::separator::Separator;
7use crate::{IntoUiElement, UiPatch, UiPatchTarget, UiSupportsChrome, UiSupportsLayout};
8
9impl UiPatchTarget for Label {
10    fn apply_ui_patch(self, _patch: UiPatch) -> Self {
11        self
12    }
13}
14
15impl<H: UiHost> IntoUiElement<H> for Label {
16    fn into_element(self, cx: &mut ElementContext<'_, H>) -> AnyElement {
17        Label::into_element(self, cx)
18    }
19}
20
21impl UiPatchTarget for Separator {
22    fn apply_ui_patch(self, patch: UiPatch) -> Self {
23        self.refine_layout(patch.layout)
24    }
25}
26
27impl UiSupportsLayout for Separator {}
28
29impl<H: UiHost> IntoUiElement<H> for Separator {
30    fn into_element(self, cx: &mut ElementContext<'_, H>) -> AnyElement {
31        Separator::into_element(self, cx)
32    }
33}
34
35impl UiPatchTarget for AspectRatio {
36    fn apply_ui_patch(self, patch: UiPatch) -> Self {
37        self.refine_style(patch.chrome).refine_layout(patch.layout)
38    }
39}
40
41impl UiSupportsChrome for AspectRatio {}
42impl UiSupportsLayout for AspectRatio {}
43
44impl<H: UiHost> IntoUiElement<H> for AspectRatio {
45    fn into_element(self, cx: &mut ElementContext<'_, H>) -> AnyElement {
46        AspectRatio::into_element(self, cx)
47    }
48}
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53    use crate::LayoutRefinement;
54    use crate::UiExt as _;
55
56    #[test]
57    fn ui_builder_supports_selected_primitives() {
58        let _ = Label::new("x").ui().build();
59        let _ = Separator::new()
60            .ui()
61            .layout(LayoutRefinement::default())
62            .build();
63        let _ = Separator::new().ui().w_full().build();
64
65        // Compile-only smoke: `AspectRatio` stays compatible with the UI patch/builder surface.
66        fn assert_aspect_ratio_builds(ar: AspectRatio) {
67            let _ = ar.ui().p(crate::Space::N4).w_full().build();
68        }
69        let _ = assert_aspect_ratio_builds;
70    }
71}