Struct native_windows_gui::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
sourceimpl Tooltip
impl Tooltip
pub fn builder<'a>() -> TooltipBuilder<'a>
sourcepub fn text(&self, owner: &ControlHandle, buffer_size: Option<usize>) -> String
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.
sourcepub fn set_text<'a>(&self, owner: &ControlHandle, text: &'a str)
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
sourcepub fn set_decoration<'a>(&self, title: &'a str, ico: &Icon)
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
sourcepub fn set_default_decoration<'a>(&self, title: &'a str, icon: TooltipIcon)
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
sourcepub fn set_delay_time(&self, delay: Option<u16>)
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
sourcepub fn delay_time(&self) -> u16
pub fn delay_time(&self) -> u16
Return the delay time of the tooltip in milliseconds
sourcepub fn set_enabled(&self, v: bool)
pub fn set_enabled(&self, v: bool)
Enable or disable the control Windows does not support reading the enabled state of a tooltip btw.
sourcepub fn register<'a, W: Into<ControlHandle>>(&self, owner: W, text: &'a str)
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.
sourcepub fn register_callback<W: Into<ControlHandle>>(&self, owner: W)
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
sourcepub fn unregister<W: Into<ControlHandle>>(&self, owner: W)
pub fn unregister<W: Into<ControlHandle>>(&self, owner: W)
Remove the tooltip from a control
sourcepub fn class_name(&self) -> &'static str
pub fn class_name(&self) -> &'static str
Winapi class name used during control creation
sourcepub fn forced_flags(&self) -> u32
pub fn forced_flags(&self) -> u32
Winapi flags required by the control
Trait Implementations
sourceimpl From<&Tooltip> for ControlHandle
impl From<&Tooltip> for ControlHandle
sourceimpl From<&mut Tooltip> for ControlHandle
impl From<&mut Tooltip> for ControlHandle
sourceimpl PartialEq<ControlHandle> for Tooltip
impl PartialEq<ControlHandle> for Tooltip
sourcefn eq(&self, other: &ControlHandle) -> bool
fn eq(&self, other: &ControlHandle) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl PartialEq<Tooltip> for ControlHandle
impl PartialEq<Tooltip> for ControlHandle
sourceimpl PartialEq<Tooltip> for Tooltip
impl PartialEq<Tooltip> for Tooltip
impl Eq for Tooltip
impl StructuralEq for Tooltip
impl StructuralPartialEq for Tooltip
Auto Trait Implementations
impl RefUnwindSafe for Tooltip
impl !Send for Tooltip
impl !Sync for Tooltip
impl Unpin for Tooltip
impl UnwindSafe for Tooltip
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more