Skip to main content

Tooltip

Struct Tooltip 

Source
pub struct Tooltip<Msg> { /* private fields */ }
Expand description

Wraps widgets and shows a short text next to them after the pointer rests on them for the theme’s motion.hover-delay.

The text is one row on the overlay surface, below the widgets by default. It flips to the other side when there is no room, and moves to another side when it would cover the pointer. It disappears as soon as the pointer leaves. With on_focus it also shows, at once, while keyboard focus is inside. The text fades in over motion.enter.

Style keys: tooltip (bg, fg, padding).

use qframe::prelude::*;
use qframe::widgets::Tooltip;

struct Toolbar;

impl App for Toolbar {
    type Msg = ();
    fn update(&mut self, (): ()) -> Command<()> {
        Command::none()
    }
    fn view(&self, ui: &mut View<'_, ()>) {
        ui.add_with(Tooltip::new("Restart every container"), |ui| {
            ui.add(Button::new("Restart").on_press(()));
        });
    }
}

let mut app = Harness::new(Toolbar, 40, 4);
app.hover(3, 0).advance(std::time::Duration::from_secs(1));
assert!(app.screen().contains("Restart every container"));

Implementations§

Source§

impl<Msg: 'static> Tooltip<Msg>

Source

pub fn new(text: impl Into<String>) -> Self

A tooltip saying text. Add the widgets it explains with View::add_with.

Source

pub fn placement(self, placement: Placement) -> Self

The preferred side; Placement::Below by default.

Source

pub fn on_focus(self, on_focus: bool) -> Self

Also shows the tooltip while keyboard focus is inside the wrapped widgets.

Trait Implementations§

Source§

impl<Msg: 'static> Container<Msg> for Tooltip<Msg>

Source§

fn set_children(&mut self, children: Vec<Node<Msg>>)

Receives the children built for this widget.
Source§

impl<Msg: 'static> Widget<Msg> for Tooltip<Msg>

Source§

fn measure(&self, cx: &mut MeasureCx<'_>, available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn paint_overlay(&self, cx: &mut PaintCx<'_>, anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.
Source§

fn event(&self, _cx: &mut EventCx<'_, Msg>, _event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for Tooltip<Msg>

§

impl<Msg> !Send for Tooltip<Msg>

§

impl<Msg> !Sync for Tooltip<Msg>

§

impl<Msg> !UnwindSafe for Tooltip<Msg>

§

impl<Msg> Freeze for Tooltip<Msg>
where Vec<Node<Msg>>: Freeze,

§

impl<Msg> Unpin for Tooltip<Msg>
where Vec<Node<Msg>>: Unpin,

§

impl<Msg> UnsafeUnpin for Tooltip<Msg>
where Vec<Node<Msg>>: UnsafeUnpin,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.