ui/
ui.rs

1use forte_engine::{component_app::EngineComponent, create_app, run_app, ui::{elements::UIElement, style::{Color, PositionSetting, Sizing, Style}, UIEngine}};
2use glyphon::{Attrs, Metrics};
3
4pub struct TestComponent {}
5
6impl EngineComponent<(&mut RenderEngine, &mut UIEngine)> for TestComponent {
7    fn start(&mut self, (engine, ui): (&mut RenderEngine, &mut UIEngine)) {
8        let mut a = UIElement::container(
9            &engine, 
10            Style { 
11                width: Sizing::Px(200.0), 
12                height: Sizing::Px(200.0), 
13                color: Color { red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0 },
14                border: Sizing::Px(5.0),
15                round: Sizing::Px(15.0),
16                ..Default::default() 
17            }
18        );
19        a.children.push(UIElement::container(
20            &engine, 
21            Style {
22                width: Sizing::Px(100.0), 
23                height: Sizing::Px(100.0), 
24                position_setting: PositionSetting::Parent,
25                top: Sizing::Px(10.0),
26                left: Sizing::Px(10.0),
27                border: Sizing::Px(5.0),
28                round: Sizing::Px(10.0),
29                color: Color { red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0 },
30                ..Default::default() 
31            }
32        ));
33        ui.elements.push(a);
34
35        let text = UIElement::text(
36            &engine, 
37            ui,
38            Style {
39                width: Sizing::Px(180.0), 
40                height: Sizing::Px(50.0), 
41                position_setting: PositionSetting::Parent,
42                top: Sizing::Px(10.0),
43                left: Sizing::Px(10.0),
44                border: Sizing::Px(5.0),
45                round: Sizing::Px(10.0),
46                color: Color { red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0 },
47                ..Default::default() 
48            }, 
49            "Hello world!",
50            Attrs::new().family(glyphon::Family::SansSerif),
51            glyphon::Color::rgb(255, 255, 255),
52            Metrics::new(30.0, 42.0)
53        );
54        ui.elements.push(text);
55    }
56
57    fn create(_: &mut RenderEngine) -> Self { Self {} }
58    fn update(&mut self, _: (&mut RenderEngine, &mut UIEngine)) {}
59    fn render<'rpass>(&'rpass mut self, _: &'rpass RenderEngine, _: &mut wgpu::RenderPass<'rpass>) {}
60    fn exit(&mut self, _: (&mut RenderEngine, &mut UIEngine)) {}
61}
62
63create_app! {
64    CLEAR_COLOR = wgpu::Color { r: 0.0, g: 0.0, b: 0.0, a: 0.0 },
65
66    APP {
67        ui_engine: UIEngine[render_engine],
68        test: TestComponent[render_engine, ui_engine]
69    },
70
71    PASSES {
72        0: {
73            PARTS: [
74                {
75                    PIPELINE: "forte.ui",
76                    PREPARE: [],
77                    RENDER: ui_engine,
78                }
79            ],
80            DEPTH: false
81        }
82    }
83}
84
85fn main() { pollster::block_on(run_app::<App>()) }