From what I understand a ScrollPane can have multiple widgets added to it by using a Table as the ScrollPane widget (this is how it is done in the ScrollPane tests within the libGDX repo).
I would like to achieve something similar but would like to have absolute positioning of many actors within the ScrollPane widget as opposed to tabular positioning which is provided by using a Table as the ScrollPane widget.
I ended up with this code which does not work, but according to the libGDX javadoc it should and I do not know why it is not working!
stage = getStage();
// Scroll pane outer container
Container<ScrollPane> container = new Container<ScrollPane>();
container.setSize(Game.getWidth(), Game.getHeight());
// Scroll pane inner container
WidgetGroup widgetGroup = new WidgetGroup();
widgetGroup.setFillParent(true);
widgetGroup.addActor(new Image(MAP_TEXTURE_ATLAS.findRegion("map")));
// Scroll pane
ScrollPane scrollPane = new ScrollPane(widgetGroup);
container.setActor(scrollPane);
stage.addActor(container);
Nothing is displayed on the screen at all;
It does however work with the below code (which is obviously not what I want as the ScrollPane widget is a Container which can have only have one actor)
// Scroll pane outer container
Container<ScrollPane> container = new Container<ScrollPane>();
container.setSize(Match3.getWidth(), Match3.getHeight());
// Scroll pane inner container
Container container2 = new Container();
container2.setBackground(new TextureRegionDrawable(MAP_TEXTURE_ATLAS.findRegion("map")));
// Scroll pane
ScrollPane scrollPane = new ScrollPane(container2);
container.setActor(scrollPane);
stage.addActor(container);
Is there a way to use WidgetGroup with ScrollPane, or any way of how I can achieve the functionality that I require.
Thanks
ALTERNATIVE IMPLEMENTATION OF ACCEPTED ANSWER
After reading the accepted answer I decided to create my own class, the implementation is below;
// Scroll pane outer container
Container<ScrollPane> container = new Container<ScrollPane>();
container.setSize(Match3.getWidth(), Match3.getHeight());
class ScrollWidget extends WidgetGroup {
private float prefHeight;
private float prefWidth;
public ScrollWidget(Image image) {
prefHeight = image.getHeight();
prefWidth = image.getWidth();
addActor(image);
}
@Override
public float getPrefHeight() {
return prefHeight;
}
@Override
public float getPrefWidth() {
return prefWidth;
}
}
ScrollWidget scrollWidget = new ScrollWidget(
new Image(MAP_TEXTURE_ATLAS.findRegion("map"))
);
// Scroll pane
ScrollPane scrollPane = new ScrollPane(scrollWidget);
scrollPane.setOverscroll(false, false);
scrollPane.layout();
scrollPane.updateVisualScroll();
scrollPane.setScrollY(scrollPane.getMaxY());
container.setActor(scrollPane);
stage.addActor(container);