dusk_ui/
component.rs

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
use twilight_model::channel::message;

use crate::context::BuildContextPrefix;

pub mod button;
pub mod row_button;
pub mod select_menu;

pub trait Component<D> {
    fn build(self: Box<Self>, ctx: BuildContextPrefix<D>) -> message::Component;
}

#[derive(Default)]
pub struct CompWindow<D> {
    phantom: std::marker::PhantomData<D>,
    pub(crate) children: Vec<Box<dyn Component<D>>>,
}

impl<D> CompWindow<D> {
    pub fn new() -> Self {
        Self {
            phantom: Default::default(),
            children: Vec::new(),
        }
    }
}

impl<D, C: 'static + Component<D>> std::ops::Add<C> for CompWindow<D> {
    type Output = Self;

    fn add(mut self, rhs: C) -> Self::Output {
        self.children.push(Box::new(rhs));
        self
    }
}