public SelectBox(Object[] items, SelectBoxStyle style) {
    setStyle(style);
    setItems(items);
    setWidth(getPrefWidth());
    setHeight(getPrefHeight());

    addListener(
        clickListener =
            new ClickListener() {
              public boolean touchDown(
                  InputEvent event, float x, float y, int pointer, int button) {
                if (pointer == 0 && button != 0) return false;
                if (list != null && list.getParent() != null) {
                  hideList();
                  return true;
                }
                Stage stage = getStage();
                Vector2 stageCoords = Vector2.tmp;
                stage.screenToStageCoordinates(stageCoords.set(screenCoords.x, screenCoords.y));
                list = new SelectList(stageCoords.x, stageCoords.y);
                stage.addActor(list);
                return true;
              }
            });
  }
Esempio n. 2
0
 /**
  * If this key is pressed, {@link #result(Object)} is called with the specified object.
  *
  * @see Keys
  */
 public Dialog key(final int keycode, final Object object) {
   addListener(
       new InputListener() {
         public boolean keyDown(InputEvent event, int keycode2) {
           if (keycode == keycode2) {
             result(object);
             if (!cancelHide) hide();
             cancelHide = false;
           }
           return false;
         }
       });
   return this;
 }
Esempio n. 3
0
 protected void setStage(Stage stage) {
   if (stage == null) addListener(focusListener);
   else removeListener(focusListener);
   super.setStage(stage);
 }