com.badlogic.gdx.scenes.scene2d.utils.Layout Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.utils.Layout. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TabPane.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@Override public float getPrefWidth() {
    if (selectedIndex == -1)
        return 0;
    validate();
    float headersWidth = 0;
    float maxWidth = 0f;
    for (Actor header : headers) {
        maxWidth = Math.max(header instanceof Layout ? ((Layout) header).getPrefWidth() : header.getWidth(), maxWidth);
    }
    headersWidth += maxWidth * headers.size;
    headersWidth += headersLeftOffset;
    headersWidth += headersRightOffset;
    headersWidth += headersBetweenOffset * (headers.size - 1);
    float contentsWidth = 0;
    for (Actor content : contents) {
        contentsWidth = Math.max(contentsWidth, content instanceof Layout ? ((Layout) content).getPrefWidth() : content.getWidth());
    }
    return Math.max(contentsWidth, headersWidth);
}
 
Example #2
Source File: VisSplitPane.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
@Override
public void layout () {
	if (!vertical)
		calculateHorizBoundsAndPositions();
	else
		calculateVertBoundsAndPositions();

	Actor firstWidget = this.firstWidget;
	if (firstWidget != null) {
		Rectangle firstWidgetBounds = this.firstWidgetBounds;
		firstWidget.setBounds(firstWidgetBounds.x, firstWidgetBounds.y, firstWidgetBounds.width, firstWidgetBounds.height);
		if (firstWidget instanceof Layout) ((Layout) firstWidget).validate();
	}
	Actor secondWidget = this.secondWidget;
	if (secondWidget != null) {
		Rectangle secondWidgetBounds = this.secondWidgetBounds;
		secondWidget.setBounds(secondWidgetBounds.x, secondWidgetBounds.y, secondWidgetBounds.width, secondWidgetBounds.height);
		if (secondWidget instanceof Layout) ((Layout) secondWidget).validate();
	}
}
 
Example #3
Source File: MundusSplitPane.java    From Mundus with Apache License 2.0 6 votes vote down vote up
@Override
public void layout() {
    if (!vertical)
        calculateHorizBoundsAndPositions();
    else
        calculateVertBoundsAndPositions();

    Actor firstWidget = this.firstWidget;
    if (firstWidget != null) {
        Rectangle firstWidgetBounds = this.firstWidgetBounds;
        firstWidget.setBounds(firstWidgetBounds.x, firstWidgetBounds.y, firstWidgetBounds.width,
                firstWidgetBounds.height);
        if (firstWidget instanceof Layout) ((Layout) firstWidget).validate();
    }
    Actor secondWidget = this.secondWidget;
    if (secondWidget != null) {
        Rectangle secondWidgetBounds = this.secondWidgetBounds;
        secondWidget.setBounds(secondWidgetBounds.x, secondWidgetBounds.y, secondWidgetBounds.width,
                secondWidgetBounds.height);
        if (secondWidget instanceof Layout) ((Layout) secondWidget).validate();
    }
}
 
Example #4
Source File: TransformScalableWrapper.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefHeight() {
    if (actor == null) return 0f;

    if (actor instanceof Layout) {
        Layout layout = (Layout) actor;
        return layout.getPrefHeight() * getScaleY();
    } else {
        return origHeight * getScaleY();
    }
}
 
Example #5
Source File: HorizontalFlowGroup.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void computeSize () {
	prefWidth = getWidth();
	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;
}
 
Example #6
Source File: VerticalFlowGroup.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void computeSize () {
	prefWidth = 0;
	prefHeight = getHeight();
	sizeInvalid = false;

	SnapshotArray<Actor> children = getChildren();

	float y = 0;
	float columnWidth = 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 (y + height > getHeight()) {
			y = 0;
			prefWidth += columnWidth + spacing;
			columnWidth = width;
		} else {
			columnWidth = Math.max(width, columnWidth);
		}

		y += height + spacing;
	}

	//handle last column width
	prefWidth += columnWidth + spacing;
}
 
Example #7
Source File: IconStack.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void computeSize () {
	sizeInvalid = false;
	prefWidth = 0;
	prefHeight = 0;
	minWidth = 0;
	minHeight = 0;
	maxWidth = 0;
	maxHeight = 0;
	SnapshotArray<Actor> children = getChildren();
	for (int i = 0, n = children.size; i < n; i++) {
		Actor child = children.get(i);
		float childMaxWidth, childMaxHeight;
		if (child instanceof Layout) {
			Layout layout = (Layout) child;
			prefWidth = Math.max(prefWidth, layout.getPrefWidth());
			prefHeight = Math.max(prefHeight, layout.getPrefHeight());
			minWidth = Math.max(minWidth, layout.getMinWidth());
			minHeight = Math.max(minHeight, layout.getMinHeight());
			childMaxWidth = layout.getMaxWidth();
			childMaxHeight = layout.getMaxHeight();
		} else {
			prefWidth = Math.max(prefWidth, child.getWidth());
			prefHeight = Math.max(prefHeight, child.getHeight());
			minWidth = Math.max(minWidth, child.getWidth());
			minHeight = Math.max(minHeight, child.getHeight());
			childMaxWidth = 0;
			childMaxHeight = 0;
		}
		if (childMaxWidth > 0) maxWidth = maxWidth == 0 ? childMaxWidth : Math.min(maxWidth, childMaxWidth);
		if (childMaxHeight > 0) maxHeight = maxHeight == 0 ? childMaxHeight : Math.min(maxHeight, childMaxHeight);
	}
}
 
Example #8
Source File: VisSplitPane.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefHeight () {
	float height = 0;
	if (firstWidget != null)
		height = firstWidget instanceof Layout ? ((Layout) firstWidget).getPrefHeight() : firstWidget.getHeight();
	if (secondWidget != null)
		height += secondWidget instanceof Layout ? ((Layout) secondWidget).getPrefHeight() : secondWidget.getHeight();
	if (vertical) height += style.handle.getMinHeight();
	return height;
}
 
Example #9
Source File: VisSplitPane.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefWidth () {
	float width = 0;
	if (firstWidget != null)
		width = firstWidget instanceof Layout ? ((Layout) firstWidget).getPrefWidth() : firstWidget.getWidth();
	if (secondWidget != null)
		width += secondWidget instanceof Layout ? ((Layout) secondWidget).getPrefWidth() : secondWidget.getWidth();
	if (!vertical) width += style.handle.getMinWidth();
	return width;
}
 
Example #10
Source File: MultiSplitPane.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefHeight () {
	float height = 0;
	for (Actor actor : getChildren()) {
		height = actor instanceof Layout ? ((Layout) actor).getPrefHeight() : actor.getHeight();

	}
	if (vertical) height += handleBounds.size * style.handle.getMinHeight();
	return height;
}
 
Example #11
Source File: MultiSplitPane.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefWidth () {
	float width = 0;
	for (Actor actor : getChildren()) {
		width = actor instanceof Layout ? ((Layout) actor).getPrefWidth() : actor.getWidth();
	}
	if (!vertical) width += handleBounds.size * style.handle.getMinWidth();
	return width;
}
 
Example #12
Source File: MultiSplitPane.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public void layout () {
	if (!vertical)
		calculateHorizBoundsAndPositions();
	else
		calculateVertBoundsAndPositions();

	SnapshotArray<Actor> actors = getChildren();
	for (int i = 0; i < actors.size; i++) {
		Actor actor = actors.get(i);
		Rectangle bounds = widgetBounds.get(i);
		actor.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
		if (actor instanceof Layout) ((Layout) actor).validate();
	}
}
 
Example #13
Source File: MundusMultiSplitPane.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefHeight() {
    float height = 0;
    for (Actor actor : getChildren()) {
        height = actor instanceof Layout ? ((Layout) actor).getPrefHeight() : actor.getHeight();

    }
    if (vertical) height += handleBounds.size * style.handle.getMinHeight();
    return height;
}
 
Example #14
Source File: MundusMultiSplitPane.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefWidth() {
    float width = 0;
    for (Actor actor : getChildren()) {
        width = actor instanceof Layout ? ((Layout) actor).getPrefWidth() : actor.getWidth();
    }
    if (!vertical) width += handleBounds.size * style.handle.getMinWidth();
    return width;
}
 
Example #15
Source File: MundusMultiSplitPane.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public void layout() {
    if (!vertical)
        calculateHorizBoundsAndPositions();
    else
        calculateVertBoundsAndPositions();

    SnapshotArray<Actor> actors = getChildren();
    for (int i = 0; i < actors.size; i++) {
        Actor actor = actors.get(i);
        Rectangle bounds = widgetBounds.get(i);
        actor.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
        if (actor instanceof Layout) ((Layout) actor).validate();
    }
}
 
Example #16
Source File: MundusSplitPane.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefHeight() {
    float height = 0;
    if (firstWidget != null)
        height = firstWidget instanceof Layout ? ((Layout) firstWidget).getPrefHeight() : firstWidget.getHeight();
    if (secondWidget != null) height += secondWidget instanceof Layout ? ((Layout) secondWidget).getPrefHeight()
            : secondWidget.getHeight();
    if (vertical) height += style.handle.getMinHeight();
    return height;
}
 
Example #17
Source File: MundusSplitPane.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefWidth() {
    float width = 0;
    if (firstWidget != null)
        width = firstWidget instanceof Layout ? ((Layout) firstWidget).getPrefWidth() : firstWidget.getWidth();
    if (secondWidget != null)
        width += secondWidget instanceof Layout ? ((Layout) secondWidget).getPrefWidth() : secondWidget.getWidth();
    if (!vertical) width += style.handle.getMinWidth();
    return width;
}
 
Example #18
Source File: ScrollPane.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public float getPrefHeight () {
	if (widget instanceof Layout) {
		float height = ((Layout)widget).getPrefHeight();
		if (style.background != null) height += style.background.getTopHeight() + style.background.getBottomHeight();
		if (forceScrollX) {
			float scrollbarHeight = 0;
			if (style.hScrollKnob != null) scrollbarHeight = style.hScrollKnob.getMinHeight();
			if (style.hScroll != null) scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight());
			height += scrollbarHeight;
		}
		return height;
	}
	return 150;
}
 
Example #19
Source File: ScrollPane.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public float getPrefWidth () {
	if (widget instanceof Layout) {
		float width = ((Layout)widget).getPrefWidth();
		if (style.background != null) width += style.background.getLeftWidth() + style.background.getRightWidth();
		if (forceScrollY) {
			float scrollbarWidth = 0;
			if (style.vScrollKnob != null) scrollbarWidth = style.vScrollKnob.getMinWidth();
			if (style.vScroll != null) scrollbarWidth = Math.max(scrollbarWidth, style.vScroll.getMinWidth());
			width += scrollbarWidth;
		}
		return width;
	}
	return 150;
}
 
Example #20
Source File: ScalarScalableWrapper.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefHeight() {
    if (actor == null) return 0f;

    if (actor instanceof Layout) {
        Layout layout = (Layout) actor;
        return layout.getPrefHeight() * scaleY;
    } else {
        return origHeight * scaleY;
    }
}
 
Example #21
Source File: ScalarScalableWrapper.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefWidth() {
    if (actor == null) return 0f;

    if (actor instanceof Layout) {
        Layout layout = (Layout) actor;
        return layout.getPrefWidth() * scaleX;
    } else {
        return origWidth * scaleX;
    }
}
 
Example #22
Source File: TransformScalableWrapper.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefHeight() {
    if (actor == null) return 0f;

    if (actor instanceof Layout) {
        Layout layout = (Layout) actor;
        return layout.getPrefHeight() * getScaleY();
    } else {
        return origHeight * getScaleY();
    }
}
 
Example #23
Source File: TransformScalableWrapper.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefWidth() {
    if (actor == null) return 0f;

    if (actor instanceof Layout) {
        Layout layout = (Layout) actor;
        return layout.getPrefWidth() * getScaleX();
    } else {
        return origWidth * getScaleX();
    }
}
 
Example #24
Source File: FilteredTree.java    From talos with Apache License 2.0 5 votes vote down vote up
private void computeSize (Array<Node<T>> nodes, float indent) {
    float ySpacing = this.ySpacing;
    float spacing = iconSpacingLeft + iconSpacingRight;
    for (int i = 0, n = nodes.size; i < n; i++) {
        Node node = nodes.get(i);

        if (node.filtered)
            continue;

        float rowWidth = indent + iconSpacingRight;
        Actor actor = node.actor;
        if (actor instanceof Layout) {
            Layout layout = (Layout)actor;
            rowWidth += layout.getPrefWidth();
            node.height = layout.getPrefHeight();
            layout.pack();
        } else {
            rowWidth += actor.getWidth();
            node.height = actor.getHeight();
        }
        if (node.icon != null) {
            rowWidth += spacing + node.icon.getMinWidth();
            node.height = Math.max(node.height, node.icon.getMinHeight());
        }
        prefWidth = Math.max(prefWidth, rowWidth);
        prefHeight -= node.height + ySpacing;
        if (node.expanded)
            computeSize(node.children, indent + indentSpacing);
    }
}
 
Example #25
Source File: ScalarScalableWrapper.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefHeight() {
    if (actor == null) return 0f;

    if (actor instanceof Layout) {
        Layout layout = (Layout) actor;
        return layout.getPrefHeight() * scaleY;
    } else {
        return origHeight * scaleY;
    }
}
 
Example #26
Source File: ScalarScalableWrapper.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefWidth() {
    if (actor == null) return 0f;

    if (actor instanceof Layout) {
        Layout layout = (Layout) actor;
        return layout.getPrefWidth() * scaleX;
    } else {
        return origWidth * scaleX;
    }
}
 
Example #27
Source File: TransformScalableWrapper.java    From gdx-vfx with Apache License 2.0 5 votes vote down vote up
@Override
public float getPrefWidth() {
    if (actor == null) return 0f;

    if (actor instanceof Layout) {
        Layout layout = (Layout) actor;
        return layout.getPrefWidth() * getScaleX();
    } else {
        return origWidth * getScaleX();
    }
}
 
Example #28
Source File: TabPane.java    From dice-heroes with GNU General Public License v3.0 4 votes vote down vote up
@Override public float getPrefHeight() {
        if (selectedIndex == -1)
            return 0;
//        validate();
        // left offset
        float headersHeight = 0f;
        if (selectedIndex == 0) {
            if (style.activeBorderLeftEdge != null) {
                headersHeight = style.activeBorderLeftEdge.getMinHeight();
            }
        } else {
            if (style.inactiveBorderLeftEdge != null) {
                headersHeight = Math.max(headersHeight, style.inactiveBorderLeftEdge.getMinHeight());
            }
        }
        //right offset
        if (selectedIndex == headers.size - 1) {
            if (style.activeBorderRightEdge != null) {
                headersHeight = Math.max(headersHeight, style.activeBorderRightEdge.getMinHeight());
            }
        } else {
            if (style.inactiveBorderRightEdge != null) {
                headersHeight = Math.max(headersHeight, style.inactiveBorderRightEdge.getMinHeight());
            }
        }
        //size between headers
        if (style.inactiveBorder != null) {
            headersHeight = Math.max(headersHeight, style.inactiveBorder.getMinHeight());
        }
        if (style.activeBorderLeft != null) {
            headersHeight = Math.max(headersHeight, style.activeBorderLeft.getMinHeight());
        }
        if (style.activeBorderRight != null) {
            headersHeight = Math.max(headersHeight, style.activeBorderRight.getMinHeight());
        }
        for (Actor header : headers) {
            headersHeight = Math.max(headersHeight, header instanceof Layout ? ((Layout) header).getPrefHeight() : header.getHeight());
        }

        float contentsHeight = 0;
        for (Actor content : contents) {
            contentsHeight = Math.max(contentsHeight, content instanceof Layout ? ((Layout) content).getPrefHeight() : content.getHeight());
        }
        return headersHeight + contentsHeight;
    }
 
Example #29
Source File: DiceWindow.java    From dice-heroes with GNU General Public License v3.0 4 votes vote down vote up
@Override protected void doShow(final UserData userData) {
    final Table items = new Table();
    final ScrollPane pane = new ScrollPane(items, new ScrollPane.ScrollPaneStyle()) {

        @Override public void layout() {
            float w = items.getPrefWidth();
            float h = Math.min(getParent().getHeight(), items.getPrefHeight());
            if (w != getWidth() || h != getHeight()) {
                setSize(w, h);
                invalidateHierarchy();
            }
            super.layout();
        }
    };
    pane.setTouchable(Touchable.childrenOnly);
    pane.setOverscroll(false, false);
    pane.setCancelTouchFocus(false);
    pane.addListener(new ChangeListener() {

        @Override public void changed(ChangeEvent event, Actor actor) {
            pane.layout();
            pane.layout();
            items.layout();
            if (actor instanceof Layout)
                ((Layout) actor).layout();
            pane.layout();
            pane.layout();
            pane.scrollTo(actor.getX(), actor.getY(), actor.getWidth(), actor.getHeight() + 100);
        }
    });

    Iterable<Die> dice = userData.dice();
    int i = 1;
    int count = userData.diceCount();
    for (Die die : dice) {
        DiePane diePane = new DiePane(die, userData, diceWindowGroup);
        table.add(diePane);
        diePane.setWidth(0);
        diePane.pack();
        diePane.setWidth(ViewController.CELL_SIZE * 6.6f);
        Cell cell = items.add(diePane).fillX().maxWidth(ViewController.CELL_SIZE * 6.6f);
        if (i != count) {
            cell.padBottom(-1);
        }
        cell.row();
        map.put(die, diePane);
        diePane.info.addListener(createMinimizeListener(die, dice));
        i++;
    }
    items.pack();
    table.add(pane).width(items.getPrefWidth());//.size(items.getPrefWidth(), 200);
}
 
Example #30
Source File: SettingsMenu.java    From Cubes with MIT License 4 votes vote down vote up
public ListObject(Label label, Actor actor) {
  this.label = label;
  this.actor = actor;
  if (!(actor instanceof Layout)) throw new CubesException("Settings actor must implement Layout");
}