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