deploy_feedback_button.rs

 1use gpui::{elements::*, CursorStyle, Entity, MouseButton, RenderContext, View, ViewContext};
 2use settings::Settings;
 3use workspace::{item::ItemHandle, StatusItemView};
 4
 5use crate::feedback_editor::{FeedbackEditor, GiveFeedback};
 6
 7pub struct DeployFeedbackButton {
 8    active: bool,
 9}
10
11impl Entity for DeployFeedbackButton {
12    type Event = ();
13}
14
15impl DeployFeedbackButton {
16    pub fn new() -> Self {
17        DeployFeedbackButton { active: false }
18    }
19}
20
21impl View for DeployFeedbackButton {
22    fn ui_name() -> &'static str {
23        "DeployFeedbackButton"
24    }
25
26    fn render(&mut self, cx: &mut RenderContext<'_, Self>) -> ElementBox {
27        let active = self.active;
28        Stack::new()
29            .with_child(
30                MouseEventHandler::<Self>::new(0, cx, |state, cx| {
31                    let theme = &cx.global::<Settings>().theme;
32                    let style = &theme
33                        .workspace
34                        .status_bar
35                        .sidebar_buttons
36                        .item
37                        .style_for(state, active);
38
39                    Svg::new("icons/speech_bubble_12.svg")
40                        .with_color(style.icon_color)
41                        .constrained()
42                        .with_width(style.icon_size)
43                        .aligned()
44                        .constrained()
45                        .with_width(style.icon_size)
46                        .with_height(style.icon_size)
47                        .contained()
48                        .with_style(style.container)
49                        .boxed()
50                })
51                .with_cursor_style(CursorStyle::PointingHand)
52                .on_click(MouseButton::Left, move |_, cx| {
53                    if !active {
54                        cx.dispatch_action(GiveFeedback)
55                    }
56                })
57                .boxed(),
58            )
59            .boxed()
60    }
61}
62
63impl StatusItemView for DeployFeedbackButton {
64    fn set_active_pane_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
65        if let Some(item) = item {
66            if let Some(_) = item.downcast::<FeedbackEditor>() {
67                self.active = true;
68                cx.notify();
69                return;
70            }
71        }
72        self.active = false;
73        cx.notify();
74    }
75}