Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScrollPane offsets widget by bar size #2777

Closed
dermetfan opened this issue Jan 28, 2015 · 2 comments
Closed

ScrollPane offsets widget by bar size #2777

dermetfan opened this issue Jan 28, 2015 · 2 comments
Labels
bug need more info needs more info. Likely to be closed when no reaction given.

Comments

@dermetfan
Copy link
Contributor

This bug was introduced in 1.5.3. Here's a comparision between 1.5.2 (left) and 1.5.3 (right):
scrollpane bug 1 5 3

The bar for scrolling on x is not currently visible but notice the widget is offset by its height in 1.5.3.

I believe this commit introduced the problem. Since this commit scrollbarHeight is only subtracted from areaHeight if scrolling on both axes is enabled which in my picture is not the case. Undoing the changes to ScrollPane in this commit should fix the issue.

@NathanSweet
Copy link
Member

Can you please edit scroll pane test to show the problem?

@badlogic badlogic added bug need more info needs more info. Likely to be closed when no reaction given. labels Feb 2, 2015
@dermetfan
Copy link
Contributor Author

I didn't get the ScrollPaneTest to show the issue without major changes so I provide my code as a separate test instead. Note you have to resize the window for the issue to actually show by making it thinner and thinner.

package com.badlogic.gdx.tests;

import com.badlogic.gdx.tests.utils.GdxTest;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.BaseDrawable;
import com.badlogic.gdx.utils.viewport.ExtendViewport;

public class ScrollPaneTest extends GdxTest implements Screen {

    private Stage stage;

    public ScrollPaneTest() {
        stage = new Stage(new ExtendViewport(320, 568, 568, 0));

        Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));

        Table table = new Table(skin);
        table.setFillParent(true);
        stage.addActor(table);

        // achievement list
        VerticalGroup achievements = new VerticalGroup();
        achievements.fill();
        for(int i = 0; i < 10; i++) {
            String name;
            switch(i) {
            case 0:
                name = "Warming Up: Played 5 times";
                break;
            case 1:
                name = "Committed: Played 10 minutes";
                break;
            case 2:
                name = "One Good Deed A Day: Donated $1 to charity!";
                break;
            default:
                name = "-";
            }

            Label label = new Label(String.valueOf(i + 1).concat(". ").concat(name), skin);
            Image medal = new Image(new BaseDrawable() {{
                setMinWidth(25);
                setMinHeight(25);
            }});

            Table inner = new Table();
            inner.add(label).expand().left();
            inner.add(medal);

            achievements.addActor(inner);
        }
        ScrollPane achievementsPane = new ScrollPane(achievements, skin);

        // GPGS button
        TextButton gpgs = new TextButton("GPGS", skin);

        // dare button
        TextButton dare = new TextButton("Dare!", skin);

        // build table
        table.add("Achievements").top().pad(10).colspan(2).row();
        table.add(achievementsPane).expand().fill().colspan(2).row();
        table.add(gpgs);
        table.add(dare);
    }

    @Override
    public void render () {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stage.act();
        stage.draw();
    }

    @Override
    public void resize (int width, int height) {
        stage.getViewport().update(width, height, true);
    }

    @Override
    public void dispose () {
        stage.dispose();
    }

    public boolean needsGL20 () {
        return false;
    }

    // if used as screen

    @Override
    public void show() {
        create();
    }

    @Override
    public void render(float delta) {
        render();
    }

    @Override
    public void hide() {}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug need more info needs more info. Likely to be closed when no reaction given.
Projects
None yet
Development

No branches or pull requests

3 participants