subject_field->create_tooltip("A brief title"); // ... INSERT_LIBX_NAMESPACE::w::label_config config; config.widthmm=30; text_field->create_tooltip("A brief message, a few lines long.", config);
inputfieldsandbuttons.C
gives an example of creating tooltips.
A tooltip is a small popup window that appears when the pointer
gets positioned on top of a widget and doesn't move for a
few seconds. The tooltip popup appears next to the pointer and goes
away automatically when the pointer moves again.
Tooltip text should be small. The tooltip gets positioned above and to the right of the pointer by default. If the pointer is near the edge of the screen the tooltip may get repositioned so that its entire contents are visible.
The first parameter to create_tooltip
()
is actually a
x::w::text_param
object.
This allows custom fonts and text colors for the tooltip. The
tooltip's background color is fixed by the current theme.
An optional second parameter specifies the tooltip's width in
millimeters. The tooltip's gext gets word-wrapped to fit within the
given width. The tooltip's text does not get word-wrapped otherwise,
but may contain '\n'
s to introduce explicit
line breaks.
x::functionref<void (THREAD_CALLBACK, const x::w::tooltip_factory &)> factory=x::w::create_label_tooltip("Push for help", x::w::label_config{}); // ... help_button_1->create_custom_tooltip(factory); help_button_2->create_custom_tooltip(factory);
A tooltip gets created only when necessary.
A widget's
create_tooltip
() is equivalent to calling the
widget's create_custom_tooltip
() with a
callback from
create_label_tooltip
().
Using create_label_tooltip
() and then installing
the resulting callback in multiple widgets is slightly more efficient,
by capturing the tooltip text and configuration only once, and sharing
them with the widgets.