ccf_gpui_widgets/widgets/
tooltip.rs1use gpui::prelude::*;
20use gpui::*;
21
22use crate::theme::{get_theme_or, Theme};
23
24pub struct Tooltip {
26 text: SharedString,
27 custom_theme: Option<Theme>,
28}
29
30impl Tooltip {
31 pub fn new(text: impl Into<SharedString>) -> Self {
33 Self {
34 text: text.into(),
35 custom_theme: None,
36 }
37 }
38
39 #[must_use]
41 pub fn theme(mut self, theme: Theme) -> Self {
42 self.custom_theme = Some(theme);
43 self
44 }
45}
46
47impl Render for Tooltip {
48 fn render(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>) -> impl IntoElement {
49 let theme = get_theme_or(cx, self.custom_theme.as_ref());
50
51 div()
52 .px_2()
53 .py_1()
54 .bg(rgb(theme.tooltip_bg))
55 .border_1()
56 .border_color(rgb(theme.tooltip_border))
57 .rounded_md()
58 .shadow_md()
59 .text_sm()
60 .text_color(rgb(theme.tooltip_text))
61 .child(self.text.clone())
62 }
63}