| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::component::button::{Button, ButtonVariants as _}; |
| 3 | use gpui_kit::component::v_flex; |
| 4 | use gpui_kit::*; |
| 5 | |
| 6 | use super::widgets::icon; |
| 7 | use crate::theme; |
| 8 | |
| 9 | pub(super) const TOOL_WIDTH: f32 = 56.; |
| 10 | pub(super) const TOOL_HEIGHT: f32 = 48.; |
| 11 | pub(super) const TOOL_GAP: f32 = 2.; |
| 12 | pub(super) const GROUP_GAP: f32 = 12.; |
| 13 | pub(super) const SPLIT_CHEVRON_WIDTH: f32 = 20.; |
| 14 | pub(super) const LEAVE_HEIGHT: f32 = 32.; |
| 15 | pub(super) const GROUP_DIVIDER_WIDTH: f32 = 1.; |
| 16 | const TOOL_ICON: f32 = 20.; |
| 17 | const TOOL_LABEL: f32 = 11.; |
| 18 | const TOOL_RADIUS: f32 = 6.; |
| 19 | const CHEVRON_ICON: f32 = 12.; |
| 20 | |
| 21 | pub(super) fn tool_face( |
| 22 | id: impl Into<ElementId>, |
| 23 | glyph: IconName, |
| 24 | label: impl Into<SharedString>, |
| 25 | active: bool, |
| 26 | ) -> Stateful<Div> { |
| 27 | let color = if active { |
| 28 | theme::accent_text() |
| 29 | } else { |
| 30 | theme::text() |
| 31 | }; |
| 32 | v_flex() |
| 33 | .id(id) |
| 34 | .w(px(TOOL_WIDTH)) |
| 35 | .h(px(TOOL_HEIGHT)) |
| 36 | .flex_none() |
| 37 | .items_center() |
| 38 | .justify_center() |
| 39 | .gap(px(3.)) |
| 40 | .rounded(px(TOOL_RADIUS)) |
| 41 | .cursor_pointer() |
| 42 | .hover(|face| face.bg(theme::row_hover())) |
| 43 | .child(icon(glyph, TOOL_ICON, color)) |
| 44 | .child( |
| 45 | div() |
| 46 | .text_size(px(TOOL_LABEL)) |
| 47 | .line_height(px(TOOL_LABEL + 3.)) |
| 48 | .text_color(color) |
| 49 | .child(label.into()), |
| 50 | ) |
| 51 | } |
| 52 | |
| 53 | pub(super) fn tool_trigger(button_id: &'static str, face: Stateful<Div>) -> Button { |
| 54 | Button::new(button_id) |
| 55 | .ghost() |
| 56 | .p_0() |
| 57 | .w(px(TOOL_WIDTH)) |
| 58 | .h(px(TOOL_HEIGHT)) |
| 59 | .rounded(px(TOOL_RADIUS)) |
| 60 | .child(face) |
| 61 | } |
| 62 | |
| 63 | pub(super) fn split_chevron(button_id: &'static str, face_id: &'static str) -> Button { |
| 64 | Button::new(button_id) |
| 65 | .ghost() |
| 66 | .p_0() |
| 67 | .w(px(SPLIT_CHEVRON_WIDTH)) |
| 68 | .h(px(TOOL_HEIGHT)) |
| 69 | .rounded(px(TOOL_RADIUS)) |
| 70 | .child( |
| 71 | div() |
| 72 | .id(face_id) |
| 73 | .w(px(SPLIT_CHEVRON_WIDTH)) |
| 74 | .h(px(TOOL_HEIGHT)) |
| 75 | .flex() |
| 76 | .items_center() |
| 77 | .justify_center() |
| 78 | .rounded(px(TOOL_RADIUS)) |
| 79 | .hover(|face| face.bg(theme::row_hover())) |
| 80 | .child(icon(IconName::ChevronDown, CHEVRON_ICON, theme::text())), |
| 81 | ) |
| 82 | } |
| 83 | |
| 84 | pub(super) fn group_divider() -> Div { |
| 85 | div() |
| 86 | .flex_none() |
| 87 | .w(px(GROUP_DIVIDER_WIDTH)) |
| 88 | .h(px(TOOL_HEIGHT - 16.)) |
| 89 | .bg(theme::border()) |
| 90 | } |