Ejemplo n.º 1
0
  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;
              }
            });
  }
Ejemplo n.º 2
0
    private void layout() {
      final BitmapFont font = style.font;
      final Drawable listSelection = style.listSelection;
      final Drawable listBackground = style.listBackground;

      itemHeight = font.getCapHeight() + -font.getDescent() * 2 + style.itemSpacing;
      itemHeight += listSelection.getTopHeight() + listSelection.getBottomHeight();

      textOffsetX = listSelection.getLeftWidth() + style.itemSpacing;
      textOffsetY = listSelection.getTopHeight() + -font.getDescent() + style.itemSpacing / 2;

      setWidth(SelectBox.this.getWidth());
      setHeight(
          items.length * itemHeight
              + listBackground.getTopHeight()
              + listBackground.getBottomHeight());
    }