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 classPopup.AddToStageBehavioradds the popup to theEvent's StageinPopup.AddToStageBehavior.show(Event, Popup)if it is on no or another Stagestatic interfacePopup.Behaviorwhat to do in the Popup methodsstatic classPopup.BehaviorMultiplexera Multiplexer for Behaviorsstatic classPopup.FadeBehaviorfades in/out inPopup.FadeBehavior.show(Event, Popup)/Popup.FadeBehavior.hide(Event, Popup)usingAlphaActionsstatic classPopup.MenuBehaviorThe behavior of a menu such as a menu bar or context menu.static classPopup.PositionBehaviorsets the position of the popup inPopup.PositionBehavior.show(Event, Popup)static classPopup.Reactionstatic classPopup.TooltipBehaviorThe Behavior of a classic tooltip.static classPopup.VisibilityBehaviorshows 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.BehaviorgetBehavior()TgetPopup()booleanhandle(com.badlogic.gdx.scenes.scene2d.Event event)booleanhide()booleanhide(com.badlogic.gdx.scenes.scene2d.Event event)Makes thepopupinvisible.booleanisAscendantOf(com.badlogic.gdx.scenes.scene2d.Actor child)voidsetBehavior(Popup.Behavior behavior)voidsetPopup(T popup)booleanshow()booleanshow(com.badlogic.gdx.scenes.scene2d.Event event)Makes thepopupvisibleand 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- thepopupbehavior- thebehavior
-
Popup
- Parameters:
behaviors- the Behaviors to create aPopup.BehaviorMultiplexerfor- 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 thepopupvisibleand 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 thepopupinvisible. Override this for custom behavior.- Returns:
- if the event is handled
-
handle
public boolean handle(com.badlogic.gdx.scenes.scene2d.Event event)- Specified by:
handlein 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
popupof this or a childPopup
-
getPopup
- Returns:
- the
popup
-
setPopup
- Parameters:
popup- thepopupto set
-
getBehavior
- Returns:
- the
behavior
-
setBehavior
- Parameters:
behavior- thebehaviorto set
-