Skip to main content

HoverTracker

Struct HoverTracker 

Source
pub struct HoverTracker { /* private fields */ }
Expand description

Tracks hover state for widgets.

Used in conjunction with Tooltip to show tooltips after a delay when the mouse hovers over a widget.

§Examples

use minui::widgets::HoverTracker;
use std::time::{Duration, Instant};

let mut tracker = HoverTracker::new();

// On mouse move over widget:
if widget.contains_point(x, y) {
    tracker.start_hover();
}

// On mouse leave:
tracker.end_hover();

// Check if tooltip should be shown:
if let Some(tooltip) = tracker.should_show_tooltip(Duration::from_millis(500)) {
    tooltip.draw(window)?;
}

Implementations§

Source§

impl HoverTracker

Source

pub fn new() -> Self

Creates a new hover tracker.

Source

pub fn start_hover(&mut self)

Starts tracking hover state.

Call this when the mouse enters a widget’s bounds.

Source

pub fn end_hover(&mut self)

Ends hover state.

Call this when the mouse leaves a widget’s bounds.

Source

pub fn hover_duration(&self) -> Option<Duration>

Checks if hovering and returns elapsed time.

Returns:

  • Some(duration) if currently hovering (time since hover started)
  • None if not hovering
Source

pub fn is_hovering(&self) -> bool

Returns whether currently hovering.

Source

pub fn should_show_tooltip(&self, delay: Duration) -> bool

Checks if tooltip should be shown based on delay.

Returns true if hover duration exceeds specified delay.

This checks the current elapsed time since hover started, so it can be called each frame to detect when the delay period has passed.

Unlike should_show_tooltip_once(), this does NOT reset the hover state, so the tooltip will remain visible while hovering.

Source

pub fn should_hide_tooltip(&self) -> bool

Checks if tooltip should be hidden (user left widget).

Returns true if user is NOT hovering anymore.

Use this to hide the tooltip when the user moves away from the widget.

Source

pub fn has_delay_passed(&self, delay: Duration) -> bool

Checks if the tooltip delay has been reached (persistent check).

This is different from should_show_tooltip() in that it doesn’t require continuous rechecking - once the delay passes, it stays true until end_hover() is called.

Returns true if the tooltip delay period has elapsed.

Source

pub fn should_show_tooltip_once(&mut self, delay: Duration) -> bool

Checks if tooltip should be shown and resets the hover timer.

This is useful for showing a tooltip exactly once when the delay is reached. After calling this, the hover state is reset and the user must hover again to see the tooltip again.

Returns true if the tooltip should be shown now (delay just reached).

Trait Implementations§

Source§

impl Default for HoverTracker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.