public ScrollPaneStyle getStyle () {
return style;
}
public void layout () {
final NinePatch bg = style.background;
final NinePatch hScrollKnob = style.hScrollKnob;
final NinePatch vScrollKnob = style.vScrollKnob;
// For no background, ex. background is drawn a parent who has two scroll area
float bgLeftWidth = bg == null ? 0 : bg.getLeftWidth();
float bgRightWidth = bg == null ? 0 : bg.getRightWidth();
float bgTopHeight = bg == null ? 0 : bg.getTopHeight();
float bgBottomHeight = bg == null ? 0 : bg.getTopHeight();
// Get available space size by subtracting background's padded area.
areaWidth = width - bgLeftWidth - bgRightWidth;
areaHeight = height - bgTopHeight - bgBottomHeight;
if (widget == null) return;
// Get widget's desired width.
float widgetWidth, widgetHeight;
if (widget instanceof Layout) {
Layout layout = (Layout)widget;
widgetWidth = layout.getPrefWidth();
widgetHeight = layout.getPrefHeight();
} else {
widgetWidth = widget.width;
widgetHeight = widget.height;
}
// Figure out if we need horizontal/vertical scrollbars.
scrollX = false;
scrollY = false;
if (!disableX && widgetWidth > areaWidth) scrollX = true;
if (!disableY && widgetHeight > areaHeight) scrollY = true;
// Check again, now taking into account the area that's taken up by any enabled scrollbars.
if (!disableX && scrollY && widgetWidth > areaWidth - vScrollKnob.getTotalWidth()) {
scrollX = true;
areaWidth -= vScrollKnob.getTotalWidth();
}
if (!disableY && scrollX && widgetHeight > areaHeight - hScrollKnob.getTotalHeight()) {
scrollY = true;
areaHeight -= hScrollKnob.getTotalHeight();
}
// Set the widget area bounds.
widgetAreaBounds.set(bgLeftWidth, bgBottomHeight + (scrollX ? hScrollKnob.getTotalHeight() : 0), areaWidth, areaHeight);
amountX = MathUtils.clamp(amountX, 0, widgetAreaBounds.x);
amountY = MathUtils.clamp(amountY, 0, widgetAreaBounds.y);
// If the widget is smaller than the available space, make it take up the available space.
widgetWidth = disableX ? width : Math.max(areaWidth, widgetWidth);
widgetHeight = disableY ? height : Math.max(areaHeight, widgetHeight);
if (widget.width != widgetWidth || widget.height != widgetHeight) {
widget.width = widgetWidth;
widget.height = widgetHeight;
}
// Set the bounds and scroll knob sizes if scrollbars are needed.
if (scrollX) {
hScrollBounds.set(bgLeftWidth, bgBottomHeight, areaWidth, hScrollKnob.getTotalHeight());
hKnobBounds.width = Math.max(hScrollKnob.getTotalWidth(), (int)(hScrollBounds.width * areaWidth / widget.width));
hKnobBounds.height = hScrollKnob.getTotalHeight();
hKnobBounds.x = hScrollBounds.x + (int)((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX());
hKnobBounds.y = hScrollBounds.y;
}
if (scrollY) {
vScrollBounds.set(width - bgRightWidth - vScrollKnob.getTotalWidth(), height - bgTopHeight - areaHeight,
vScrollKnob.getTotalWidth(), areaHeight);
vKnobBounds.width = vScrollKnob.getTotalWidth();
vKnobBounds.height = Math.max(vScrollKnob.getTotalHeight(), (int)(vScrollBounds.height * areaHeight / widget.height));
vKnobBounds.x = vScrollBounds.x;
vKnobBounds.y = vScrollBounds.y + (int)((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY()));
}
if (widget instanceof Layout) {