Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Extend tooltip to take meta + kb
Nate Butler251b4640c6e4
diff --git a/crates/ui2/src/components/tooltip.rs b/crates/ui2/src/components/tooltip.rsindex ee3e9708c0a..0d4f10e35e9 100644--- a/crates/ui2/src/components/tooltip.rs+++ b/crates/ui2/src/components/tooltip.rs@@ -1,32 +1,57 @@-use gpui::{div, Div, ParentElement, Render, SharedString, Styled, ViewContext};+use gpui::{div, Component, Div, ParentElement, Render, SharedString, Styled, ViewContext};use theme2::ActiveTheme;-use crate::StyledExt;+use crate::{h_stack, v_stack, Label, LabelColor, StyledExt};++use super::keybinding;#[derive(Clone, Debug)]pub struct TextTooltip {title: SharedString,+ meta: Option<SharedString>,+ keybinding: Option<SharedString>,}impl TextTooltip {pub fn new(title: impl Into<SharedString>) -> Self {Self {title: title.into(),+ meta: None,+ keybinding: None,}}++ pub fn meta(mut self, meta: impl Into<SharedString>) -> Self {+ self.meta = Some(meta.into());+ self+ }++ pub fn keybinding(mut self, keybinding: impl Into<SharedString>) -> Self {+ self.keybinding = Some(keybinding.into());+ self+ }}impl Render for TextTooltip {type Element = Div<Self>;fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {- div()+ v_stack().elevation_2(cx).font("Zed Sans")- .text_ui()+ .text_ui_sm().text_color(cx.theme().colors().text).py_1().px_2()- .child(self.title.clone())+ .child(h_stack().child(self.title.clone()).when_some(+ self.keybinding.clone(),+ |this, keybinding| {+ this.justify_between()+ .child(Label::new(keybinding).color(LabelColor::Muted))+ },+ ))+ .when_some(self.meta.clone(), |this, meta| {+ this.child(Label::new(meta).color(LabelColor::Muted))+ })}}diff --git a/crates/workspace2/src/workspace2.rs b/crates/workspace2/src/workspace2.rsindex 575ab6b8bd3..eb7ef7608e8 100644--- a/crates/workspace2/src/workspace2.rs+++ b/crates/workspace2/src/workspace2.rs@@ -69,7 +69,7 @@ use std::{};use theme2::ActiveTheme;pub use toolbar::{ToolbarItemLocation, ToolbarItemView};-use ui::{h_stack, Button, ButtonVariant, Label, LabelColor};+use ui::{h_stack, Button, ButtonVariant, Label, LabelColor, TextTooltip};use util::ResultExt;use uuid::Uuid;use workspace_settings::{AutosaveSetting, WorkspaceSettings};@@ -2660,17 +2660,42 @@ impl Workspace {h_stack()// TODO - Add player menu.child(- Button::new("player")- .variant(ButtonVariant::Ghost)- .color(Some(LabelColor::Player(0))),+ div()+ .id("project_owner_indicator")+ .child(+ Button::new("player")+ .variant(ButtonVariant::Ghost)+ .color(Some(LabelColor::Player(0))),+ )+ .tooltip(move |_, cx| {+ cx.build_view(|cx| TextTooltip::new("Toggle following"))+ }),)// TODO - Add project menu- .child(Button::new("project_name").variant(ButtonVariant::Ghost))+ .child(+ div()+ .id("titlebar_project_menu_button")+ .child(Button::new("project_name").variant(ButtonVariant::Ghost))+ .tooltip(move |_, cx| {+ cx.build_view(|cx| TextTooltip::new("Recent Projects"))+ }),+ )// TODO - Add git menu.child(- Button::new("branch_name")- .variant(ButtonVariant::Ghost)- .color(Some(LabelColor::Muted)),+ div()+ .id("titlebar_git_menu_button")+ .child(+ Button::new("branch_name")+ .variant(ButtonVariant::Ghost)+ .color(Some(LabelColor::Muted)),+ )+ .tooltip(move |_, cx| {+ cx.build_view(|cx| {+ TextTooltip::new("Recent Branches")+ .keybinding("⌘B")+ .meta("Only local branches shown")+ })+ }),),) // self.titlebar_item.child(h_stack().child(Label::new("Right side titlebar item")))