gpui_component/sidebar/
footer.rs

1use gpui::{
2    prelude::FluentBuilder as _, Div, InteractiveElement, IntoElement, ParentElement, RenderOnce,
3    Styled,
4};
5
6use crate::{h_flex, menu::DropdownMenu, ActiveTheme as _, Collapsible, Selectable};
7
8/// Footer for the [`super::Sidebar`].
9#[derive(IntoElement)]
10pub struct SidebarFooter {
11    base: Div,
12    selected: bool,
13    collapsed: bool,
14}
15
16impl SidebarFooter {
17    /// Create a new [`SidebarFooter`].
18    pub fn new() -> Self {
19        Self {
20            base: h_flex().gap_2().w_full(),
21            selected: false,
22            collapsed: false,
23        }
24    }
25}
26
27impl Selectable for SidebarFooter {
28    fn selected(mut self, selected: bool) -> Self {
29        self.selected = selected;
30        self
31    }
32
33    fn is_selected(&self) -> bool {
34        self.selected
35    }
36}
37
38impl Collapsible for SidebarFooter {
39    fn is_collapsed(&self) -> bool {
40        self.collapsed
41    }
42
43    fn collapsed(mut self, collapsed: bool) -> Self {
44        self.collapsed = collapsed;
45        self
46    }
47}
48
49impl ParentElement for SidebarFooter {
50    fn extend(&mut self, elements: impl IntoIterator<Item = gpui::AnyElement>) {
51        self.base.extend(elements);
52    }
53}
54
55impl Styled for SidebarFooter {
56    fn style(&mut self) -> &mut gpui::StyleRefinement {
57        self.base.style()
58    }
59}
60
61impl InteractiveElement for SidebarFooter {
62    fn interactivity(&mut self) -> &mut gpui::Interactivity {
63        self.base.interactivity()
64    }
65}
66
67impl DropdownMenu for SidebarFooter {}
68
69impl RenderOnce for SidebarFooter {
70    fn render(self, _: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement {
71        h_flex()
72            .id("sidebar-footer")
73            .gap_2()
74            .p_2()
75            .w_full()
76            .justify_between()
77            .rounded(cx.theme().radius)
78            .hover(|this| {
79                this.bg(cx.theme().sidebar_accent)
80                    .text_color(cx.theme().sidebar_accent_foreground)
81            })
82            .when(self.selected, |this| {
83                this.bg(cx.theme().sidebar_accent)
84                    .text_color(cx.theme().sidebar_accent_foreground)
85            })
86            .child(self.base)
87    }
88}