Skip to main content

gpui_component/sidebar/
footer.rs

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