tab.rs

 1use gpui2::elements::div;
 2use gpui2::style::{StyleHelpers, Styleable};
 3use gpui2::{Element, IntoElement, ParentElement, ViewContext};
 4
 5use crate::theme;
 6
 7#[derive(Element)]
 8pub struct Tab {
 9    title: &'static str,
10    enabled: bool,
11}
12
13pub fn tab<V: 'static>(title: &'static str, enabled: bool) -> impl Element<V> {
14    Tab { title, enabled }
15}
16
17impl Tab {
18    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
19        let theme = theme(cx);
20
21        div()
22            .px_2()
23            .py_0p5()
24            .flex()
25            .items_center()
26            .justify_center()
27            .rounded_lg()
28            .fill(if self.enabled {
29                theme.highest.on.default.background
30            } else {
31                theme.highest.base.default.background
32            })
33            .hover()
34            .fill(if self.enabled {
35                theme.highest.on.hovered.background
36            } else {
37                theme.highest.base.hovered.background
38            })
39            .active()
40            .fill(if self.enabled {
41                theme.highest.on.pressed.background
42            } else {
43                theme.highest.base.pressed.background
44            })
45            .child(
46                div()
47                    .text_sm()
48                    .text_color(if self.enabled {
49                        theme.highest.base.default.foreground
50                    } else {
51                        theme.highest.variant.default.foreground
52                    })
53                    .child(self.title),
54            )
55    }
56}