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()));
}
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));
}
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);
}
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);
}
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));
}
Aggregations