Skip to content

Commit

Permalink
tooltip improvements (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmoulton authored Sep 30, 2024
1 parent 1c78ca3 commit 69ed0ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,17 @@ impl StylePropValue for Brush {
}
}
}
impl StylePropValue for Duration {
fn debug_view(&self) -> Option<Box<dyn View>> {
None
}

fn interpolate(&self, other: &Self, value: f64) -> Option<Self> {
self.as_secs_f64()
.interpolate(&other.as_secs_f64(), value)
.map(Duration::from_secs_f64)
}
}

pub trait StyleClass: Default + Copy + 'static {
fn key() -> StyleKey;
Expand Down
11 changes: 5 additions & 6 deletions src/views/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
style_class!(pub TooltipClass);
style_class!(pub TooltipContainerClass);

prop!(pub Delay: f64 {} = 0.6);
prop!(pub Delay: Duration {} = Duration::from_millis(600));

prop_extractor! {
TooltipStyle {
Expand Down Expand Up @@ -110,10 +110,9 @@ impl View for Tooltip {
Event::PointerMove(e) => {
if self.overlay.borrow().is_none() && cx.app_state.dragging.is_none() {
let id = self.id();
let token =
exec_after(Duration::from_secs_f64(self.style.delay()), move |token| {
id.update_state(token);
});
let token = exec_after(self.style.delay(), move |token| {
id.update_state(token);
});
self.hover = Some((e.pos, token));
}
}
Expand Down Expand Up @@ -146,7 +145,7 @@ pub trait TooltipExt {
fn tooltip<V: IntoView + 'static>(self, tip: impl Fn() -> V + 'static) -> Tooltip;
}

impl<T: View + 'static> TooltipExt for T {
impl<T: IntoView + 'static> TooltipExt for T {
fn tooltip<V: IntoView + 'static>(self, tip: impl Fn() -> V + 'static) -> Tooltip {
tooltip(self, tip)
}
Expand Down

0 comments on commit 69ed0ea

Please sign in to comment.