mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-12 05:27:07 +00:00
Multi-element are now generic over any drawable child, which can be converted into an element. Co-Authored-By: Nathan Sobo <nathan@zed.dev> Co-Authored-By: Max Brunsfeld <max@zed.dev>
84 lines
2.5 KiB
Rust
84 lines
2.5 KiB
Rust
use gpui::{
|
|
elements::*,
|
|
platform::{CursorStyle, MouseButton},
|
|
Entity, View, ViewContext,
|
|
};
|
|
use settings::Settings;
|
|
use workspace::{item::ItemHandle, StatusItemView};
|
|
|
|
use crate::feedback_editor::{FeedbackEditor, GiveFeedback};
|
|
|
|
pub struct DeployFeedbackButton {
|
|
active: bool,
|
|
}
|
|
|
|
impl Entity for DeployFeedbackButton {
|
|
type Event = ();
|
|
}
|
|
|
|
impl DeployFeedbackButton {
|
|
pub fn new() -> Self {
|
|
DeployFeedbackButton { active: false }
|
|
}
|
|
}
|
|
|
|
impl View for DeployFeedbackButton {
|
|
fn ui_name() -> &'static str {
|
|
"DeployFeedbackButton"
|
|
}
|
|
|
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
|
|
let active = self.active;
|
|
let theme = cx.global::<Settings>().theme.clone();
|
|
Stack::new()
|
|
.with_child(
|
|
MouseEventHandler::<Self, Self>::new(0, cx, |state, _| {
|
|
let style = &theme
|
|
.workspace
|
|
.status_bar
|
|
.sidebar_buttons
|
|
.item
|
|
.style_for(state, active);
|
|
|
|
Svg::new("icons/feedback_16.svg")
|
|
.with_color(style.icon_color)
|
|
.constrained()
|
|
.with_width(style.icon_size)
|
|
.aligned()
|
|
.constrained()
|
|
.with_width(style.icon_size)
|
|
.with_height(style.icon_size)
|
|
.contained()
|
|
.with_style(style.container)
|
|
})
|
|
.with_cursor_style(CursorStyle::PointingHand)
|
|
.on_click(MouseButton::Left, move |_, _, cx| {
|
|
if !active {
|
|
cx.dispatch_action(GiveFeedback)
|
|
}
|
|
})
|
|
.with_tooltip::<Self>(
|
|
0,
|
|
"Send Feedback".into(),
|
|
Some(Box::new(GiveFeedback)),
|
|
theme.tooltip.clone(),
|
|
cx,
|
|
),
|
|
)
|
|
.into_element()
|
|
}
|
|
}
|
|
|
|
impl StatusItemView for DeployFeedbackButton {
|
|
fn set_active_pane_item(&mut self, item: Option<&dyn ItemHandle>, cx: &mut ViewContext<Self>) {
|
|
if let Some(item) = item {
|
|
if let Some(_) = item.downcast::<FeedbackEditor>() {
|
|
self.active = true;
|
|
cx.notify();
|
|
return;
|
|
}
|
|
}
|
|
self.active = false;
|
|
cx.notify();
|
|
}
|
|
}
|