1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Tooltip widget
//!
//! A lightweight tooltip for displaying text messages.
//! Uses GPUI's native `.tooltip()` method for positioning.
//!
//! # Example
//!
//! ```ignore
//! use ccf_gpui_widgets::widgets::Tooltip;
//!
//! div()
//! .id("my_element")
//! .child("Hover me")
//! .tooltip(|_window, cx| {
//! cx.new(|_cx| Tooltip::new("This is a tooltip"))
//! })
//! ```
use gpui::prelude::*;
use gpui::*;
use crate::theme::{get_theme_or, Theme};
/// A simple tooltip view for displaying text messages
pub struct Tooltip {
text: SharedString,
custom_theme: Option<Theme>,
}
impl Tooltip {
/// Create a new tooltip with the given text
pub fn new(text: impl Into<SharedString>) -> Self {
Self {
text: text.into(),
custom_theme: None,
}
}
/// Set custom theme (builder pattern)
#[must_use]
pub fn theme(mut self, theme: Theme) -> Self {
self.custom_theme = Some(theme);
self
}
}
impl Render for Tooltip {
fn render(&mut self, _window: &mut Window, cx: &mut Context<'_, Self>) -> impl IntoElement {
let theme = get_theme_or(cx, self.custom_theme.as_ref());
div()
.px_2()
.py_1()
.bg(rgb(theme.tooltip_bg))
.border_1()
.border_color(rgb(theme.tooltip_border))
.rounded_md()
.shadow_md()
.text_sm()
.text_color(rgb(theme.tooltip_text))
.child(self.text.clone())
}
}