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