Skip to content

Tooltips

intrigus edited this page Oct 19, 2015 · 15 revisions

Tooltips (source) are widgets that appear below other widgets after user hovers mouse pointer on that other widget. Showcase

Tooltip can be attached to any actor, only one tooltip can be attached to actor at the same time. By default tooltip appears bellow actor, however if there is not enough space bellow actor, tooltip will be displayed above it.

Tooltip constructors:

//creates tooltip with provided text
public Tooltip (Actor target, String text)

//creates tooltip with provided actor as tooltip content
public Tooltip (Actor target, Actor content)

Example, creating tooltip for VisLabel:

VisLabel labelWithTooltip = new VisLabel("label with tooltip");
new Tooltip(labelWithTooltip, "this label has a tooltip");

Detaching any tooltip from actor:

Tooltip.removeTooltip(someActor)

As you can see tooltips are not part of actor (i.e. method like actor.setTooltip(...) does not exist). Tooltips works by attaching listener to target actor, if you remove that listener from actor (for example by calling actor.clearListeners()) then you have to attach tooltip again by calling tooltip.attach(), you can also remove tooltip manually by calling tooltip.detach())

Tooltip target can be changed by calling tooltip.setTarget(Actor newTarget), this will automatically detach tooltip from old target and attach it to new target.

VisImageButton

VisImageButton has constructor that allows to add tooltip alongside with button icon, for example (code from showcase):

VisImageButton exploreButton = new VisImageButton(Assets.getIcon("folder-open"), "Explore");
VisImageButton settingsButton = new VisImageButton(Assets.getIcon("settings-view"), "Change view");
VisImageButton importButton = new VisImageButton(Assets.getIcon("import"), "Import");

(Assets class is part of VisEditor, getIcon(...) returns Drawable)