Example usage for com.badlogic.gdx.scenes.scene2d.ui Table getPrefWidth

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Table getPrefWidth

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui Table getPrefWidth.

Prototype

public float getPrefWidth() 

Source Link

Usage

From source file:com.kotcrab.vis.ui.util.value.PrefWidthIfVisibleValue.java

License:Apache License

@Override
public float get(Actor actor) {
    if (actor instanceof Widget) {
        Widget widget = (Widget) actor;//from w w  w  . jav  a  2s . c  o  m
        return widget.isVisible() ? widget.getPrefWidth() : 0;
    }

    if (actor instanceof Table) {
        Table table = (Table) actor;
        return table.isVisible() ? table.getPrefWidth() : 0;
    }

    throw new IllegalStateException("Unsupported actor type for PrefWidthIfVisibleValue: " + actor.getClass());
}

From source file:com.vlaaad.dice.ui.windows.DiceWindow.java

License:Open Source License

@Override
protected void doShow(final UserData userData) {
    final Table items = new Table();
    final ScrollPane pane = new ScrollPane(items, new ScrollPane.ScrollPaneStyle()) {

        @Override//from   w ww  .j a  va  2s  . co m
        public void layout() {
            float w = items.getPrefWidth();
            float h = Math.min(getParent().getHeight(), items.getPrefHeight());
            if (w != getWidth() || h != getHeight()) {
                setSize(w, h);
                invalidateHierarchy();
            }
            super.layout();
        }
    };
    pane.setTouchable(Touchable.childrenOnly);
    pane.setOverscroll(false, false);
    pane.setCancelTouchFocus(false);
    pane.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            pane.layout();
            pane.layout();
            items.layout();
            if (actor instanceof Layout)
                ((Layout) actor).layout();
            pane.layout();
            pane.layout();
            pane.scrollTo(actor.getX(), actor.getY(), actor.getWidth(), actor.getHeight() + 100);
        }
    });

    Iterable<Die> dice = userData.dice();
    int i = 1;
    int count = userData.diceCount();
    for (Die die : dice) {
        DiePane diePane = new DiePane(die, userData, diceWindowGroup);
        table.add(diePane);
        diePane.setWidth(0);
        diePane.pack();
        diePane.setWidth(ViewController.CELL_SIZE * 6.6f);
        Cell cell = items.add(diePane).fillX().maxWidth(ViewController.CELL_SIZE * 6.6f);
        if (i != count) {
            cell.padBottom(-1);
        }
        cell.row();
        map.put(die, diePane);
        diePane.info.addListener(createMinimizeListener(die, dice));
        i++;
    }
    items.pack();
    table.add(pane).width(items.getPrefWidth());//.size(items.getPrefWidth(), 200);
}

From source file:com.vlaaad.dice.ui.windows.PotionsWindow.java

License:Open Source License

@Override
protected void initialize() {
    Table content = new Table(Config.skin);
    content.setBackground("ui-creature-info-background");
    content.setTouchable(Touchable.enabled);
    content.defaults().pad(2);//from  w w  w  .j  a  va 2  s  .  c o m
    Array<Ability> potions = new Array<Ability>();
    for (Ability ability : Config.abilities.byType(Ability.Type.potion)) {
        potions.add(ability);
    }
    potions.sort(Ability.COST_COMPARATOR);

    potionsList = new Table();
    Image selection = new Image(Config.skin.getDrawable("selection/turn"));
    potionsList.addActor(selection);

    potionName = new LocLabel("");
    potionDescription = new LocLabel("");
    potionDescription.setAlignment(Align.center | Align.top);
    potionDescription.setWrap(true);

    ingredientsTable = new Table(Config.skin);
    ingredientsTable.defaults().pad(2);

    Table viewRow = new Table();
    potionsList.add(viewRow).row();
    viewRow.defaults().pad(2);
    int i = 0;
    ActorGestureListener l = null;
    for (Ability ability : potions) {
        AbilityIconCounter icon = new AbilityIconCounter(ability, 0);
        icon.image.setOrigin(icon.image.getWidth() / 2, icon.image.getHeight() / 2);
        potionIcons.put(ability, icon);
        ActorGestureListener listener = createPotionTapListener(icon, ability, selection, potionsList,
                potionName, potionDescription, ingredientsTable);
        if (l == null) {
            l = listener;
        }
        iconListeners.put(ability, listener);
        icon.addListener(listener);
        i++;
        viewRow.add(icon);
        if (i % 5 == 0) {
            viewRow = new Table();
            viewRow.defaults().pad(2);
            potionsList.add(viewRow).row();
        }
    }

    craftingPane = new CraftingPane(3, potions);

    Table craftTable = new Table(Config.skin);
    craftTable.setBackground("ui-craft-content");
    craftTable.defaults().pad(4);
    craftTable.add(craftingPane).row();
    craftTable.add(ingredientsContainer).row();

    content.add(potionsList).row();
    content.add(new Tile("ui-creature-info-line")).size(80, 1).row();
    content.add(potionName).row();
    content.add(ingredientsTable).padTop(5).padBottom(1).row();
    content.add(potionDescription).size(130, 48).row();
    content.add(craftTable).expandX().fillX().pad(-2).row();

    Container contentContainer = new Container(content);
    contentContainer.width(content.getPrefWidth());
    scrollPane = new ScrollPane(contentContainer);
    scrollPane.setOverscroll(false, false);
    scrollPane.setCancelTouchFocus(false);
    table.add(scrollPane).width(contentContainer.getMaxWidth());

    if (l != null) {
        table.invalidate();
        table.validate();
        l.tap(null, 0, 0, 0, 0);
    }
}

From source file:com.vlaaad.dice.ui.windows.SelectAbilityWindow.java

License:Open Source License

@Override
protected void doShow(Params params) {
    this.params = params;
    Table content = new Table(Config.skin);
    content.defaults().pad(2);//w w w .  ja  v  a 2 s  . co  m
    content.setBackground("ui-inventory-ability-window-background");
    table.add(content);

    TextButton button = new LocTextButton("ui-select");

    Image itemSelection = new Image(Config.skin.getDrawable("ui-creature-info-ability-selection"));

    LocLabel itemDescriptionLabel = new LocLabel("ui-creature-info-window-ability-description",
            Thesaurus.params().with("name", params.abilities.first().locNameKey()).with("desc",
                    params.abilities.first().locDescKey()),
            DESCRIPTION);
    itemDescriptionLabel.setWrap(true);
    itemDescriptionLabel.setAlignment(Align.center);

    Label label = new LocLabel("ui-select-ability-for-" + params.ability.name,
            Thesaurus.params().with("die", params.creature.description.nameLocKey()));
    label.setWrap(true);
    label.setAlignment(Align.center);
    content.add(label).width(110).row();
    content.add(new Image(Config.skin, "ui-creature-info-line")).width(80).row();

    int i = 0;
    Table row = new Table();
    content.add(row).row();
    for (Ability ability : params.abilities) {
        Group group = new Group();
        AbilityIcon icon = new AbilityIcon(ability);
        group.addActor(icon);
        group.setSize(icon.getPrefWidth(), icon.getPrefHeight());
        row.add(group);
        ClickListener clickListener = createListener(ability, button, itemSelection, group,
                itemDescriptionLabel);
        icon.addListener(clickListener);
        if (i == 0) {
            clickListener.clicked(null, 0, 0);
        }
        if (i % 3 == 2 && i != params.abilities.size - 1) {
            row = new Table();
            content.add(row).row();
        }
        i++;
    }

    content.add(new Image(Config.skin, "ui-creature-info-line")).width(80).row();
    content.add(itemDescriptionLabel).width(ViewController.CELL_SIZE * 4 + 32).height(50).row();

    content.add(button).padTop(6).padBottom(6).width(70);
    button.setDisabled(true);
    button.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            hide();
        }
    });

    particles = new ParticleActor(Config.particles.get("ability-concentration").obtain());
    table.addActor(particles);
    table.layout();
    particles.toBack();
    particles.setPosition(content.getX() + content.getPrefWidth() / 2,
            content.getY() + content.getPrefHeight() / 2);
    for (ParticleEmitter emitter : particles.effect.getEmitters()) {
        emitter.getSpawnWidth().setHigh(content.getPrefWidth() + PARTICLE_OFFSET * 2);
        emitter.getSpawnHeight().setHigh(content.getPrefHeight() + PARTICLE_OFFSET * 2);
    }
}

From source file:com.vlaaad.dice.ui.windows.SelectCreatureToResurrectWindow.java

License:Open Source License

@Override
protected void doShow(SelectCreatureToResurrectWindow.Params params) {
    future = params.future;//www  .  ja  va 2 s .c  o  m
    selected = params.creatures.random();
    Table content = new Table(Config.skin);
    content.setBackground("ui-inventory-ability-window-background");
    content.defaults().pad(2);
    table.add(content);
    Label label = new LocLabel("ui-resurrect-header",
            Thesaurus.params().with("die", params.creature.description.nameLocKey()));
    label.setWrap(true);
    label.setAlignment(Align.center);
    content.add(label).width(110).row();
    content.add(new Image(Config.skin, "ui-creature-info-line")).width(50).row();

    Image selection = new Image(Config.skin.getDrawable("selection/turn"));
    selection.setY(-2);
    int i = 0;
    Table row = new Table();
    content.add(row).padTop(16).row();
    TextButton button = new LocTextButton("ui-select");
    for (Creature creature : params.creatures) {
        WorldObjectView view = ViewController.createView(params.creature.world.viewer,
                params.creature.world.playerColors, creature);
        row.add(view).padLeft(2).padRight(2);
        view.addListener(createListener(creature, button, view, selection));
        if (i % 4 == 3 && i != params.creatures.size - 1) {
            row = new Table();
            content.add(row).padTop(16).row();
        }
        i++;
    }
    content.add(button).padTop(6).padBottom(6).width(70);
    button.setDisabled(true);
    button.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            hide();
        }
    });

    particles = new ParticleActor(Config.particles.get("ability-concentration").obtain());
    table.addActor(particles);
    table.layout();
    particles.toBack();
    particles.setPosition(content.getX() + content.getPrefWidth() / 2,
            content.getY() + content.getPrefHeight() / 2);
    for (ParticleEmitter emitter : particles.effect.getEmitters()) {
        emitter.getSpawnWidth().setHigh(content.getPrefWidth() + PARTICLE_OFFSET * 2);
        emitter.getSpawnHeight().setHigh(content.getPrefHeight() + PARTICLE_OFFSET * 2);
    }
}

From source file:org.ams.testapps.paintandphysics.cardhouse.CardHouseWithGUI.java

License:Open Source License

/**
 * Show the gui, the stage is cleared first.
 *
 * @param onPause something to do when the men button is clicked. Probably show a menu.
 *///from  ww  w .  ja  v a 2 s.  c  o m
private void showGUI(final Runnable onPause) {
    if (debug)
        debug("Showing GUI.");

    stage.clear();

    // prepare menu button
    final TextButton menuButton = new TextButton("Menu", skin);
    menuButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            pauseGame(onPause);
        }
    });

    final Table mainMenuTable = new Table();
    mainMenuTable.add(menuButton).pad(SceneUtil.getPreferredPadding(stage));
    stage.addActor(mainMenuTable);

    // prepare angle buttons
    final Table angleButtonsTable = createAngleButtons();
    stage.addActor(angleButtonsTable);
    // prepare angle label
    stage.addActor(createAngleLabel());
    // prepare height of house label
    stage.addActor(createTopLabel());

    // sets position of buttons on resize
    guiResizeTask = new Runnable() {
        @Override
        public void run() {
            mainMenuTable.setPosition(mainMenuTable.getPrefWidth() * 0.5f,
                    stage.getHeight() - mainMenuTable.getPrefHeight() * 0.5f);

            angleButtonsTable.setPosition(stage.getWidth() - angleButtonsTable.getPrefWidth() * 0.5f,
                    stage.getHeight() - angleButtonsTable.getPrefHeight() * 0.5f);

        }
    };
    guiResizeTask.run();
}