1use gpui::{
2 point, App, Context, EventEmitter, IntoElement, PlatformDisplay, Size, Window,
3 WindowBackgroundAppearance, WindowBounds, WindowDecorations, WindowKind, WindowOptions,
4};
5use release_channel::ReleaseChannel;
6use std::rc::Rc;
7use theme;
8use ui::{prelude::*, Render};
9
10pub struct ToolReadyPopUp {
11 caption: SharedString,
12 icon: IconName,
13 icon_color: Color,
14}
15
16impl ToolReadyPopUp {
17 pub fn new(caption: impl Into<SharedString>, icon: IconName, icon_color: Color) -> Self {
18 Self {
19 caption: caption.into(),
20 icon,
21 icon_color,
22 }
23 }
24
25 pub fn window_options(screen: Rc<dyn PlatformDisplay>, cx: &App) -> WindowOptions {
26 let size = Size {
27 width: px(440.),
28 height: px(72.),
29 };
30
31 let notification_margin_width = px(16.);
32 let notification_margin_height = px(-48.);
33
34 let bounds = gpui::Bounds::<Pixels> {
35 origin: screen.bounds().top_right()
36 - point(
37 size.width + notification_margin_width,
38 notification_margin_height,
39 ),
40 size,
41 };
42
43 let app_id = ReleaseChannel::global(cx).app_id();
44
45 WindowOptions {
46 window_bounds: Some(WindowBounds::Windowed(bounds)),
47 titlebar: None,
48 focus: false,
49 show: true,
50 kind: WindowKind::PopUp,
51 is_movable: false,
52 display_id: Some(screen.id()),
53 window_background: WindowBackgroundAppearance::Transparent,
54 app_id: Some(app_id.to_owned()),
55 window_min_size: None,
56 window_decorations: Some(WindowDecorations::Client),
57 }
58 }
59}
60
61pub enum ToolReadyPopupEvent {
62 Accepted,
63 Dismissed,
64}
65
66impl EventEmitter<ToolReadyPopupEvent> for ToolReadyPopUp {}
67
68impl Render for ToolReadyPopUp {
69 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
70 let ui_font = theme::setup_ui_font(window, cx);
71 let line_height = window.line_height();
72
73 h_flex()
74 .size_full()
75 .p_3()
76 .gap_4()
77 .justify_between()
78 .elevation_3(cx)
79 .text_ui(cx)
80 .font(ui_font)
81 .border_color(cx.theme().colors().border)
82 .rounded_xl()
83 .child(
84 h_flex()
85 .items_start()
86 .gap_2()
87 .child(
88 h_flex().h(line_height).justify_center().child(
89 Icon::new(self.icon)
90 .color(self.icon_color)
91 .size(IconSize::Small),
92 ),
93 )
94 .child(
95 v_flex()
96 .child(Headline::new("Agent Panel").size(HeadlineSize::XSmall))
97 .child(Label::new(self.caption.clone()).color(Color::Muted)),
98 ),
99 )
100 .child(
101 h_flex()
102 .gap_0p5()
103 .child(
104 Button::new("open", "View Panel")
105 .style(ButtonStyle::Tinted(ui::TintColor::Accent))
106 .on_click({
107 cx.listener(move |_this, _event, _, cx| {
108 cx.emit(ToolReadyPopupEvent::Accepted);
109 })
110 }),
111 )
112 .child(Button::new("dismiss", "Dismiss").on_click({
113 cx.listener(move |_, _event, _, cx| {
114 cx.emit(ToolReadyPopupEvent::Dismissed);
115 })
116 })),
117 )
118 }
119}