Skip to main content

liora_components/
button_group.rs

1use crate::Button;
2use gpui::{App, Component, IntoElement, RenderOnce, Window, div, prelude::*};
3
4pub struct ButtonGroup {
5    buttons: Vec<Button>,
6}
7
8impl ButtonGroup {
9    pub fn new() -> Self {
10        Self {
11            buttons: Vec::new(),
12        }
13    }
14
15    pub fn button(mut self, button: Button) -> Self {
16        self.buttons.push(button);
17        self
18    }
19}
20
21impl RenderOnce for ButtonGroup {
22    fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
23        // let theme = &cx.global::<liora_core::Config>().theme;
24        let count = self.buttons.len();
25
26        div()
27            .flex()
28            .flex_row()
29            .items_center()
30            .children(self.buttons.into_iter().enumerate().map(|(i, btn)| {
31                // Note: In GPUI 0.2.2, we don't have an easy way to override
32                // internal parts of Button from outside without adding more fields to Button.
33                // For now, we'll just render them side-by-side.
34                // Real ButtonGroup implementation would need Button to support custom corners.
35
36                // To keep it simple for now, we'll just use the flex row.
37                // In a future update, we can add .rounded_none(), .rounded_left(), etc. to Button.
38                if i > 0 && i < count {
39                    // btn = btn.margin_left(px(-1.0)); // overlap borders
40                }
41                btn
42            }))
43    }
44}
45
46impl IntoElement for ButtonGroup {
47    type Element = Component<Self>;
48    fn into_element(self) -> Self::Element {
49        Component::new(self)
50    }
51}