Skip to content

Commit

Permalink
Modified FlexBoxTest to emulate the appearance of the Yoga Playground.
Browse files Browse the repository at this point in the history
  • Loading branch information
raeleus committed Sep 4, 2022
1 parent 9b74a2d commit 21a215f
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/test/java/dev/lyze/flexbox/FlexBoxTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package dev.lyze.flexbox;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.kotcrab.vis.ui.VisUI;
Expand All @@ -14,6 +16,11 @@
import io.github.orioncraftmc.meditate.enums.YogaFlexDirection;
import io.github.orioncraftmc.meditate.enums.YogaWrap;

/**
* This test demonstrates the use of FlexBox directly in a {@link Stage Stage}. This emulates the layout of the
* <a href="https://yogalayout.com/playground/">Yoga Playground</a> Press LEFT CLICK to add a new element. Press RIGHT
* CLICK to remove an element.
*/
public class FlexBoxTest extends ApplicationAdapter {
private Stage stage;
private FlexBox flexBox;
Expand All @@ -31,21 +38,19 @@ public void create() {
stage = new Stage(new ScreenViewport());
stage.setDebugAll(true);

Table table = new Table();
table.setFillParent(true);
table.add(new VisLabel("TABLE"));

flexBox = new FlexBox();
flexBox.setFillParent(true);
flexBox.getRoot().setFlexDirection(YogaFlexDirection.ROW);
flexBox.getRoot().setWrap(YogaWrap.WRAP);
stage.addActor(flexBox);

for (int i = 0; i < 3; i++) {
YogaNode node = flexBox.add(new VisLabel("Item " + i));
node.setWidth(400);
for (int i = 1; i < 4; i++) {
VisLabel label = new VisLabel(Integer.toString(i));
label.setAlignment(Align.center);
YogaNode node = flexBox.add(label);
node.setWidth(100);
node.setHeight(100);
}

table.add(flexBox);
stage.addActor(table);
}

@Override
Expand All @@ -54,6 +59,20 @@ public void render() {

stage.act();
stage.draw();

if (Gdx.input.isButtonJustPressed(Buttons.LEFT)) {
VisLabel label = new VisLabel(Integer.toString(flexBox.getChildren().size + 1));
label.setAlignment(Align.center);
YogaNode node = flexBox.add(label);
node.setWidth(100);
node.setHeight(100);
}

if (Gdx.input.isButtonJustPressed(Buttons.RIGHT)) {
if (flexBox.getChildren().size > 0) {
flexBox.remove(flexBox.getRoot().getChildAt(flexBox.getChildren().size - 1));
}
}
}

@Override
Expand Down

0 comments on commit 21a215f

Please sign in to comment.