1#![allow(missing_docs)]
2
3use crate::prelude::*;
4use gpui::*;
5
6#[derive(IntoElement)]
7pub struct ToolStrip {
8 id: ElementId,
9 tools: Vec<IconButton>,
10 axis: Axis,
11}
12
13impl ToolStrip {
14 fn new(id: ElementId, axis: Axis) -> Self {
15 Self {
16 id,
17 tools: vec![],
18 axis,
19 }
20 }
21
22 pub fn vertical(id: impl Into<ElementId>) -> Self {
23 Self::new(id.into(), Axis::Vertical)
24 }
25
26 pub fn tools(mut self, tools: Vec<IconButton>) -> Self {
27 self.tools = tools;
28 self
29 }
30
31 pub fn tool(mut self, tool: IconButton) -> Self {
32 self.tools.push(tool);
33 self
34 }
35}
36
37impl RenderOnce for ToolStrip {
38 fn render(self, cx: &mut WindowContext) -> impl IntoElement {
39 let group = format!("tool_strip_{}", self.id.clone());
40
41 div()
42 .id(self.id.clone())
43 .group(group)
44 .map(|element| match self.axis {
45 Axis::Vertical => element.v_flex(),
46 Axis::Horizontal => element.h_flex(),
47 })
48 .flex_none()
49 .gap(Spacing::Small.rems(cx))
50 .p(Spacing::XSmall.rems(cx))
51 .border_1()
52 .border_color(cx.theme().colors().border)
53 .rounded(rems_from_px(6.0))
54 .bg(cx.theme().colors().elevated_surface_background)
55 .children(self.tools)
56 }
57}