Struct Tooltip

Source
pub struct Tooltip {
    pub handle: ControlHandle,
}
Expand description

Tooltips appear automatically, or pop up, when the user pauses the mouse pointer over a tool or some other UI element. The tooltip appears near the pointer and disappears when the user clicks a mouse button, moves the pointer away from the tool, or simply waits for a few seconds.

A tooltip can be applied to multiple controls, each with their own custom text. This is done/undone using the register/unregister functions. So do not think as Tooltip as a standalone toolip, but more like a manager.

A tooltip can support static text using register and dynamic text using register_callback.

Tooltip requires the tooltip features

Example:

use native_windows_gui as nwg;

/// Building a tooltip and add tooltips at the same time
fn build_tooltip(tt: &mut nwg::Tooltip, btn1: &nwg::Button, btn2: &nwg::Button) {
    nwg::Tooltip::builder()
        .register(btn1, "A test button")
        .register_callback(btn2)
        .build(tt);
}

/// Adding/Updating a tooltip after the initial tooltip creation
fn add_tooltip(btn: &nwg::Button, tt: &nwg::Tooltip) {
    tt.register(btn, "This is a button!");
}

/// Dynamic tooltip callback setup
fn add_dynamic_tooltip(tt: &nwg::Tooltip, btn: &nwg::Button) {
    tt.register_callback(btn);
}


struct GuiStruct {
    // Skipping other members
    tt: nwg::Tooltip,
    button: nwg::Button
}

impl GuiStruct {
    /// The dynamic tooltip callback, triggered by the event loop
    fn events_callback(&self, evt: nwg::Event, evt_data: &nwg::EventData, handle: nwg::ControlHandle) {
        match evt {
            nwg::Event::OnTooltipText => {
                // Compare the handle to check which control will display the tooltip
                if &handle == &self.button {
                    let tooltip_data = evt_data.on_tooltip_text();
                    tooltip_data.set_text(&format!("Button text: \"{}\"", self.button.text()));
                }
            },
            _ => {}
        }
    }
}


Fields§

§handle: ControlHandle

Implementations§

Source§

impl Tooltip

Source

pub fn builder<'a>() -> TooltipBuilder<'a>

Source

pub fn text(&self, owner: &ControlHandle, buffer_size: Option<usize>) -> String

Return the current text of the tooltip. There is no way to know the size of the text so you have to pass the buffer size. The default buffer size is 200 characters.

Source

pub fn set_text<'a>(&self, owner: &ControlHandle, text: &'a str)

Change the text of a previously registered control Use the register function is associate a control with this tooltip

Source

pub fn set_decoration<'a>(&self, title: &'a str, ico: &Icon)

Set the icon and the title of a tooltip. This method use custom icon defined by user resources

Source

pub fn set_default_decoration<'a>(&self, title: &'a str, icon: TooltipIcon)

Set the icon and the title of a tooltip. This method use built-in icon defined by TooltipIcon

Source

pub fn hide(&self)

Hide the tooltip popup

Source

pub fn count(&self) -> usize

Return the number of controls registered by the tooltip

Source

pub fn set_delay_time(&self, delay: Option<u16>)

Set the delay time for the tooltip to spawn in milliseconds Set the value to None to reset the value to default

Source

pub fn delay_time(&self) -> u16

Return the delay time of the tooltip in milliseconds

Source

pub fn set_enabled(&self, v: bool)

Enable or disable the control Windows does not support reading the enabled state of a tooltip btw.

Source

pub fn register<'a, W: Into<ControlHandle>>(&self, owner: W, text: &'a str)

Register the tooltip under a control. owner must be a window control.

Source

pub fn register_callback<W: Into<ControlHandle>>(&self, owner: W)

Register the tooltip under a control. owner must be a window control. When the user trigger the tooltip, the application receives a OnTooltipText event

Source

pub fn unregister<W: Into<ControlHandle>>(&self, owner: W)

Remove the tooltip from a control

Source

pub fn class_name(&self) -> &'static str

Winapi class name used during control creation

Source

pub fn flags(&self) -> u32

Winapi base flags used during window creation

Source

pub fn forced_flags(&self) -> u32

Winapi flags required by the control

Trait Implementations§

Source§

impl Default for Tooltip

Source§

fn default() -> Tooltip

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

impl Drop for Tooltip

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<&Tooltip> for ControlHandle

Source§

fn from(control: &Tooltip) -> Self

Converts to this type from the input type.
Source§

impl From<&mut Tooltip> for ControlHandle

Source§

fn from(control: &mut Tooltip) -> Self

Converts to this type from the input type.
Source§

impl PartialEq<ControlHandle> for Tooltip

Source§

fn eq(&self, other: &ControlHandle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Tooltip> for ControlHandle

Source§

fn eq(&self, other: &Tooltip) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Tooltip

Source§

fn eq(&self, other: &Tooltip) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Tooltip

Source§

impl StructuralPartialEq for Tooltip

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.