BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / scheduled_toolbar.rs

scheduled_toolbar.rs

scheduled_toolbar.rs 2.1 KiB Download Raw
1use gpui_kit::assets::IconName;
2use gpui_kit::base::GlobalState;
3use gpui_kit::component::h_flex;
4use gpui_kit::*;
5
6use super::message_actions::{Action, HoverChange, bar_button};
7use super::widgets::icon;
8use crate::theme;
9
10pub struct ScheduledMenu {
11 pub key: String,
12 pub edit: Action,
13 pub send_now: Action,
14 pub delete: Action,
15 pub hover: HoverChange,
16}
17
18fn element_id(prefix: &str, key: &str) -> ElementId {
19 ElementId::Name(format!("{prefix}-{key}").into())
20}
21
22fn text_button(id: ElementId, label: &'static str) -> Stateful<Div> {
23 bar_button(id)
24 .w_auto()
25 .px(px(8.))
26 .text_size(px(12.5))
27 .text_color(theme::text_soft())
28 .child(label)
29}
30
31pub fn scheduled_toolbar(menu: ScheduledMenu) -> AnyElement {
32 let ScheduledMenu {
33 key,
34 edit,
35 send_now,
36 delete,
37 hover,
38 } = menu;
39 h_flex()
40 .id(element_id("scheduled-toolbar", &key))
41 .p(px(2.))
42 .gap(px(2.))
43 .items_center()
44 .rounded(px(8.))
45 .bg(theme::surface())
46 .border_1()
47 .border_color(theme::border_strong())
48 .occlude()
49 .on_hover(move |hovered, _, cx| hover(*hovered, cx))
50 .on_mouse_down(MouseButton::Left, |_, _, cx| {
51 GlobalState::suppress_text_selection(cx)
52 })
53 .child(
54 text_button(element_id("scheduled-edit", &key), "Edit").on_click(
55 move |_, window, cx| {
56 cx.stop_propagation();
57 edit(window, cx);
58 },
59 ),
60 )
61 .child(
62 text_button(element_id("scheduled-send-now", &key), "Send now").on_click(
63 move |_, window, cx| {
64 cx.stop_propagation();
65 send_now(window, cx);
66 },
67 ),
68 )
69 .child(
70 bar_button(element_id("scheduled-delete", &key))
71 .child(icon(IconName::Trash, 16., theme::red_soft()))
72 .on_click(move |_, window, cx| {
73 cx.stop_propagation();
74 delete(window, cx);
75 }),
76 )
77 .into_any_element()
78}