Move more tooltip logic into gpui2 & fix tooltip moving on paint

Co-Authored-By: Conrad Irwin <conrad@zed.dev>
This commit is contained in:
Julia 2023-11-03 18:37:15 -04:00
parent 3834e26f71
commit 4725cd2cd6
6 changed files with 61 additions and 54 deletions

View file

@ -1,44 +1,16 @@
use std::time::Duration;
use gpui2::{
div, px, Component, Div, ParentElement, Render, SharedString, Styled, View, ViewContext,
VisualContext, WindowContext,
};
use gpui2::{div, px, Div, ParentElement, Render, SharedString, Styled, ViewContext};
use theme2::ActiveTheme;
const DELAY: Duration = Duration::from_millis(500);
#[derive(Clone, Debug)]
pub struct TextTooltip {
title: SharedString,
visible: bool,
}
impl TextTooltip {
pub fn new(str: SharedString) -> Self {
Self {
title: str,
visible: false,
}
}
pub fn build_view(str: SharedString, cx: &mut WindowContext) -> View<Self> {
let view = cx.build_view(|cx| TextTooltip::new(str));
let handle = view.downgrade();
cx.spawn(|mut cx| async move {
cx.background_executor().timer(DELAY).await;
handle
.update(&mut cx, |this, cx| {
this.visible = true;
cx.notify();
})
.ok();
})
.detach();
view
Self { title: str }
}
}
@ -48,7 +20,6 @@ impl Render for TextTooltip {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let theme = cx.theme();
div()
.when(!self.visible, |this| this.invisible())
.bg(theme.colors().background)
.rounded(px(8.))
.border()