List of usage examples for com.badlogic.gdx.scenes.scene2d.utils Layout getPrefWidth
public float getPrefWidth();
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 ava2 s . co m*/ 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.crashinvaders.common.scene2d.HorizontalGroupExtended.java
License:Apache License
private void computeSize() { sizeInvalid = false;/*w w w.j a va2 s . c o m*/ Array<Actor> children = getVisibleChildren(); int n = children.size; prefWidth = padLeft + padRight + spacing * (n - 1); prefHeight = 0; for (int i = 0; i < n; i++) { Actor child = children.get(i); if (child instanceof Layout) { Layout layout = (Layout) child; prefWidth += layout.getPrefWidth(); prefHeight = Math.max(prefHeight, layout.getPrefHeight()); } else { prefWidth += child.getWidth(); prefHeight = Math.max(prefHeight, child.getHeight()); } } prefHeight += padTop + padBottom; if (round) { prefWidth = Math.round(prefWidth); prefHeight = Math.round(prefHeight); } }
From source file:com.crashinvaders.common.scene2d.HorizontalGroupExtended.java
License:Apache License
@Override public void layout() { float spacing = this.spacing, padBottom = this.padBottom; int align = this.align; boolean reverse = this.reverse, round = this.round; float groupHeight = getHeight() - padTop - padBottom; float x = !reverse ? padLeft : getWidth() - padRight + spacing; Array<Actor> children = getVisibleChildren(); for (int i = 0, n = children.size; i < n; i++) { Actor child = children.get(i);//from www .j av a 2s. co m float width, height; if (child instanceof Layout) { Layout layout = (Layout) child; if (fill > 0) height = groupHeight * fill; else height = Math.min(layout.getPrefHeight(), groupHeight); height = Math.max(height, layout.getMinHeight()); float maxHeight = layout.getMaxHeight(); if (maxHeight > 0 && height > maxHeight) height = maxHeight; width = layout.getPrefWidth(); } else { width = child.getWidth(); height = child.getHeight(); if (fill > 0) height *= fill; } float y = padBottom; if ((align & Align.top) != 0) y += groupHeight - height; else if ((align & Align.bottom) == 0) // center y += (groupHeight - height) / 2; if (reverse) x -= (width + spacing); if (round) child.setBounds(Math.round(x), Math.round(y), Math.round(width), Math.round(height)); else child.setBounds(x, y, width, height); if (!reverse) x += (width + spacing); } }
From source file:com.kotcrab.vis.editor.ui.HorizontalFlowGroup.java
License:Apache License
private void computeSize() { prefWidth = 0;//from www .ja v a 2 s .c om prefHeight = 0; sizeInvalid = false; SnapshotArray<Actor> children = getChildren(); float groupWidth = getWidth(); float x = 0; float maxHeight = 0; for (int i = 0, n = children.size; i < n; i++) { Actor child = children.get(i); float width = child.getWidth(); float height = child.getHeight(); if (child instanceof Layout) { Layout layout = (Layout) child; width = layout.getPrefWidth(); height = layout.getPrefHeight(); } if (x + width <= groupWidth) { prefWidth += width + spacing; x += width + spacing; maxHeight = Math.max(height, maxHeight); } else { prefHeight += maxHeight + spacing; maxHeight = height; x = width + spacing; } } prefHeight += maxHeight; }
From source file:com.kotcrab.vis.editor.ui.HorizontalFlowGroup.java
License:Apache License
public void layout() { if (sizeInvalid) { computeSize();/* ww w. ja va 2 s . com*/ if (lastPrefHeight != prefHeight) { lastPrefHeight = prefHeight; invalidateHierarchy(); } } SnapshotArray<Actor> children = getChildren(); float groupWidth = getWidth(); float x = 0; float y = getHeight(); float maxHeight = 0; for (int i = 0, n = children.size; i < n; i++) { Actor child = children.get(i); float width = child.getWidth(); float height = child.getHeight(); if (child instanceof Layout) { Layout layout = (Layout) child; width = layout.getPrefWidth(); height = layout.getPrefHeight(); } if (x + width <= groupWidth) { maxHeight = Math.max(height, maxHeight); } else { y -= maxHeight + spacing; maxHeight = height; x = 0; } child.setBounds(x, y - height, width, height); x += width + spacing; } }
From source file:com.kotcrab.vis.ui.layout.ColumnGroup.java
License:Apache License
private void computeSize() { prefWidth = 0;//www.j ava 2 s .c om prefHeight = 0; sizeInvalid = false; SnapshotArray<Actor> children = getChildren(); for (int i = 0, n = children.size; i < n; i++) { Actor child = children.get(i); float width = child.getWidth(); float height = child.getHeight(); if (child instanceof Layout) { Layout layout = (Layout) child; width = layout.getPrefWidth(); height = layout.getPrefHeight(); } prefWidth = Math.max(prefWidth, width); prefHeight += height; } }
From source file:com.kotcrab.vis.ui.layout.ColumnGroup.java
License:Apache License
@Override public void layout() { if (sizeInvalid) { computeSize();// w ww . j av a 2 s. com if (lastPrefHeight != prefHeight) { lastPrefHeight = prefHeight; invalidateHierarchy(); } } float y = getHeight(); SnapshotArray<Actor> children = getChildren(); for (int i = 0, n = children.size; i < n; i++) { Actor child = children.get(i); float width = child.getWidth(); float height = child.getHeight(); if (child instanceof Layout) { Layout layout = (Layout) child; width = layout.getPrefWidth(); height = layout.getPrefHeight(); } child.setBounds(0, y - height, width, height); y -= height; } }
From source file:com.kotcrab.vis.ui.layout.FloatingGroup.java
License:Apache License
@Override public void layout() { if (useChildrenPreferredSize == false) return;/* w w w. ja v a2 s .com*/ SnapshotArray<Actor> children = getChildren(); for (int i = 0; i < children.size; i++) { Actor child = children.get(i); float width = child.getWidth(); float height = child.getHeight(); if (child instanceof Layout) { Layout layout = (Layout) child; width = layout.getPrefWidth(); height = layout.getPrefHeight(); } child.setBounds(child.getX(), child.getY(), width, height); } }
From source file:com.kotcrab.vis.ui.layout.HorizontalFlowGroup.java
License:Apache License
private void computeSize() { prefWidth = getWidth();/*w w w . java 2s.c om*/ prefHeight = 0; sizeInvalid = false; SnapshotArray<Actor> children = getChildren(); float x = 0; float rowHeight = 0; for (int i = 0; i < children.size; i++) { Actor child = children.get(i); float width = child.getWidth(); float height = child.getHeight(); if (child instanceof Layout) { Layout layout = (Layout) child; width = layout.getPrefWidth(); height = layout.getPrefHeight(); } if (x + width > getWidth()) { x = 0; prefHeight += rowHeight + spacing; rowHeight = height; } else { rowHeight = Math.max(height, rowHeight); } x += width + spacing; } //handle last row height prefHeight += rowHeight + spacing; }
From source file:com.kotcrab.vis.ui.layout.HorizontalFlowGroup.java
License:Apache License
@Override public void layout() { if (sizeInvalid) { computeSize();/*from www.j a v a 2 s . c o m*/ if (lastPrefHeight != prefHeight) { lastPrefHeight = prefHeight; invalidateHierarchy(); } } SnapshotArray<Actor> children = getChildren(); float x = 0; float y = getHeight(); float rowHeight = 0; for (int i = 0; i < children.size; i++) { Actor child = children.get(i); float width = child.getWidth(); float height = child.getHeight(); if (child instanceof Layout) { Layout layout = (Layout) child; width = layout.getPrefWidth(); height = layout.getPrefHeight(); } if (x + width > getWidth()) { x = 0; y -= rowHeight + spacing; rowHeight = height; } else { rowHeight = Math.max(height, rowHeight); } child.setBounds(x, y - height, width, height); x += width + spacing; } }