Skip to main content

Tooltip

Struct Tooltip 

Source
pub struct Tooltip;
Expand description

A tooltip component for displaying contextual information.

Tooltip displays a positioned overlay with helpful text relative to a target area. It implements:

§Positioning

The tooltip can be positioned Above, Below, Left, or Right of its target. When there isn’t enough space for the preferred position, it automatically falls back to the opposite side.

§Auto-hide

When configured with a duration, the tooltip automatically hides after the specified time. Send periodic Tick(elapsed_ms) messages to drive this functionality.

§Visual Format

Target area [████████]

         ┌─────────────────┐
         │ Helpful tooltip │  ← Tooltip (Below)
         │ text here       │
         └─────────────────┘

§Example

use envision::component::{Tooltip, TooltipMessage, TooltipOutput, TooltipState, Component, Toggleable};

let mut state = TooltipState::new("Click to submit")
    .with_duration(3000);

// Show the tooltip
let output = Tooltip::update(&mut state, TooltipMessage::Show);
assert_eq!(output, Some(TooltipOutput::Shown));

// Tick until it expires
let output = Tooltip::update(&mut state, TooltipMessage::Tick(3000));
assert_eq!(output, Some(TooltipOutput::Expired));
assert!(!state.is_visible());

Implementations§

Source§

impl Tooltip

Source

pub fn view_at( state: &TooltipState, frame: &mut Frame<'_>, target: Rect, bounds: Rect, )

Renders the tooltip relative to a target area within bounds.

This is the primary rendering method. Call this instead of view() when you need to position the tooltip relative to a specific target.

§Arguments
  • state - The tooltip state
  • frame - The frame to render to
  • target - The target area to position relative to
  • bounds - The bounding area (typically frame.area())
§Example
use envision::component::{Tooltip, TooltipState, Toggleable};
use ratatui::prelude::*;

let mut state = TooltipState::new("Button help text");
Tooltip::show(&mut state);
assert!(Tooltip::is_visible(&state));

Trait Implementations§

Source§

impl Component for Tooltip

Source§

type State = TooltipState

The component’s internal state type. Read more
Source§

type Message = TooltipMessage

Messages this component can receive. Read more
Source§

type Output = TooltipOutput

Messages this component can emit to its parent. Read more
Source§

fn init() -> Self::State

Initialize the component state. Read more
Source§

fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>

Update component state based on a message. Read more
Source§

fn view( state: &Self::State, frame: &mut Frame<'_>, area: Rect, _theme: &Theme, _ctx: &ViewContext, )

Render the component to the given area. Read more
Source§

fn traced_view( state: &Self::State, frame: &mut Frame<'_>, area: Rect, theme: &Theme, ctx: &ViewContext, )

Renders the component with optional tracing instrumentation. Read more
Source§

fn handle_event(state: &Self::State, event: &Event) -> Option<Self::Message>

Maps an input event to a component message. Read more
Source§

fn dispatch_event( state: &mut Self::State, event: &Event, ) -> Option<Self::Output>

Dispatches an event by mapping it to a message and updating state. Read more
Source§

impl Toggleable for Tooltip

Source§

fn is_visible(state: &Self::State) -> bool

Returns true if this component is currently visible.
Source§

fn set_visible(state: &mut Self::State, visible: bool)

Sets the visibility of this component.
Source§

fn toggle(state: &mut Self::State)

Toggles the visibility of this component.
Source§

fn show(state: &mut Self::State)

Shows this component. Read more
Source§

fn hide(state: &mut Self::State)

Hides this component. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> StateExt for T

Source§

fn updated(self, cmd: Command<impl Clone>) -> UpdateResult<Self, impl Clone>

Updates self and returns a command.
Source§

fn unchanged(self) -> UpdateResult<Self, ()>

Returns self with no command.
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.