Class Popup<T extends com.badlogic.gdx.scenes.scene2d.Actor>

java.lang.Object
net.dermetfan.gdx.scenes.scene2d.ui.Popup<T>
Type Parameters:
T - the type of popup
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
Flexible popup system for things like tooltips, context menus and menu bars.

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.

Examples:
  • 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
  • Constructor Details

  • Method Details

    • show

      public boolean show()
      See Also:
      show(Event)
    • show

      public boolean show​(com.badlogic.gdx.scenes.scene2d.Event event)
      Makes the popup visible and brings it to front. 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 the popup 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 interface com.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 child Popup
    • getPopup

      public T getPopup()
      Returns:
      the popup
    • setPopup

      public void setPopup​(T popup)
      Parameters:
      popup - the popup to set
    • getBehavior

      public Popup.Behavior getBehavior()
      Returns:
      the behavior
    • setBehavior

      public void setBehavior​(Popup.Behavior behavior)
      Parameters:
      behavior - the behavior to set