com.badlogic.gdx.scenes.scene2d.ui.Table类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中com.badlogic.gdx.scenes.scene2d.ui.Table类的一些代码示例,展示了Table类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Table类的具体详情如下:
包路径:com.badlogic.gdx.scenes.scene2d.ui.Table
类名称:Table

Table介绍

[英]A group that sizes and positions children using table constraints. By default, #getTouchable() is Touchable#childrenOnly.

The preferred and minimum sizes are that of the children when laid out in columns and rows.
[中]使用表约束调整和定位子对象的组。默认情况下,#getTouchable()是可触摸的#childrenOnly。
首选尺寸和最小尺寸是按列和行排列时的儿童尺寸。

代码示例

代码示例来源:origin: libgdx/libgdx

root = new Table() {
  public void draw (Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);
Table table = new Table();
table.setTransform(true);
table.setPosition(100, 100);
table.setOrigin(0, 0);
table.setRotation(45);
table.setScaleY(2);
table.add(label);
table.add(new TextButton("Text Button", skin));
table.pack();
table.addListener(new ClickListener() {
  public void clicked (InputEvent event, float x, float y) {
    System.out.println("click!");
Table table2 = new Table();
table2.add(button);
table2.setTransform(true);
table2.setScaleX(1.5f);
table2.setOrigin(table2.getPrefWidth() / 2, table2.getPrefHeight() / 2);
root.debug();
root.setFillParent(true);
root.add(new Label("meow meow meow meow meow meow meow meow meow meow meow meow", skin)).colspan(3).expandX();
root.add(new TextButton("Text Button", skin));

代码示例来源:origin: libgdx/libgdx

/** Sets the padTop, padLeft, padBottom, and padRight around the table to the specified value. */
public Table pad (float pad) {
  pad(new Fixed(pad));
  return this;
}

代码示例来源:origin: libgdx/libgdx

/** @see #setBackground(Drawable) */
public Table background (Drawable background) {
  setBackground(background);
  return this;
}

代码示例来源:origin: libgdx/libgdx

public Actor hit (float x, float y, boolean touchable) {
  if (clip) {
    if (touchable && getTouchable() == Touchable.disabled) return null;
    if (x < 0 || x >= getWidth() || y < 0 || y >= getHeight()) return null;
  }
  return super.hit(x, y, touchable);
}

代码示例来源:origin: libgdx/libgdx

/** Called to draw the background, before clipping is applied (if enabled). Default implementation draws the background
 * drawable. */
protected void drawBackground (Batch batch, float parentAlpha, float x, float y) {
  if (background == null) return;
  Color color = getColor();
  batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
  background.draw(batch, x, y, getWidth(), getHeight());
}

代码示例来源:origin: libgdx/libgdx

public void draw (Batch batch, float parentAlpha) {
  validate();
  if (isTransform()) {
    applyTransform(batch, computeTransform());
    drawBackground(batch, parentAlpha, 0, 0);
    if (clip) {
      batch.flush();
      float padLeft = this.padLeft.get(this), padBottom = this.padBottom.get(this);
      if (clipBegin(padLeft, padBottom, getWidth() - padLeft - padRight.get(this),
        getHeight() - padBottom - padTop.get(this))) {
        drawChildren(batch, parentAlpha);
        batch.flush();
        clipEnd();
      }
    } else
      drawChildren(batch, parentAlpha);
    resetTransform(batch);
  } else {
    drawBackground(batch, parentAlpha, getX(), getY());
    super.draw(batch, parentAlpha);
  }
}

代码示例来源:origin: libgdx/libgdx

Gdx.input.setInputProcessor(stage);
Table container = new Table();
stage.addActor(container);
container.setFillParent(true);
container.pad(10).defaults().expandX().fillX().space(4);
scrollPane.setFlickScroll(false);
container.row().height(350);
container.add(scrollPane);
container.debugAll();

代码示例来源:origin: libgdx/libgdx

Table root = new Table();
stage.addActor(root);
root.setFillParent(true);
Table column1 = new Table(skin);
column1.add("WHITE", "default", Color.WHITE).row();
column1.add("LIGHT_GRAY", "default", Color.LIGHT_GRAY).row();
column1.add("GRAY", "default", Color.GRAY).row();
column1.add("DARK_GRAY", "default", Color.DARK_GRAY).row();
column1.add("BLUE", "default", Color.BLUE).row();
column1.add("NAVY", "default", Color.NAVY).row();
column1.add("ROYAL", "default", Color.ROYAL).row();
column1.add("SLATE", "default", Color.SLATE).row();
column1.add("SKY", "default", Color.SKY).row();
column1.add("CYAN", "default", Color.CYAN).row();
column1.add("TEAL", "default", Color.TEAL).row();
Table column2 = new Table(skin);
column2.add("GREEN", "default", Color.GREEN).row();
column2.add("CHARTREUSE", "default", Color.CHARTREUSE).row();
column2.add("LIME", "default", Color.LIME).row();
column2.add("FOREST", "default", Color.FOREST).row();
column2.add("OLIVE", "default", Color.OLIVE).row();
column2.add("YELLOW", "default", Color.YELLOW).row();
column2.add("GOLD", "default", Color.GOLD).row();
column2.add("GOLDENROD", "default", Color.GOLDENROD).row();
column2.add("ORANGE", "default", Color.ORANGE).row();

代码示例来源:origin: libgdx/libgdx

bottomLeft = new Table();
bottomLeft.setPosition(x, y);
bottomLeft.setSize(contWidth, contHeight);
stage.addActor(bottomLeft);
bottomRight = new Table();
bottomRight.setSize(contWidth, contHeight);
x = bottomLeft.getX() + bottomLeft.getWidth() + gap;
bottomRight.setPosition(x, y);
stage.addActor(bottomRight);
topLeft = new Table();
topLeft.setSize(contWidth, contHeight);
x = bottomLeft.getX();
y = bottomLeft.getY() + bottomLeft.getHeight() + gap;
topLeft.setPosition(x, y);
stage.addActor(topLeft);
topRight = new Table();
topRight.setSize(contWidth, contHeight);
x = bottomRight.getX();
y = topLeft.getY();
topRight.setPosition(x, y);
stage.addActor(topRight);
horizOnlyTop = new Table();
horizOnlyTop.setSize(contWidth, contHeight);
x = topRight.getX();
y = topRight.getY() + topRight.getHeight() + gap;

代码示例来源:origin: libgdx/libgdx

private void setupUI () {
  ui = new Stage(new ExtendViewport(640, 480));
  Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  skipCleanup = new CheckBox("Skip blend function clean-up", skin);
  skipCleanup.addListener(listener);
  logLabel = new Label("", skin.get(LabelStyle.class));
  clearEmitters = new TextButton("Clear screen", skin);
  clearEmitters.addListener(listener);
  scaleEffects = new TextButton("Scale existing effects", skin);
  scaleEffects.addListener(listener);
  Table table = new Table();
  table.setTransform(false);
  table.setFillParent(true);
  table.defaults().padTop(5).left();
  table.top().left().padLeft(5);
  table.add(skipCleanup).colspan(2).row();
  table.add(clearEmitters).spaceRight(10);
  table.add(scaleEffects).row();
  table.add(logLabel).colspan(2);
  ui.addActor(table);
}

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  batch = new SpriteBatch();
  skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  stage = new Stage();
  Gdx.input.setInputProcessor(stage);
  Table table = new Table();
  stage.addActor(table);
  table.setPosition(200, 65);
  Label label1 = new Label("This text is scaled 2x.", skin);
  label1.setFontScale(2);
  Label label2 = new Label(
    "This text is scaled. This text is scaled. This text is scaled. This text is scaled. This text is scaled. ", skin);
  label2.setWrap(true);
  label2.setFontScale(0.75f, 0.75f);
  table.debug();
  table.add(label1);
  table.row();
  table.add(label2).fill();
  table.pack();
}

代码示例来源:origin: libgdx/libgdx

longButton.debug();
Table root = new Table(skin);
root.setFillParent(true);
root.setBackground(skin.getDrawable("default-pane"));
root.defaults().space(6);
root.setTransform(true);
root.rotateBy(10);
root.setScale(1.3f, 1);
root.debug();
stage2.addActor(root);
root.add(shortButton).pad(5);
root.add(longButton).row();
root.add("Colspan").colspan(2).row();

代码示例来源:origin: libgdx/libgdx

skin = new Skin(Gdx.files.internal("data/uiskin.json"));
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
container = new Table();
ui.addActor(container);
container.debug();
Table table = new Table();
ScrollPane scroll = new ScrollPane(table);
container.add(scroll).expand().fill();
table.pad(10).defaults().expandX().space(4);
Arrays.sort(tests, new Comparator<Instancer>() {
  @Override
  table.row();
  TextButton button = new TextButton(instancer.instance().getClass().getName(), skin);
  button.addListener(new ClickListener() {
  table.add(button).expandX().fillX();
container.row();
container.add(new Label("Click on a test to start it, press ESC to close it.", new LabelStyle(font, Color.WHITE))).pad(5, 5,
  5, 5);

代码示例来源:origin: libgdx/libgdx

TextField addressText = new TextField("", skin);
Table table = new Table();
stage.addActor(table);
table.setSize(260, 195);
table.setPosition(190, 142);
table.debug();
table.add(button);
Table table2 = new Table();
stage.addActor(table2);
table2.setFillParent(true);
table2.bottom();
table2.add(button2);

代码示例来源:origin: libgdx/libgdx

Table root = new Table();
root.setFillParent(true);
root.debug().defaults().space(6).size(110);
stage.addActor(root);
root.add(new Container(label("center")));
root.add(new Container(label("top")).top());
root.add(new Container(label("right")).right());
root.add(new Container(label("bottom")).bottom());
root.add(new Container(label("left")).left());
root.row();
root.add(new Container(label("fill")).fill());
root.add(new Container(label("fillX")).fillX());
root.add(new Container(label("fillY")).fillY());
root.add(new Container(label("fill 75%")).fill(0.75f, 0.75f));
root.add(new Container(label("fill 75% br")).fill(0.75f, 0.75f).bottom().right());
root.row();
root.add(new Container(label("padTop 5\ntop")).padTop(5).top());
root.add(new Container(label("padBottom 5\nbottom")).padBottom(5).bottom());
root.add(new Container(label("padLeft 15")).padLeft(15));
root.add(new Container(label("pad 10 fill")).pad(10).fill());
root.add(new Container(label("pad 10 tl")).pad(10).top().left());
root.row();
root.add(new Container(label("bg")).background(logo));
root.add(new Container(label("bg height 50")).background(logo).height(50));
transformBG.setOrigin(55, 55);
transformBG.rotateBy(90);
root.add(transformBG);

代码示例来源:origin: libgdx/libgdx

public void create () {
  stage = new Stage();
  Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  label = new Label("", skin);
  Table root = new Table(skin);
  root.setFillParent(true);
  root.setBackground(skin.getDrawable("default-pane"));
  root.debug().defaults().space(6);
  root.add(new TextButton("Button 1", skin));
  root.add(new TextButton("Button 2", skin)).row();
  root.add("Press spacebar to change the viewport:").colspan(2).row();
  root.add(label).colspan(2);
  stage.addActor(root);
  viewports = getViewports(stage.getCamera());
  names = getViewportNames();
  stage.setViewport(viewports.first());
  label.setText(names.first());
  Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {
    public boolean keyDown (int keycode) {
      if (keycode == Input.Keys.SPACE) {
        int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size;
        label.setText(names.get(index));
        Viewport viewport = viewports.get(index);
        stage.setViewport(viewport);
        resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
      }
      return false;
    }
  }, stage));
}

代码示例来源:origin: libgdx/libgdx

private void setupUI () {
  Skin skin = assets.get(DEFAULT_SKIN);
  Table table = new Table();
  table.setFillParent(true);
  table.top().left().add(new Label("FPS ", skin)).left();
  table.add(fpsLabel = new Label("", skin)).left().expandX().row();
  ui.addActor(table);
}

代码示例来源:origin: libgdx/libgdx

public void create () {
  stage = new Stage();
  Gdx.input.setInputProcessor(stage);
  root = new Table();
  root.setFillParent(true);
  stage.addActor(root);
  skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  Table labels = new Table();
  root.add(new ScrollPane(labels, skin)).expand().fill();
  root.row();
  root.add(drawnLabel = new Label("", skin));
  for (int i = 0; i < count; i++) {
    labels.add(new Label("Label: " + i, skin) {
      public void draw (Batch batch, float parentAlpha) {
        super.draw(batch, parentAlpha);
        drawn++;
      }
    });
    labels.row();
  }
}

代码示例来源:origin: libgdx/libgdx

volume.setValue(1);
final Label volumeValue = new Label("1.0", skin);
Table table = new Table();
final Slider pan = new Slider(-1f, 1f, 0.1f, false, skin);
pan.setValue(0);
final Label panValue = new Label("0.0", skin);
table.setFillParent(true);
table.align(Align.center | Align.top);
table.columnDefaults(0).expandX().right().uniformX();
table.columnDefaults(2).expandX().left().uniformX();
table.add(play);
table.add(stop).left();
table.row();
table.add(new Label("Pitch", skin));
table.add(pitch);
table.add(pitchValue);
table.row();
table.add(new Label("Volume", skin));
table.add(volume);
table.add(volumeValue);
table.row();
table.add(new Label("Pan", skin));
table.add(pan);
table.add(panValue);
ui.addActor(table);

代码示例来源:origin: libgdx/libgdx

myLabel.setWrap(true);
Table t = new Table();
t.row();
t.add(myLabel);
t.layout();
scrollPane2.setFlickScroll(false);
Label minSizeLabel = new Label("minWidth cell", skin); // demos SplitPane respecting widget's minWidth
Table rightSideTable = new Table(skin);
rightSideTable.add(minSizeLabel).growX().row();
rightSideTable.add(scrollPane2).grow();
SplitPane splitPane = new SplitPane(scrollPane, rightSideTable, false, skin, "default-horizontal");
fpsLabel = new Label("fps:", skin);
  "This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip!",
  skin));
Table tooltipTable = new Table(skin);
tooltipTable.pad(10).background("default-round");
tooltipTable.add(new TextButton("Fancy tooltip!", skin));
imgButton.addListener(new Tooltip(tooltipTable));
window.getTitleTable().add(new TextButton("X", skin)).height(window.getPadTop());
window.setPosition(0, 0);
window.defaults().spaceBottom(10);

相关文章

微信公众号

最新文章

更多