Search in sources :

Example 1 with ComponentWrapper

use of net.miginfocom.layout.ComponentWrapper in project Terasology by MovingBlocks.

the class MigLayout method onDraw.

@Override
public void onDraw(Canvas canvas) {
    int[] bounds = { 0, 0, canvas.size().x, canvas.size().y };
    layoutContainer(canvas, bounds);
    for (ComponentWrapper wrapper : wrappers.values()) {
        UIWidget component = (UIWidget) wrapper.getComponent();
        Rect2i region = Rect2i.createFromMinAndSize(wrapper.getX(), wrapper.getY(), wrapper.getWidth(), wrapper.getHeight());
        canvas.drawWidget(component, region);
    }
    if (debug) {
        grid.paintDebug();
    }
    for (Rect2i region : debugRects) {
        canvas.drawLine(region.minX(), region.minY(), region.maxX(), region.minY(), Color.WHITE);
        canvas.drawLine(region.maxX(), region.minY(), region.maxX(), region.maxY(), Color.WHITE);
        canvas.drawLine(region.maxX(), region.maxY(), region.minX(), region.maxY(), Color.WHITE);
        canvas.drawLine(region.minX(), region.maxY(), region.minX(), region.minY(), Color.WHITE);
    }
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) ComponentWrapper(net.miginfocom.layout.ComponentWrapper) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 2 with ComponentWrapper

use of net.miginfocom.layout.ComponentWrapper in project Terasology by MovingBlocks.

the class MigLayout method addWidget.

@Override
public void addWidget(UIWidget element, CCHint hint) {
    final ComponentWrapper cw = getWrapper(element);
    final String cStr = ConstraintParser.prepare(hint != null ? hint.cc : "");
    CC constraint = AccessController.doPrivileged((PrivilegedAction<CC>) () -> ConstraintParser.parseComponentConstraint(cStr));
    ccMap.put(cw, constraint);
    wrappers.put(element, cw);
    children.add(cw);
    dirty = true;
}
Also used : CC(net.miginfocom.layout.CC) ComponentWrapper(net.miginfocom.layout.ComponentWrapper)

Example 3 with ComponentWrapper

use of net.miginfocom.layout.ComponentWrapper in project Terasology by MovingBlocks.

the class MigLayout method removeWidget.

@Override
public void removeWidget(UIWidget element) {
    ComponentWrapper cw = wrappers.remove(element);
    ccMap.remove(cw);
    children.remove(cw);
    invalidate();
}
Also used : ComponentWrapper(net.miginfocom.layout.ComponentWrapper)

Example 4 with ComponentWrapper

use of net.miginfocom.layout.ComponentWrapper in project Terasology by MovingBlocks.

the class MigLayout method layoutContainer.

public void layoutContainer(Canvas canvas, int[] bounds) {
    for (ComponentWrapper wrapper : children) {
        if (wrapper instanceof MigLayout) {
            MigLayout layout = (MigLayout) wrapper;
            layout.layoutContainer(canvas, bounds);
        } else if (wrapper instanceof MigComponent) {
            MigComponent migComponent = (MigComponent) wrapper;
            migComponent.calculatePreferredSize(canvas, canvas.size());
        }
    }
    checkCache();
    if (grid.layout(bounds, lc.getAlignX(), lc.getAlignY(), debug, true)) {
        grid = null;
        checkCache();
        grid.layout(bounds, lc.getAlignX(), lc.getAlignY(), debug, false);
    }
}
Also used : ComponentWrapper(net.miginfocom.layout.ComponentWrapper)

Example 5 with ComponentWrapper

use of net.miginfocom.layout.ComponentWrapper in project Terasology by MovingBlocks.

the class MigLayout method getWrapper.

private ComponentWrapper getWrapper(UIWidget comp) {
    ComponentWrapper cw;
    if (comp instanceof MigLayout) {
        MigLayout migLayout = (MigLayout) comp;
        migLayout.setParent(this);
        cw = migLayout;
    } else {
        cw = new MigComponent(this, comp);
    }
    return cw;
}
Also used : ComponentWrapper(net.miginfocom.layout.ComponentWrapper)

Aggregations

ComponentWrapper (net.miginfocom.layout.ComponentWrapper)5 CC (net.miginfocom.layout.CC)1 Rect2i (org.terasology.math.geom.Rect2i)1 UIWidget (org.terasology.rendering.nui.UIWidget)1