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

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

本文整理了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

  1. root = new Table() {
  2. public void draw (Batch batch, float parentAlpha) {
  3. super.draw(batch, parentAlpha);
  4. Table table = new Table();
  5. table.setTransform(true);
  6. table.setPosition(100, 100);
  7. table.setOrigin(0, 0);
  8. table.setRotation(45);
  9. table.setScaleY(2);
  10. table.add(label);
  11. table.add(new TextButton("Text Button", skin));
  12. table.pack();
  13. table.addListener(new ClickListener() {
  14. public void clicked (InputEvent event, float x, float y) {
  15. System.out.println("click!");
  16. Table table2 = new Table();
  17. table2.add(button);
  18. table2.setTransform(true);
  19. table2.setScaleX(1.5f);
  20. table2.setOrigin(table2.getPrefWidth() / 2, table2.getPrefHeight() / 2);
  21. root.debug();
  22. root.setFillParent(true);
  23. root.add(new Label("meow meow meow meow meow meow meow meow meow meow meow meow", skin)).colspan(3).expandX();
  24. root.add(new TextButton("Text Button", skin));

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

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

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

  1. /** @see #setBackground(Drawable) */
  2. public Table background (Drawable background) {
  3. setBackground(background);
  4. return this;
  5. }

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

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

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

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

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

  1. public void draw (Batch batch, float parentAlpha) {
  2. validate();
  3. if (isTransform()) {
  4. applyTransform(batch, computeTransform());
  5. drawBackground(batch, parentAlpha, 0, 0);
  6. if (clip) {
  7. batch.flush();
  8. float padLeft = this.padLeft.get(this), padBottom = this.padBottom.get(this);
  9. if (clipBegin(padLeft, padBottom, getWidth() - padLeft - padRight.get(this),
  10. getHeight() - padBottom - padTop.get(this))) {
  11. drawChildren(batch, parentAlpha);
  12. batch.flush();
  13. clipEnd();
  14. }
  15. } else
  16. drawChildren(batch, parentAlpha);
  17. resetTransform(batch);
  18. } else {
  19. drawBackground(batch, parentAlpha, getX(), getY());
  20. super.draw(batch, parentAlpha);
  21. }
  22. }

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

  1. Gdx.input.setInputProcessor(stage);
  2. Table container = new Table();
  3. stage.addActor(container);
  4. container.setFillParent(true);
  5. container.pad(10).defaults().expandX().fillX().space(4);
  6. scrollPane.setFlickScroll(false);
  7. container.row().height(350);
  8. container.add(scrollPane);
  9. container.debugAll();

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

  1. Table root = new Table();
  2. stage.addActor(root);
  3. root.setFillParent(true);
  4. Table column1 = new Table(skin);
  5. column1.add("WHITE", "default", Color.WHITE).row();
  6. column1.add("LIGHT_GRAY", "default", Color.LIGHT_GRAY).row();
  7. column1.add("GRAY", "default", Color.GRAY).row();
  8. column1.add("DARK_GRAY", "default", Color.DARK_GRAY).row();
  9. column1.add("BLUE", "default", Color.BLUE).row();
  10. column1.add("NAVY", "default", Color.NAVY).row();
  11. column1.add("ROYAL", "default", Color.ROYAL).row();
  12. column1.add("SLATE", "default", Color.SLATE).row();
  13. column1.add("SKY", "default", Color.SKY).row();
  14. column1.add("CYAN", "default", Color.CYAN).row();
  15. column1.add("TEAL", "default", Color.TEAL).row();
  16. Table column2 = new Table(skin);
  17. column2.add("GREEN", "default", Color.GREEN).row();
  18. column2.add("CHARTREUSE", "default", Color.CHARTREUSE).row();
  19. column2.add("LIME", "default", Color.LIME).row();
  20. column2.add("FOREST", "default", Color.FOREST).row();
  21. column2.add("OLIVE", "default", Color.OLIVE).row();
  22. column2.add("YELLOW", "default", Color.YELLOW).row();
  23. column2.add("GOLD", "default", Color.GOLD).row();
  24. column2.add("GOLDENROD", "default", Color.GOLDENROD).row();
  25. column2.add("ORANGE", "default", Color.ORANGE).row();

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

  1. bottomLeft = new Table();
  2. bottomLeft.setPosition(x, y);
  3. bottomLeft.setSize(contWidth, contHeight);
  4. stage.addActor(bottomLeft);
  5. bottomRight = new Table();
  6. bottomRight.setSize(contWidth, contHeight);
  7. x = bottomLeft.getX() + bottomLeft.getWidth() + gap;
  8. bottomRight.setPosition(x, y);
  9. stage.addActor(bottomRight);
  10. topLeft = new Table();
  11. topLeft.setSize(contWidth, contHeight);
  12. x = bottomLeft.getX();
  13. y = bottomLeft.getY() + bottomLeft.getHeight() + gap;
  14. topLeft.setPosition(x, y);
  15. stage.addActor(topLeft);
  16. topRight = new Table();
  17. topRight.setSize(contWidth, contHeight);
  18. x = bottomRight.getX();
  19. y = topLeft.getY();
  20. topRight.setPosition(x, y);
  21. stage.addActor(topRight);
  22. horizOnlyTop = new Table();
  23. horizOnlyTop.setSize(contWidth, contHeight);
  24. x = topRight.getX();
  25. y = topRight.getY() + topRight.getHeight() + gap;

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

  1. private void setupUI () {
  2. ui = new Stage(new ExtendViewport(640, 480));
  3. Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  4. skipCleanup = new CheckBox("Skip blend function clean-up", skin);
  5. skipCleanup.addListener(listener);
  6. logLabel = new Label("", skin.get(LabelStyle.class));
  7. clearEmitters = new TextButton("Clear screen", skin);
  8. clearEmitters.addListener(listener);
  9. scaleEffects = new TextButton("Scale existing effects", skin);
  10. scaleEffects.addListener(listener);
  11. Table table = new Table();
  12. table.setTransform(false);
  13. table.setFillParent(true);
  14. table.defaults().padTop(5).left();
  15. table.top().left().padLeft(5);
  16. table.add(skipCleanup).colspan(2).row();
  17. table.add(clearEmitters).spaceRight(10);
  18. table.add(scaleEffects).row();
  19. table.add(logLabel).colspan(2);
  20. ui.addActor(table);
  21. }

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

  1. @Override
  2. public void create () {
  3. batch = new SpriteBatch();
  4. skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  5. stage = new Stage();
  6. Gdx.input.setInputProcessor(stage);
  7. Table table = new Table();
  8. stage.addActor(table);
  9. table.setPosition(200, 65);
  10. Label label1 = new Label("This text is scaled 2x.", skin);
  11. label1.setFontScale(2);
  12. Label label2 = new Label(
  13. "This text is scaled. This text is scaled. This text is scaled. This text is scaled. This text is scaled. ", skin);
  14. label2.setWrap(true);
  15. label2.setFontScale(0.75f, 0.75f);
  16. table.debug();
  17. table.add(label1);
  18. table.row();
  19. table.add(label2).fill();
  20. table.pack();
  21. }

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

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

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

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

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

  1. TextField addressText = new TextField("", skin);
  2. Table table = new Table();
  3. stage.addActor(table);
  4. table.setSize(260, 195);
  5. table.setPosition(190, 142);
  6. table.debug();
  7. table.add(button);
  8. Table table2 = new Table();
  9. stage.addActor(table2);
  10. table2.setFillParent(true);
  11. table2.bottom();
  12. table2.add(button2);

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

  1. Table root = new Table();
  2. root.setFillParent(true);
  3. root.debug().defaults().space(6).size(110);
  4. stage.addActor(root);
  5. root.add(new Container(label("center")));
  6. root.add(new Container(label("top")).top());
  7. root.add(new Container(label("right")).right());
  8. root.add(new Container(label("bottom")).bottom());
  9. root.add(new Container(label("left")).left());
  10. root.row();
  11. root.add(new Container(label("fill")).fill());
  12. root.add(new Container(label("fillX")).fillX());
  13. root.add(new Container(label("fillY")).fillY());
  14. root.add(new Container(label("fill 75%")).fill(0.75f, 0.75f));
  15. root.add(new Container(label("fill 75% br")).fill(0.75f, 0.75f).bottom().right());
  16. root.row();
  17. root.add(new Container(label("padTop 5\ntop")).padTop(5).top());
  18. root.add(new Container(label("padBottom 5\nbottom")).padBottom(5).bottom());
  19. root.add(new Container(label("padLeft 15")).padLeft(15));
  20. root.add(new Container(label("pad 10 fill")).pad(10).fill());
  21. root.add(new Container(label("pad 10 tl")).pad(10).top().left());
  22. root.row();
  23. root.add(new Container(label("bg")).background(logo));
  24. root.add(new Container(label("bg height 50")).background(logo).height(50));
  25. transformBG.setOrigin(55, 55);
  26. transformBG.rotateBy(90);
  27. root.add(transformBG);

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

  1. public void create () {
  2. stage = new Stage();
  3. Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  4. label = new Label("", skin);
  5. Table root = new Table(skin);
  6. root.setFillParent(true);
  7. root.setBackground(skin.getDrawable("default-pane"));
  8. root.debug().defaults().space(6);
  9. root.add(new TextButton("Button 1", skin));
  10. root.add(new TextButton("Button 2", skin)).row();
  11. root.add("Press spacebar to change the viewport:").colspan(2).row();
  12. root.add(label).colspan(2);
  13. stage.addActor(root);
  14. viewports = getViewports(stage.getCamera());
  15. names = getViewportNames();
  16. stage.setViewport(viewports.first());
  17. label.setText(names.first());
  18. Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {
  19. public boolean keyDown (int keycode) {
  20. if (keycode == Input.Keys.SPACE) {
  21. int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size;
  22. label.setText(names.get(index));
  23. Viewport viewport = viewports.get(index);
  24. stage.setViewport(viewport);
  25. resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  26. }
  27. return false;
  28. }
  29. }, stage));
  30. }

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

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

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

  1. public void create () {
  2. stage = new Stage();
  3. Gdx.input.setInputProcessor(stage);
  4. root = new Table();
  5. root.setFillParent(true);
  6. stage.addActor(root);
  7. skin = new Skin(Gdx.files.internal("data/uiskin.json"));
  8. Table labels = new Table();
  9. root.add(new ScrollPane(labels, skin)).expand().fill();
  10. root.row();
  11. root.add(drawnLabel = new Label("", skin));
  12. for (int i = 0; i < count; i++) {
  13. labels.add(new Label("Label: " + i, skin) {
  14. public void draw (Batch batch, float parentAlpha) {
  15. super.draw(batch, parentAlpha);
  16. drawn++;
  17. }
  18. });
  19. labels.row();
  20. }
  21. }

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

  1. volume.setValue(1);
  2. final Label volumeValue = new Label("1.0", skin);
  3. Table table = new Table();
  4. final Slider pan = new Slider(-1f, 1f, 0.1f, false, skin);
  5. pan.setValue(0);
  6. final Label panValue = new Label("0.0", skin);
  7. table.setFillParent(true);
  8. table.align(Align.center | Align.top);
  9. table.columnDefaults(0).expandX().right().uniformX();
  10. table.columnDefaults(2).expandX().left().uniformX();
  11. table.add(play);
  12. table.add(stop).left();
  13. table.row();
  14. table.add(new Label("Pitch", skin));
  15. table.add(pitch);
  16. table.add(pitchValue);
  17. table.row();
  18. table.add(new Label("Volume", skin));
  19. table.add(volume);
  20. table.add(volumeValue);
  21. table.row();
  22. table.add(new Label("Pan", skin));
  23. table.add(pan);
  24. table.add(panValue);
  25. ui.addActor(table);

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

  1. myLabel.setWrap(true);
  2. Table t = new Table();
  3. t.row();
  4. t.add(myLabel);
  5. t.layout();
  6. scrollPane2.setFlickScroll(false);
  7. Label minSizeLabel = new Label("minWidth cell", skin); // demos SplitPane respecting widget's minWidth
  8. Table rightSideTable = new Table(skin);
  9. rightSideTable.add(minSizeLabel).growX().row();
  10. rightSideTable.add(scrollPane2).grow();
  11. SplitPane splitPane = new SplitPane(scrollPane, rightSideTable, false, skin, "default-horizontal");
  12. fpsLabel = new Label("fps:", skin);
  13. "This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip!",
  14. skin));
  15. Table tooltipTable = new Table(skin);
  16. tooltipTable.pad(10).background("default-round");
  17. tooltipTable.add(new TextButton("Fancy tooltip!", skin));
  18. imgButton.addListener(new Tooltip(tooltipTable));
  19. window.getTitleTable().add(new TextButton("X", skin)).height(window.getPadTop());
  20. window.setPosition(0, 0);
  21. window.defaults().spaceBottom(10);

相关文章