kernel_list_item.rs

 1use gpui::AnyElement;
 2use ui::{Indicator, ListItem, prelude::*};
 3
 4use crate::KernelSpecification;
 5
 6#[derive(IntoElement)]
 7pub struct KernelListItem {
 8    kernel_specification: KernelSpecification,
 9    status_color: Color,
10    buttons: Vec<AnyElement>,
11    children: Vec<AnyElement>,
12}
13
14impl KernelListItem {
15    pub fn new(kernel_specification: KernelSpecification) -> Self {
16        Self {
17            kernel_specification,
18            status_color: Color::Disabled,
19            buttons: Vec::new(),
20            children: Vec::new(),
21        }
22    }
23
24    pub fn status_color(mut self, color: Color) -> Self {
25        self.status_color = color;
26        self
27    }
28
29    pub fn button(mut self, button: impl IntoElement) -> Self {
30        self.buttons.push(button.into_any_element());
31        self
32    }
33
34    pub fn buttons(mut self, buttons: impl IntoIterator<Item = impl IntoElement>) -> Self {
35        self.buttons
36            .extend(buttons.into_iter().map(|button| button.into_any_element()));
37        self
38    }
39}
40
41impl ParentElement for KernelListItem {
42    fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
43        self.children.extend(elements);
44    }
45}
46
47impl RenderOnce for KernelListItem {
48    fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
49        ListItem::new(self.kernel_specification.name())
50            .selectable(false)
51            .start_slot(
52                h_flex()
53                    .size_3()
54                    .justify_center()
55                    .child(Indicator::dot().color(self.status_color)),
56            )
57            .children(self.children)
58            .end_slot(h_flex().gap_2().children(self.buttons))
59    }
60}