Extend tooltip to take meta + kb
This commit is contained in:
parent
5ae96e4eb6
commit
251b4640c6
2 changed files with 63 additions and 13 deletions
|
@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue