Example usage for com.badlogic.gdx.scenes.scene2d.utils Drawable getMinHeight

List of usage examples for com.badlogic.gdx.scenes.scene2d.utils Drawable getMinHeight

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.utils Drawable getMinHeight.

Prototype

public float getMinHeight();

Source Link

Usage

From source file:CB_UI_Base.GL_UI.utils.EmptyDrawable.java

License:Apache License

/** Creates a new empty drawable with the same sizing information as the specified drawable. */
public EmptyDrawable(Drawable drawable) {
    leftWidth = drawable.getLeftWidth();
    rightWidth = drawable.getRightWidth();
    topHeight = drawable.getTopHeight();
    bottomHeight = drawable.getBottomHeight();
    minWidth = drawable.getMinWidth();/*from w w w.  jav a  2s.  c  om*/
    minHeight = drawable.getMinHeight();
}

From source file:com.agateau.ui.menu.TabMenuItem.java

License:Apache License

private void drawFrameBorder(Batch batch, Drawable drawable, float x, float width) {
    drawable.draw(batch, x, getY(), width, drawable.getMinHeight());
}

From source file:com.anstrat.gui.SnapScrollPane.java

License:Apache License

public void layout() {
    final Drawable bg = style.background;
    final Drawable hScrollKnob = style.hScrollKnob;
    final Drawable vScrollKnob = style.vScrollKnob;

    float bgLeftWidth = 0, bgRightWidth = 0, bgTopHeight = 0, bgBottomHeight = 0;
    if (bg != null) {
        bgLeftWidth = bg.getLeftWidth();
        bgRightWidth = bg.getRightWidth();
        bgTopHeight = bg.getTopHeight();
        bgBottomHeight = bg.getBottomHeight();
    }//from w  w w. j a  va 2  s.  c om

    float width = getWidth();
    float height = getHeight();

    float scrollbarHeight = 0;
    if (hScrollKnob != null)
        scrollbarHeight = hScrollKnob.getMinHeight();
    if (style.hScroll != null)
        scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight());
    float scrollbarWidth = 0;
    if (vScrollKnob != null)
        scrollbarWidth = vScrollKnob.getMinWidth();
    if (style.vScroll != null)
        scrollbarWidth = Math.max(scrollbarWidth, style.vScroll.getMinWidth());

    // 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.getWidth();
        widgetHeight = widget.getHeight();
    }

    // Determine if horizontal/vertical scrollbars are needed.
    scrollX = forceOverscrollX || (widgetWidth > areaWidth && !disableX);
    scrollY = forceOverscrollY || (widgetHeight > areaHeight && !disableY);

    boolean fade = fadeScrollBars;
    if (!fade) {
        // Check again, now taking into account the area that's taken up by any enabled scrollbars.
        if (scrollY) {
            areaWidth -= scrollbarWidth;
            if (!scrollX && widgetWidth > areaWidth && !disableX) {
                scrollX = true;
            }
        }
        if (scrollX) {
            areaHeight -= scrollbarHeight;
            if (!scrollY && widgetHeight > areaHeight && !disableY) {
                scrollY = true;
                areaWidth -= scrollbarWidth;
            }
        }
    }

    // Set the widget area bounds.
    widgetAreaBounds.set(bgLeftWidth, bgBottomHeight, areaWidth, areaHeight);

    if (fade) {
        // Make sure widget is drawn under fading scrollbars.
        if (scrollX)
            areaHeight -= scrollbarHeight;
        if (scrollY)
            areaWidth -= scrollbarWidth;
    } else {
        if (scrollbarsOnTop) {
            // Make sure widget is drawn under non-fading scrollbars.
            if (scrollX)
                widgetAreaBounds.height += scrollbarHeight;
            if (scrollY)
                widgetAreaBounds.width += scrollbarWidth;
        } else {
            // Offset widget area y for horizontal scrollbar.
            if (scrollX)
                widgetAreaBounds.y += scrollbarHeight;
        }
    }

    // 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);

    maxX = widgetWidth - areaWidth;
    maxY = widgetHeight - areaHeight;
    if (fade) {
        // Make sure widget is drawn under fading scrollbars.
        if (scrollX)
            maxY -= scrollbarHeight;
        if (scrollY)
            maxX -= scrollbarWidth;
    }
    amountX = MathUtils.clamp(amountX, 0, maxX);
    amountY = MathUtils.clamp(amountY, 0, maxY);

    // Set the bounds and scroll knob sizes if scrollbars are needed.
    if (scrollX) {
        if (hScrollKnob != null) {
            float hScrollHeight = style.hScroll != null ? style.hScroll.getMinHeight()
                    : hScrollKnob.getMinHeight();
            hScrollBounds.set(bgLeftWidth, bgBottomHeight, areaWidth, hScrollHeight);
            hKnobBounds.width = Math.max(hScrollKnob.getMinWidth(),
                    (int) (hScrollBounds.width * areaWidth / widget.getWidth()));
            hKnobBounds.height = hScrollKnob.getMinHeight();
            hKnobBounds.x = hScrollBounds.x
                    + (int) ((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX());
            hKnobBounds.y = hScrollBounds.y;
        } else {
            hScrollBounds.set(0, 0, 0, 0);
            hKnobBounds.set(0, 0, 0, 0);
        }
    }
    if (scrollY) {
        if (vScrollKnob != null) {
            float vScrollWidth = style.vScroll != null ? style.vScroll.getMinWidth()
                    : vScrollKnob.getMinWidth();
            vScrollBounds.set(width - bgRightWidth - vScrollWidth, height - bgTopHeight - areaHeight,
                    vScrollWidth, areaHeight);
            vKnobBounds.width = vScrollKnob.getMinWidth();
            vKnobBounds.height = Math.max(vScrollKnob.getMinHeight(),
                    (int) (vScrollBounds.height * areaHeight / widgetHeight));
            vKnobBounds.x = width - bgRightWidth - vScrollKnob.getMinWidth();
            vKnobBounds.y = vScrollBounds.y
                    + (int) ((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY()));
        } else {
            vScrollBounds.set(0, 0, 0, 0);
            vKnobBounds.set(0, 0, 0, 0);
        }
    }

    if (widget.getWidth() != widgetWidth || widget.getHeight() != widgetHeight) {
        widget.setWidth(widgetWidth);
        widget.setHeight(widgetHeight);
        if (widget instanceof Layout) {
            Layout layout = (Layout) widget;
            layout.invalidate();
            layout.validate();
        }
    } else {
        if (widget instanceof Layout)
            ((Layout) widget).validate();
    }
}

From source file:com.apptogo.roperace.custom.MyTouchpad.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();/*from  www . jav  a 2 s.  c  o m*/

    Color c = getColor();
    batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);

    float x = getX();
    float y = getY();
    float w = getWidth();
    float h = getHeight();

    final Drawable bg = style.background;
    if (bg != null)
        bg.draw(batch, x, y, w, h);

    final Drawable knob = style.knob;
    if (knob != null) {
        x += knobPosition.x - knob.getMinWidth() / 2f;
        y += knobPosition.y - knob.getMinHeight() / 2f;
        knob.draw(batch, x, y, knob.getMinWidth(), knob.getMinHeight());
    }
}

From source file:com.kotcrab.vis.ui.widget.MultiSplitPane.java

License:Apache License

private void initialize() {
    addListener(new SplitPaneCursorManager(this, vertical) {
        @Override/*w  ww  .  j a v a  2s. com*/
        protected boolean handleBoundsContains(float x, float y) {
            return getHandleContaining(x, y) != null;
        }

        @Override
        protected boolean contains(float x, float y) {
            for (Rectangle bound : widgetBounds) {
                if (bound.contains(x, y))
                    return true;
            }
            return getHandleContaining(x, y) != null;
        }
    });

    addListener(new InputListener() {
        int draggingPointer = -1;

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (isTouchable() == false)
                return false;

            if (draggingPointer != -1)
                return false;
            if (pointer == 0 && button != 0)
                return false;
            Rectangle containingHandle = getHandleContaining(x, y);
            if (containingHandle != null) {
                handleOverIndex = handleBounds.indexOf(containingHandle, true);
                FocusManager.resetFocus(getStage());

                draggingPointer = pointer;
                lastPoint.set(x, y);
                handlePosition.set(containingHandle.x, containingHandle.y);
                return true;
            }
            return false;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if (pointer == draggingPointer)
                draggingPointer = -1;
            handleOver = getHandleContaining(x, y);
        }

        @Override
        public boolean mouseMoved(InputEvent event, float x, float y) {
            handleOver = getHandleContaining(x, y);
            return false;
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            if (pointer != draggingPointer)
                return;

            Drawable handle = style.handle;
            if (!vertical) {
                float delta = x - lastPoint.x;
                float availWidth = getWidth() - handle.getMinWidth();
                float dragX = handlePosition.x + delta;
                handlePosition.x = dragX;
                dragX = Math.max(0, dragX);
                dragX = Math.min(availWidth, dragX);
                float targetSplit = dragX / availWidth;
                setSplit(handleOverIndex, targetSplit);
                lastPoint.set(x, y);
            } else {
                float delta = y - lastPoint.y;
                float availHeight = getHeight() - handle.getMinHeight();
                float dragY = handlePosition.y + delta;
                handlePosition.y = dragY;
                dragY = Math.max(0, dragY);
                dragY = Math.min(availHeight, dragY);
                float targetSplit = 1 - (dragY / availHeight);
                setSplit(handleOverIndex, targetSplit);
                lastPoint.set(x, y);
            }
            invalidate();
        }
    });
}

From source file:com.kotcrab.vis.ui.widget.VisSplitPane.java

License:Apache License

private void initialize() {
    addListener(new SplitPaneCursorManager(this, vertical) {
        @Override//from w ww.  ja v  a2 s  . com
        protected boolean handleBoundsContains(float x, float y) {
            return handleBounds.contains(x, y);
        }

        @Override
        protected boolean contains(float x, float y) {
            return firstWidgetBounds.contains(x, y) || secondWidgetBounds.contains(x, y)
                    || handleBounds.contains(x, y);
        }
    });

    addListener(new InputListener() {
        int draggingPointer = -1;

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            //TODO potential bug with libgdx scene2d?
            //fixes issue when split bar could be still dragged even when touchable is set to childrenOnly, probably scene2d issue
            if (isTouchable() == false)
                return false;

            if (draggingPointer != -1)
                return false;
            if (pointer == 0 && button != 0)
                return false;
            if (handleBounds.contains(x, y)) {
                FocusManager.resetFocus(getStage());

                draggingPointer = pointer;
                lastPoint.set(x, y);
                handlePosition.set(handleBounds.x, handleBounds.y);
                return true;
            }
            return false;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if (pointer == draggingPointer)
                draggingPointer = -1;
        }

        @Override
        public boolean mouseMoved(InputEvent event, float x, float y) {
            mouseOnHandle = handleBounds.contains(x, y);
            return false;
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            if (pointer != draggingPointer)
                return;

            Drawable handle = style.handle;
            if (!vertical) {
                float delta = x - lastPoint.x;
                float availWidth = getWidth() - handle.getMinWidth();
                float dragX = handlePosition.x + delta;
                handlePosition.x = dragX;
                dragX = Math.max(0, dragX);
                dragX = Math.min(availWidth, dragX);
                splitAmount = dragX / availWidth;
                if (splitAmount < minAmount)
                    splitAmount = minAmount;
                if (splitAmount > maxAmount)
                    splitAmount = maxAmount;
                lastPoint.set(x, y);
            } else {
                float delta = y - lastPoint.y;
                float availHeight = getHeight() - handle.getMinHeight();
                float dragY = handlePosition.y + delta;
                handlePosition.y = dragY;
                dragY = Math.max(0, dragY);
                dragY = Math.min(availHeight, dragY);
                splitAmount = 1 - (dragY / availHeight);
                if (splitAmount < minAmount)
                    splitAmount = minAmount;
                if (splitAmount > maxAmount)
                    splitAmount = maxAmount;
                lastPoint.set(x, y);
            }
            invalidate();
        }
    });
}

From source file:com.kotcrab.vis.ui.widget.VisSplitPane.java

License:Apache License

private void calculateVertBoundsAndPositions() {
    Drawable handle = style.handle;

    float width = getWidth();
    float height = getHeight();

    float availHeight = height - handle.getMinHeight();
    float topAreaHeight = (int) (availHeight * splitAmount);
    float bottomAreaHeight = availHeight - topAreaHeight;
    float handleHeight = handle.getMinHeight();

    firstWidgetBounds.set(0, height - topAreaHeight, width, topAreaHeight);
    secondWidgetBounds.set(0, 0, width, bottomAreaHeight);
    handleBounds.set(0, bottomAreaHeight, width, handleHeight);
}

From source file:com.mbrlabs.mundus.editor.ui.widgets.MundusMultiSplitPane.java

License:Apache License

private void initialize() {
    addListener(new ClickListener() {
        Cursor.SystemCursor currentCursor;
        Cursor.SystemCursor targetCursor;

        @Override/*from w w w  .ja v  a2s.  c  o  m*/
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            // @Changed
            // originally returned true
            return false;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            CursorManager.restoreDefaultCursor();
            currentCursor = null;
        }

        @Override
        public boolean mouseMoved(InputEvent event, float x, float y) {
            if (getHandleContaining(x, y) != null) {
                if (vertical) {
                    targetCursor = Cursor.SystemCursor.VerticalResize;
                } else {
                    targetCursor = Cursor.SystemCursor.HorizontalResize;
                }

                if (currentCursor != targetCursor) {
                    Gdx.graphics.setSystemCursor(targetCursor);
                    currentCursor = targetCursor;
                }
            } else {
                if (currentCursor != null) {
                    CursorManager.restoreDefaultCursor();
                    currentCursor = null;
                }
            }

            return false;
        }
    });

    addListener(new InputListener() {
        int draggingPointer = -1;

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (isTouchable() == false)
                return false;

            if (draggingPointer != -1)
                return false;
            if (pointer == 0 && button != 0)
                return false;
            Rectangle containingHandle = getHandleContaining(x, y);
            if (containingHandle != null) {
                handleOverIndex = handleBounds.indexOf(containingHandle, true);
                FocusManager.resetFocus(getStage());

                draggingPointer = pointer;
                lastPoint.set(x, y);
                handlePosition.set(containingHandle.x, containingHandle.y);
                return true;
            }
            return false;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if (pointer == draggingPointer)
                draggingPointer = -1;
            handleOver = getHandleContaining(x, y);
        }

        @Override
        public boolean mouseMoved(InputEvent event, float x, float y) {
            handleOver = getHandleContaining(x, y);
            return false;
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            if (pointer != draggingPointer)
                return;
            // @Changed
            if (!isDraggable)
                return;

            Drawable handle = style.handle;
            if (!vertical) {
                float delta = x - lastPoint.x;
                float availWidth = getWidth() - handle.getMinWidth();
                float dragX = handlePosition.x + delta;
                handlePosition.x = dragX;
                dragX = Math.max(0, dragX);
                dragX = Math.min(availWidth, dragX);
                float targetSplit = dragX / availWidth;
                setSplit(handleOverIndex, targetSplit);
                lastPoint.set(x, y);
            } else {
                float delta = y - lastPoint.y;
                float availHeight = getHeight() - handle.getMinHeight();
                float dragY = handlePosition.y + delta;
                handlePosition.y = dragY;
                dragY = Math.max(0, dragY);
                dragY = Math.min(availHeight, dragY);
                float targetSplit = 1 - (dragY / availHeight);
                setSplit(handleOverIndex, targetSplit);
                lastPoint.set(x, y);
            }
            invalidate();
            // invalidateHierarchy();
        }
    });
}

From source file:com.mbrlabs.mundus.editor.ui.widgets.MundusSplitPane.java

License:Apache License

private void initialize() {
    addListener(new ClickListener() {
        Cursor.SystemCursor currentCursor;
        Cursor.SystemCursor targetCursor;

        @Override//from  w  w w.  j av a2  s  .c  om
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            // originally returned true
            return false;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            CursorManager.restoreDefaultCursor();
            currentCursor = null;
        }

        @Override
        public boolean mouseMoved(InputEvent event, float x, float y) {
            if (handleBounds.contains(x, y)) {
                if (vertical) {
                    targetCursor = Cursor.SystemCursor.VerticalResize;
                } else {
                    targetCursor = Cursor.SystemCursor.HorizontalResize;
                }

                if (currentCursor != targetCursor) {
                    Gdx.graphics.setSystemCursor(targetCursor);
                    currentCursor = targetCursor;
                }
            } else {
                if (currentCursor != null) {
                    CursorManager.restoreDefaultCursor();
                    currentCursor = null;
                }
            }

            return false;
        }
    });

    addListener(new InputListener() {
        int draggingPointer = -1;

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            // TODO potential bug with libgdx scene2d?
            // fixes issue when split bar could be still dragged even when
            // touchable is set to childrenOnly, probably scene2d issue
            if (isTouchable() == false)
                return false;

            if (draggingPointer != -1)
                return false;
            if (pointer == 0 && button != 0)
                return false;
            if (handleBounds.contains(x, y)) {
                FocusManager.resetFocus(getStage());

                draggingPointer = pointer;
                lastPoint.set(x, y);
                handlePosition.set(handleBounds.x, handleBounds.y);
                return true;
            }
            return false;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            if (pointer == draggingPointer)
                draggingPointer = -1;
        }

        @Override
        public boolean mouseMoved(InputEvent event, float x, float y) {
            mouseOnHandle = handleBounds.contains(x, y);
            return false;
        }

        @Override
        public void touchDragged(InputEvent event, float x, float y, int pointer) {
            if (pointer != draggingPointer)
                return;

            Drawable handle = style.handle;
            if (!vertical) {
                float delta = x - lastPoint.x;
                float availWidth = getWidth() - handle.getMinWidth();
                float dragX = handlePosition.x + delta;
                handlePosition.x = dragX;
                dragX = Math.max(0, dragX);
                dragX = Math.min(availWidth, dragX);
                splitAmount = dragX / availWidth;
                if (splitAmount < minAmount)
                    splitAmount = minAmount;
                if (splitAmount > maxAmount)
                    splitAmount = maxAmount;
                lastPoint.set(x, y);
            } else {
                float delta = y - lastPoint.y;
                float availHeight = getHeight() - handle.getMinHeight();
                float dragY = handlePosition.y + delta;
                handlePosition.y = dragY;
                dragY = Math.max(0, dragY);
                dragY = Math.min(availHeight, dragY);
                splitAmount = 1 - (dragY / availHeight);
                if (splitAmount < minAmount)
                    splitAmount = minAmount;
                if (splitAmount > maxAmount)
                    splitAmount = maxAmount;
                lastPoint.set(x, y);
            }
            invalidate();
        }
    });
}

From source file:com.meizu.taskmanager.ui.ScrollPane.java

License:Apache License

public void layout() {
    final Drawable bg = style.background;
    final Drawable hScrollKnob = style.hScrollKnob;
    final Drawable vScrollKnob = style.vScrollKnob;

    float bgLeftWidth = 0, bgRightWidth = 0, bgTopHeight = 0, bgBottomHeight = 0;
    if (bg != null) {
        bgLeftWidth = bg.getLeftWidth();
        bgRightWidth = bg.getRightWidth();
        bgTopHeight = bg.getTopHeight();
        bgBottomHeight = bg.getBottomHeight();
    }// w  w w  .j  av a2  s. c  om

    float width = getWidth();
    float height = getHeight();

    float scrollbarHeight = 0;
    if (hScrollKnob != null)
        scrollbarHeight = hScrollKnob.getMinHeight();
    if (style.hScroll != null)
        scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight());
    float scrollbarWidth = 0;
    if (vScrollKnob != null)
        scrollbarWidth = vScrollKnob.getMinWidth();
    if (style.vScroll != null)
        scrollbarWidth = Math.max(scrollbarWidth, style.vScroll.getMinWidth());

    // 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.getWidth();
        widgetHeight = widget.getHeight();
    }

    // Determine if horizontal/vertical scrollbars are needed.
    scrollX = forceScrollX || (widgetWidth > areaWidth && !disableX);
    scrollY = forceScrollY || (widgetHeight > areaHeight && !disableY);

    boolean fade = fadeScrollBars;
    if (!fade) {
        // Check again, now taking into account the area that's taken up by any enabled scrollbars.
        if (scrollY) {
            areaWidth -= scrollbarWidth;
            if (!scrollX && widgetWidth > areaWidth && !disableX)
                scrollX = true;
        }
        if (scrollX) {
            areaHeight -= scrollbarHeight;
            if (!scrollY && widgetHeight > areaHeight && !disableY) {
                scrollY = true;
                areaWidth -= scrollbarWidth;
            }
        }
    }

    // The bounds of the scrollable area for the widget.
    widgetAreaBounds.set(bgLeftWidth, bgBottomHeight, areaWidth, areaHeight);

    if (fade) {
        // Make sure widget is drawn under fading scrollbars.
        if (scrollX && scrollY) {
            areaHeight -= scrollbarHeight;
            areaWidth -= scrollbarWidth;
        }
    } else {
        if (scrollbarsOnTop) {
            // Make sure widget is drawn under non-fading scrollbars.
            if (scrollX)
                widgetAreaBounds.height += scrollbarHeight;
            if (scrollY)
                widgetAreaBounds.width += scrollbarWidth;
        } else {
            // Offset widget area y for horizontal scrollbar at bottom.
            if (scrollX && hScrollOnBottom)
                widgetAreaBounds.y += scrollbarHeight;
            // Offset widget area x for vertical scrollbar at left.
            if (scrollY && !vScrollOnRight)
                widgetAreaBounds.x += scrollbarWidth;
        }
    }

    // If the widget is smaller than the available space, make it take up the available space.
    widgetWidth = disableX ? areaWidth : Math.max(areaWidth, widgetWidth);
    widgetHeight = disableY ? areaHeight : Math.max(areaHeight, widgetHeight);

    maxX = widgetWidth - areaWidth;
    maxY = widgetHeight - areaHeight;
    if (fade) {
        // Make sure widget is drawn under fading scrollbars.
        if (scrollX)
            maxY -= scrollbarHeight;
        if (scrollY)
            maxX -= scrollbarWidth;
    }
    scrollX(MathUtils.clamp(amountX, 0, maxX));
    scrollY(MathUtils.clamp(amountY, 0, maxY));

    // Set the bounds and scroll knob sizes if scrollbars are needed.
    if (scrollX) {
        if (hScrollKnob != null) {
            float hScrollHeight = style.hScroll != null ? style.hScroll.getMinHeight()
                    : hScrollKnob.getMinHeight();
            // The corner gap where the two scroll bars intersect might have to flip from right to left.
            float boundsX = vScrollOnRight ? bgLeftWidth : bgLeftWidth + scrollbarWidth;
            // Scrollbar on the top or bottom.
            float boundsY = hScrollOnBottom ? bgBottomHeight : height - bgTopHeight - hScrollHeight;
            hScrollBounds.set(boundsX, boundsY, areaWidth, hScrollHeight);
            if (variableSizeKnobs)
                hKnobBounds.width = Math.max(hScrollKnob.getMinWidth(),
                        (int) (hScrollBounds.width * areaWidth / widgetWidth));
            else
                hKnobBounds.width = hScrollKnob.getMinWidth();

            hKnobBounds.height = hScrollKnob.getMinHeight();

            hKnobBounds.x = hScrollBounds.x
                    + (int) ((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX());
            hKnobBounds.y = hScrollBounds.y;
        } else {
            hScrollBounds.set(0, 0, 0, 0);
            hKnobBounds.set(0, 0, 0, 0);
        }
    }
    if (scrollY) {
        if (vScrollKnob != null) {
            float vScrollWidth = style.vScroll != null ? style.vScroll.getMinWidth()
                    : vScrollKnob.getMinWidth();
            // the small gap where the two scroll bars intersect might have to flip from bottom to top
            float boundsX, boundsY;
            if (hScrollOnBottom) {
                boundsY = height - bgTopHeight - areaHeight;
            } else {
                boundsY = bgBottomHeight;
            }
            // bar on the left or right
            if (vScrollOnRight) {
                boundsX = width - bgRightWidth - vScrollWidth;
            } else {
                boundsX = bgLeftWidth;
            }
            vScrollBounds.set(boundsX, boundsY, vScrollWidth, areaHeight);
            vKnobBounds.width = vScrollKnob.getMinWidth();
            if (variableSizeKnobs)
                vKnobBounds.height = Math.max(vScrollKnob.getMinHeight(),
                        (int) (vScrollBounds.height * areaHeight / widgetHeight));
            else
                vKnobBounds.height = vScrollKnob.getMinHeight();

            if (vScrollOnRight) {
                vKnobBounds.x = width - bgRightWidth - vScrollKnob.getMinWidth();
            } else {
                vKnobBounds.x = bgLeftWidth;
            }
            vKnobBounds.y = vScrollBounds.y
                    + (int) ((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY()));
        } else {
            vScrollBounds.set(0, 0, 0, 0);
            vKnobBounds.set(0, 0, 0, 0);
        }
    }

    widget.setSize(widgetWidth, widgetHeight);
    if (widget instanceof Layout)
        ((Layout) widget).validate();
}