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
impl HoverTracker
Sourcepub fn start_hover(&mut self)
pub fn start_hover(&mut self)
Starts tracking hover state.
Call this when the mouse enters a widget’s bounds.
Sourcepub fn end_hover(&mut self)
pub fn end_hover(&mut self)
Ends hover state.
Call this when the mouse leaves a widget’s bounds.
Sourcepub fn hover_duration(&self) -> Option<Duration>
pub fn hover_duration(&self) -> Option<Duration>
Checks if hovering and returns elapsed time.
Returns:
Some(duration)if currently hovering (time since hover started)Noneif not hovering
Sourcepub fn is_hovering(&self) -> bool
pub fn is_hovering(&self) -> bool
Returns whether currently hovering.
Sourcepub fn should_show_tooltip(&self, delay: Duration) -> bool
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.
Sourcepub fn should_hide_tooltip(&self) -> bool
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.
Sourcepub fn has_delay_passed(&self, delay: Duration) -> bool
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.
Sourcepub fn should_show_tooltip_once(&mut self, delay: Duration) -> bool
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).