1use gpui::{Div, Render};
2use theme2::ActiveTheme;
3
4use crate::prelude::*;
5use crate::{h_stack, v_stack, KeyBinding, Label, LabelSize, StyledExt, TextColor};
6
7pub struct TextTooltip {
8 title: SharedString,
9 meta: Option<SharedString>,
10 key_binding: Option<KeyBinding>,
11}
12
13impl TextTooltip {
14 pub fn new(title: impl Into<SharedString>) -> Self {
15 Self {
16 title: title.into(),
17 meta: None,
18 key_binding: None,
19 }
20 }
21
22 pub fn meta(mut self, meta: impl Into<SharedString>) -> Self {
23 self.meta = Some(meta.into());
24 self
25 }
26
27 pub fn key_binding(mut self, key_binding: impl Into<Option<KeyBinding>>) -> Self {
28 self.key_binding = key_binding.into();
29 self
30 }
31}
32
33impl Render for TextTooltip {
34 type Element = Div<Self>;
35
36 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
37 v_stack()
38 .elevation_2(cx)
39 .font("Zed Sans")
40 .text_ui_sm()
41 .text_color(cx.theme().colors().text)
42 .py_1()
43 .px_2()
44 .child(
45 h_stack()
46 .child(self.title.clone())
47 .when_some(self.key_binding.clone(), |this, key_binding| {
48 this.justify_between().child(key_binding)
49 }),
50 )
51 .when_some(self.meta.clone(), |this, meta| {
52 this.child(
53 Label::new(meta)
54 .size(LabelSize::Small)
55 .color(TextColor::Muted),
56 )
57 })
58 }
59}