Search in sources :

Example 1 with Vector2i

use of org.joml.Vector2i in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class VSIterationUtilsTest method testIterator2d.

@Test
public void testIterator2d() {
    Iterator<Vector2i> iterator = new VSIterationUtils.Int2dIterator(-10, -10, 10, 10);
    List<Vector2i> iVals = new ArrayList<>();
    List<Vector2i> oVals = new ArrayList<>();
    while (iterator.hasNext()) {
        Vector2i vec = iterator.next();
        iVals.add(vec);
    }
    VSIterationUtils.iterate2d(-10, -10, 10, 10, (x, y) -> oVals.add(new Vector2i(x, y)));
    assertThat(iVals, containsInAnyOrder(oVals.toArray()));
}
Also used : ArrayList(java.util.ArrayList) Vector2i(org.joml.Vector2i) Test(org.junit.jupiter.api.Test)

Example 2 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class RowLayoutTest method testNoRelativeWidths.

@Test
public void testNoRelativeWidths() throws Exception {
    rowLayout.setHorizontalSpacing(0);
    Vector2i result = rowLayout.getPreferredContentSize(canvas, canvas.size());
    // Preferred width should be width of canvas
    assertEquals(CANVAS_WIDTH, result.x);
    // Preferred height should be the height of the tallest widget
    assertEquals(15, result.y);
    rowLayout.onDraw(canvas);
    // Width split equally among 3 widgets as they have no relative widths
    verify(canvas).drawWidget(itemAt1x1, RectUtility.createFromMinAndSize(0, 0, CANVAS_WIDTH / 3, CANVAS_HEIGHT));
    verify(canvas).drawWidget(itemAt1x2, RectUtility.createFromMinAndSize(CANVAS_WIDTH / 3, 0, CANVAS_WIDTH / 3, CANVAS_HEIGHT));
    verify(canvas).drawWidget(itemAt1x3, RectUtility.createFromMinAndSize(CANVAS_WIDTH / 3 + CANVAS_WIDTH / 3, 0, CANVAS_WIDTH / 3, CANVAS_HEIGHT));
}
Also used : Vector2i(org.joml.Vector2i) Test(org.junit.jupiter.api.Test)

Example 3 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class CardLayoutTest method testSwitchCard.

@Test
public void testSwitchCard() throws Exception {
    Vector2i result = cardLayout.getPreferredContentSize(canvas, canvas.size());
    // Preferred width should be the longest preferred width among widgets
    assertEquals(50, result.x);
    // Preferred height should be the tallest preferred height among widgets
    assertEquals(15, result.y);
    // Switch to widget1
    cardLayout.setDisplayedCard("widget1");
    cardLayout.onDraw(canvas);
    verify(canvas).drawWidget(widget1);
    // Switch to widget2
    cardLayout.setDisplayedCard("widget2");
    cardLayout.onDraw(canvas);
    verify(canvas).drawWidget(widget2);
    // Switch to widget3
    cardLayout.setDisplayedCard("widget3");
    cardLayout.onDraw(canvas);
    verify(canvas).drawWidget(widget3);
}
Also used : Vector2i(org.joml.Vector2i) Test(org.junit.jupiter.api.Test)

Example 4 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class CardLayoutTest method setup.

@BeforeEach
public void setup() {
    cardLayout = new CardLayout();
    widget1 = mock(UIWidget.class);
    widget2 = mock(UIWidget.class);
    widget3 = mock(UIWidget.class);
    canvas = mock(Canvas.class);
    // +-----------------------------------+  +---+  +-------+
    // |                                   |  |1x2|  |       |
    // |               1x1                 |  +---+  |       |
    // |                                   |         |  1x3  |
    // +-----------------------------------+         |       |
    // |       |
    // +-------+
    when(widget1.getPreferredContentSize(eq(canvas), any(Vector2i.class))).thenReturn(new Vector2i(50, 10));
    when(widget2.getPreferredContentSize(eq(canvas), any(Vector2i.class))).thenReturn(new Vector2i(5, 5));
    when(widget3.getPreferredContentSize(eq(canvas), any(Vector2i.class))).thenReturn(new Vector2i(10, 15));
    when(widget1.getId()).thenReturn("widget1");
    when(widget2.getId()).thenReturn("widget2");
    when(widget3.getId()).thenReturn("widget3");
    Vector2i availableSize = new Vector2i(200, 200);
    when(canvas.size()).thenReturn(availableSize);
    cardLayout.addWidget(widget1);
    cardLayout.addWidget(widget2);
    cardLayout.addWidget(widget3);
}
Also used : CardLayout(org.terasology.nui.layouts.CardLayout) Canvas(org.terasology.nui.Canvas) Vector2i(org.joml.Vector2i) UIWidget(org.terasology.nui.UIWidget) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class ColumnLayoutTest method testThreeColumnsProportionallySized.

@Test
public void testThreeColumnsProportionallySized() throws Exception {
    columnLayout.setAutoSizeColumns(false);
    columnLayout.setFillVerticalSpace(false);
    columnLayout.setColumnWidths(0.5f, 0.2f, 0.3f);
    Vector2i result = columnLayout.getPreferredContentSize(canvas, canvas.size());
    // This is the size of the first column divided by its ratio.
    // In general, the minimum column size / ratio guarantees the ration
    // and insures that every column has at least as much as its preferred size
    assertEquals(100, result.x);
    assertEquals(20, result.y);
    columnLayout.onDraw(canvas);
    // Gets half of entire area
    verify(canvas).drawWidget(itemAt1x1, RectUtility.createFromMinAndSize(0, ((CANVAS_HEIGHT - 20) / 2), CANVAS_WIDTH / 2, 10));
    // Gets one-fifth of entire area
    verify(canvas).drawWidget(itemAt2x1, RectUtility.createFromMinAndSize(CANVAS_WIDTH / 2, ((CANVAS_HEIGHT - 20) / 2), CANVAS_WIDTH * 2 / 10, 10));
    // Gets three-tens of entire area
    verify(canvas).drawWidget(itemAt3x1, RectUtility.createFromMinAndSize(CANVAS_WIDTH / 2 + CANVAS_WIDTH * 2 / 10, ((CANVAS_HEIGHT - 20) / 2), CANVAS_WIDTH * 3 / 10, 10));
    // Gets half of entire area
    verify(canvas).drawWidget(itemAt1x2, RectUtility.createFromMinAndSize(0, ((CANVAS_HEIGHT - 20) / 2) + 10, CANVAS_WIDTH / 2, 10));
    // Gets one-fifth of entire area
    verify(canvas).drawWidget(itemAt2x2, RectUtility.createFromMinAndSize(CANVAS_WIDTH / 2, ((CANVAS_HEIGHT - 20) / 2) + 10, CANVAS_WIDTH * 2 / 10, 10));
    // Gets three-tens of entire area
    verify(canvas).drawWidget(itemAt3x2, RectUtility.createFromMinAndSize(CANVAS_WIDTH / 2 + CANVAS_WIDTH * 2 / 10, ((CANVAS_HEIGHT - 20) / 2) + 10, CANVAS_WIDTH * 3 / 10, 10));
}
Also used : Vector2i(org.joml.Vector2i) Test(org.junit.jupiter.api.Test)

Aggregations

Vector2i (org.joml.Vector2i)41 Test (org.junit.jupiter.api.Test)12 Rectanglei (org.terasology.joml.geom.Rectanglei)9 Canvas (org.terasology.nui.Canvas)9 UILabel (org.terasology.nui.widgets.UILabel)6 List (java.util.List)5 Objects (java.util.Objects)5 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)5 Vector2f (org.joml.Vector2f)4 Vector2ic (org.joml.Vector2ic)4 Module (org.terasology.gestalt.module.Module)4 Name (org.terasology.gestalt.naming.Name)4 UIButton (org.terasology.nui.widgets.UIButton)4 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Collection (java.util.Collection)3 Comparator (java.util.Comparator)3 Iterator (java.util.Iterator)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3