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