Example usage for com.badlogic.gdx.utils SnapshotArray sort

List of usage examples for com.badlogic.gdx.utils SnapshotArray sort

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils SnapshotArray sort.

Prototype

public void sort(Comparator<? super T> comparator) 

Source Link

Usage

From source file:es.eucm.ead.editor.view.widgets.files.FilesListWidget.java

License:Open Source License

@Override
public void layout() {
    super.layout();

    scrollPane.invalidate();//from w w w . ja  v a2s  . c  o m

    float x = style.margin;
    float y = -style.margin;
    float containerHeight = style.margin;
    float maxHeight = 0;
    SnapshotArray<Actor> children = filesContainer.getChildren();
    children.sort(fileComparator);

    for (Actor actor : children) {
        float height = getPrefHeight(actor);
        maxHeight = Math.max(maxHeight, height);
        float width = getPrefWidth(actor);
        if (x + width + style.margin > scrollPane.getWidth()) {
            x = style.margin;
            y -= maxHeight + style.margin;
            containerHeight += maxHeight + style.margin;
        }
        actor.setBounds(x, y - height, width, height);
        x += width + style.margin;
    }

    containerHeight += maxHeight;
    for (Actor actor : children) {
        actor.setY(actor.getY() + containerHeight);
    }
    filesContainer.setBounds(0, 0, scrollPane.getWidth(), containerHeight);

    if (containerHeight < scrollPane.getHeight()) {
        scrollPane.setY(scrollPane.getY() + scrollPane.getHeight() - containerHeight);
    }
}