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 .h(px(36.))
42 .p(px(3.))
43 .gap(px(1.))
44 .items_center()
45 .rounded(px(10.))
46 .bg(theme::popup())
47 .occlude()
48 .on_hover(move |hovered, _, cx| hover(*hovered, cx))
49 .on_mouse_down(MouseButton::Left, |_, _, cx| {
50 GlobalState::suppress_text_selection(cx)
51 })
52 .child(
53 text_button(element_id("scheduled-edit", &key), "Edit").on_click(
54 move |_, window, cx| {
55 cx.stop_propagation();
56 edit(window, cx);
57 },
58 ),
59 )
60 .child(
61 text_button(element_id("scheduled-send-now", &key), "Send now").on_click(
62 move |_, window, cx| {
63 cx.stop_propagation();
64 send_now(window, cx);
65 },
66 ),
67 )
68 .child(
69 bar_button(element_id("scheduled-delete", &key))
70 .child(icon(IconName::Trash, 16., theme::red_soft()))
71 .on_click(move |_, window, cx| {
72 cx.stop_propagation();
73 delete(window, cx);
74 }),
75 )
76 .into_any_element()
77}