Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upVerticalGroup does not let ScrollPane to scroll #3501
Comments
|
Please include a link to the documentation you're referring to. |
|
Ow you mean the wiki. I guess the phrase "but is more lightweight" is not descriptive enough. I'm not native English, so not sure how to better rephrase that. But please update the wiki as you think it better fits. |
|
There is bug in the VerticalGroup code, the wiki is correct. Please try to reproduce the problem it is pretty easy to do so. |
|
Perhaps I don't understand the issue you're reporting. Make sure to include the required information to reproduce the issue. See https://github.com/libgdx/libgdx/wiki/Getting-Help#executable-example-code |
import com.badlogic.gdx.*;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.utils.viewport.*;
public class DesktopLauncher extends ApplicationAdapter {
Stage stage;
public void create () {
stage = new Stage(new ScreenViewport());
Gdx.input.setInputProcessor(stage);
Skin skin = new Skin(Gdx.files.internal("uiskin.json"));
VerticalGroup listOfLabels =new VerticalGroup();
for (int i = 0; i < 60; i++) {
listOfLabels.addActor(new Label(i+" Some Label", skin));
}
ScrollPane scrollPane=new ScrollPane(listOfLabels);
Container container= new Container(scrollPane);
scrollPane.setHeight(50); // it does not matter what I put here, but I think VerticalGroup should use this value
container.setHeight(50); // it does not matter what I put here, but I think VerticalGroup should use this value
//---- following does NOT let even the scroll to work ( no scrolling possible in vertical direction )
VerticalGroup mainVG=new VerticalGroup();
mainVG.setFillParent(true);
mainVG.addActor(container);
stage.addActor(mainVG);
}
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw();
}
public void resize (int width, int height) {
// Pass false to not modify the camera position.
stage.getViewport().update(width, height, true);
}
public static void main (String[] args) throws Exception {
new LwjglApplication(new DesktopLauncher());
}
} |
|
Never mind that. I wasn't reading correctly. Sorry. Thanks for the sscce! |
|
VerticalGroup uses getPrefHeight on its children when doing its layout. In this case, it is the fact that the ScrollPane's prefHeight is the prefHeight of its child actor even if you explicitly set the height of the ScrollPane. The Container getPrefHeight also uses getPrefHeight on its child actor, which results in the VerticalGroup laying out as if it was simply including listOfLabels. Not sure what the actual correct solution is here... I don't think this problem is unique to VerticalGroup. |
|
Quoting from API docs "Scrollbars appear when the widget is larger than the scroll pane." But there is no way to it, given what you said. I think that I should be able to set ScrollPane to be smaller and to set whatever size I want to it, so that the scroll bars starts working according to the space I have for it on UI. What are my other alternative, I just have made all my screens to extend VerticalGroup, now in one of the screens I need some label then area of scrolling (which I can control its hight) then another label after it. |
|
It works correctly. Container sets the size of its children, so set the height of the ScrollPane using Container, not using setHeight.
|
From documentation: "A VerticalGroup (code) is equivalent to a Table with only a single column, but is more lightweight." But this is not the case, hence, I have created this issue.
Very easy to reproduce:
I have tried scrollPane.setHeight() , it did not work the VG does not allow it's child to set own hight. I have tried to wrap the scrollPane with Container, did not have effect.
Now the same exact code but replace the VG with Table, then the scrolling starts to work:
This means that VG != Table(with single column)
The whole code is here :
http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=20885&p=86539