.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
use gpui::AppContext as _;
|
||||
use gpui::{
|
||||
AnyView, App, Context, Entity, IntoElement, ParentElement as _, Render, SharedString,
|
||||
Styled as _, Window, div, px,
|
||||
};
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
|
||||
/// A small text panel gpui shows next to a hovered element.
|
||||
pub struct Tooltip {
|
||||
text: SharedString,
|
||||
}
|
||||
|
||||
impl Tooltip {
|
||||
/// Creates the tooltip view.
|
||||
pub fn new<L>(text: L, cx: &mut App) -> Entity<Self>
|
||||
where
|
||||
L: Into<SharedString>,
|
||||
{
|
||||
cx.new(|_| Self { text: text.into() })
|
||||
}
|
||||
|
||||
/// The `.tooltip(...)` closure for a plain text tooltip.
|
||||
pub fn text<L>(text: L) -> impl Fn(&mut Window, &mut App) -> AnyView + 'static
|
||||
where
|
||||
L: Into<SharedString>,
|
||||
{
|
||||
let text = text.into();
|
||||
move |_, cx| Tooltip::new(text.clone(), cx).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for Tooltip {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let text_size = theme.sizes.small.text_size;
|
||||
|
||||
div()
|
||||
.px_2()
|
||||
.py_1()
|
||||
.max_w(px(360.))
|
||||
.bg(theme.colors.surface)
|
||||
.border_1()
|
||||
.border_color(theme.colors.border)
|
||||
.rounded(theme.radius.sm)
|
||||
.text_size(text_size)
|
||||
.text_color(theme.colors.surface_foreground)
|
||||
.child(self.text.clone())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user