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:
Componentfor update/view logicToggleablefor visibility control
§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
impl Tooltip
Sourcepub fn view_at(
state: &TooltipState,
frame: &mut Frame<'_>,
target: Rect,
bounds: Rect,
)
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 stateframe- The frame to render totarget- The target area to position relative tobounds- 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
impl Component for Tooltip
Source§type State = TooltipState
type State = TooltipState
The component’s internal state type. Read more
Source§type Message = TooltipMessage
type Message = TooltipMessage
Messages this component can receive. Read more
Source§type Output = TooltipOutput
type Output = TooltipOutput
Messages this component can emit to its parent. Read more
Source§fn update(state: &mut Self::State, msg: Self::Message) -> Option<Self::Output>
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,
)
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,
)
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§impl Toggleable for Tooltip
impl Toggleable for Tooltip
Source§fn is_visible(state: &Self::State) -> bool
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)
fn set_visible(state: &mut Self::State, visible: bool)
Sets the visibility of this component.
Auto Trait Implementations§
impl Freeze for Tooltip
impl RefUnwindSafe for Tooltip
impl Send for Tooltip
impl Sync for Tooltip
impl Unpin for Tooltip
impl UnsafeUnpin for Tooltip
impl UnwindSafe for Tooltip
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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