1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Defines several kinds of window-sized screens.

use crate::{
    default_theme::app_background_color,
    layout::{Dock, WindowSized},
    UIBase, UIExt,
};
use ambient_element::{
    define_el_function_for_vec_element_newtype, Element, ElementComponent, ElementComponentExt,
    Hooks,
};
use ambient_guest_bridge::core::{
    layout::components::is_screen, transform::components::translation,
};
use glam::vec3;

#[derive(Clone, Debug)]
/// Contains an element with a background color and click area.
pub struct ScreenContainer(pub Option<Element>);
impl ElementComponent for ScreenContainer {
    #[allow(clippy::clone_on_copy)]
    fn render(self: Box<Self>, _: &mut Hooks) -> Element {
        if let Some(content) = self.0 {
            UIBase
                .el()
                .with(is_screen(), ())
                .children(vec![WindowSized(vec![Dock(vec![content])
                    .el()
                    .with(translation(), vec3(0., 0., 0.1))])
                .el()
                .with_background(app_background_color().set_a(0.99).clone().into())
                .with_clickarea()
                .el()])
        } else {
            Element::new()
        }
    }
}

#[derive(Clone, Debug)]
/// Contains several elements with a background color and click area.
pub struct PageScreen(pub Vec<Element>);
define_el_function_for_vec_element_newtype!(PageScreen);
impl ElementComponent for PageScreen {
    #[allow(clippy::clone_on_copy)]
    fn render(self: Box<Self>, _: &mut Hooks) -> Element {
        WindowSized(vec![Dock(self.0).el().with_padding_even(30.)])
            .el()
            .with_background(app_background_color().set_a(0.99).clone().into())
            .with_clickarea()
            .el()
    }
}

#[derive(Clone, Debug)]
/// Contains a single element with a background color and click area.
// TODO: isn't this just [PageScreen] with a single element?
pub struct DialogScreen(pub Element);
impl ElementComponent for DialogScreen {
    #[allow(clippy::clone_on_copy)]
    fn render(self: Box<Self>, _: &mut Hooks) -> Element {
        WindowSized(vec![Dock(vec![self.0]).el().with_padding_even(30.)])
            .el()
            .with_background(app_background_color().set_a(0.99).clone().into())
            .with_clickarea()
            .el()
    }
}