Class Popup<T extends com.badlogic.gdx.scenes.scene2d.Actor>
- Type Parameters:
T
- the type ofpopup
- All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.EventListener
public class Popup<T extends com.badlogic.gdx.scenes.scene2d.Actor>
extends java.lang.Object
implements com.badlogic.gdx.scenes.scene2d.EventListener
Popup is an EventListener with a popup Actor that can be shown
and hidden
and is controlled via its Behavior
.
Behavior is an interface for actual show and hide implementations which are triggered by the Reaction
returned by its handle
method.
Usually a Behavior overrides either show
and hide
or handle
so that its purpose is clearly distinct from other Behaviors.
Those distinct Behaviors are then combined using a BehaviorMultiplexer
. You can of course override all methods in your own implementation though.
Have a look at the VisibilityBehavior
and FadeBehavior
for examples of Behaviors that only override show and hide.
The PositionBehavior
just positions the popup in show. The actual position is applied by its Position
which can be combined using PositionMultiplexers
.
-
Menu bar menu:
new Popup<>(menu, new MenuBehavior(), new PositionBehavior(new AlignPosition(Align.bottomLeft, Align.topLeft)), new VisibilityBehavior())
-
Context menu:
new Popup<>(contextMenu, new MenuBehavior(Buttons.RIGHT), new PositionBehavior(new AlignPosition(Align.topRight, Align.topLeft)), new VisibilityBehavior())
The only differences between this and the previous example are the button passed to the MenuBehavior and the first parameter of the AlignPosition constructor. -
Tooltip:
new Popup<>(tooltip, new TooltipBehavior(), new PositionBehavior(new PointerPosition(), new AlignedOffsetPosition(Align.topLeft)), new VisibilityBehavior())
Some Behaviors (like the Popup.MenuBehavior
and Popup.TooltipBehavior
) can only function properly if they receive events of Actors other than their listener Actor
(for example to hide when other Actors are clicked).
Those Behaviors usually state so in their documentation. Add the Popups using such Behaviors to an EventMultiplexer
high in the hierarchy or directly on the stage.
A Behavior can distinguish between an Event on its listener Actor by checking if it has its Popup added as listener.
Be warned that in return Behaviors not designed for this may not function properly if you forward events from other Actors to them.
- Since:
- 0.9.0
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Popup.AddToStageBehavior
adds the popup to theEvent's Stage
inPopup.AddToStageBehavior.show(Event, Popup)
if it is on no or another Stagestatic interface
Popup.Behavior
what to do in the Popup methodsstatic class
Popup.BehaviorMultiplexer
a Multiplexer for Behaviorsstatic class
Popup.FadeBehavior
fades in/out inPopup.FadeBehavior.show(Event, Popup)
/Popup.FadeBehavior.hide(Event, Popup)
usingAlphaActions
static class
Popup.MenuBehavior
The behavior of a menu such as a menu bar or context menu.static class
Popup.PositionBehavior
sets the position of the popup inPopup.PositionBehavior.show(Event, Popup)
static class
Popup.Reaction
static class
Popup.TooltipBehavior
The Behavior of a classic tooltip.static class
Popup.VisibilityBehavior
shows and hides the popup by settings its visibility -
Constructor Summary
Constructors Constructor Description Popup(T popup, Popup.Behavior behavior)
Popup(T popup, Popup.Behavior... behaviors)
-
Method Summary
Modifier and Type Method Description Popup.Behavior
getBehavior()
T
getPopup()
boolean
handle(com.badlogic.gdx.scenes.scene2d.Event event)
boolean
hide()
boolean
hide(com.badlogic.gdx.scenes.scene2d.Event event)
Makes thepopup
invisible
.boolean
isAscendantOf(com.badlogic.gdx.scenes.scene2d.Actor child)
void
setBehavior(Popup.Behavior behavior)
void
setPopup(T popup)
boolean
show()
boolean
show(com.badlogic.gdx.scenes.scene2d.Event event)
Makes thepopup
visible
and brings it tofront
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Popup
- Parameters:
popup
- thepopup
behavior
- thebehavior
-
Popup
- Parameters:
behaviors
- the Behaviors to create aPopup.BehaviorMultiplexer
for- See Also:
Popup(Actor, Behavior)
-
-
Method Details
-
show
public boolean show()- See Also:
show(Event)
-
show
public boolean show(com.badlogic.gdx.scenes.scene2d.Event event)Makes thepopup
visible
and brings it tofront
. Override this for custom behaviour.- Returns:
- if the event is handled
-
hide
public boolean hide()- See Also:
hide(Event)
-
hide
public boolean hide(com.badlogic.gdx.scenes.scene2d.Event event)Makes thepopup
invisible
. Override this for custom behavior.- Returns:
- if the event is handled
-
handle
public boolean handle(com.badlogic.gdx.scenes.scene2d.Event event)- Specified by:
handle
in interfacecom.badlogic.gdx.scenes.scene2d.EventListener
- See Also:
Popup.Behavior.handle(Event, Popup)
-
isAscendantOf
public boolean isAscendantOf(com.badlogic.gdx.scenes.scene2d.Actor child)- Parameters:
child
- the possible popup child- Returns:
- whether the given Actor is the
popup
of this or a childPopup
-
getPopup
- Returns:
- the
popup
-
setPopup
- Parameters:
popup
- thepopup
to set
-
getBehavior
- Returns:
- the
behavior
-
setBehavior
- Parameters:
behavior
- thebehavior
to set
-