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