diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2019-12-18 23:13:52 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2019-12-18 23:13:52 +0100 |
commit | ce231dbc3207237adc43f0290061d067b45da6e4 (patch) | |
tree | 771e496af7fe6f52ee3332292c7373ed8c562f9a | |
parent | d15476388238f178e0062b50292a27f2984661a6 (diff) | |
download | gdx-boardgame-ce231dbc3207237adc43f0290061d067b45da6e4.zip gdx-boardgame-ce231dbc3207237adc43f0290061d067b45da6e4.tar.gz |
UiScreen : add Scrollable test
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/UiScreen.java | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java b/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java index cb5d164..e8aea09 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java @@ -14,6 +14,7 @@ import ch.asynk.gdx.boardgame.ui.Label; import ch.asynk.gdx.boardgame.ui.List; import ch.asynk.gdx.boardgame.ui.Patch; import ch.asynk.gdx.boardgame.ui.Scissors; +import ch.asynk.gdx.boardgame.ui.Scrollable; import ch.asynk.gdx.boardgame.utils.Collection; import ch.asynk.gdx.boardgame.utils.IterableArray; @@ -159,6 +160,7 @@ class MyButton extends Button class MyList extends Patch { private Label title; + private Scrollable scrollable; private List list; class Item implements List.Item @@ -186,34 +188,34 @@ class MyList extends Patch } this.list = new List(font, textureRegion, 10, 15); this.list.setItems(items); - this.list.setParent(this); + + this.scrollable = new Scrollable(this.list); + this.scrollable.setParent(this); + this.scrollable.hScroll = true; } @Override public void computeGeometry() { - float pp = (2 * padding); - // update dimensions title.computeGeometry(); - list.computeGeometry(); - rect.width = title.getWidth() + pp; - rect.height = title.getHeight() + pp + list.getHeight() + 15; - if ((list.getWidth() + pp) > rect.width) rect.width = list.getWidth() + pp; + scrollable.computeGeometry(); + rect.height = 300; + rect.width = scrollable.getBestWidth() + (2 * padding) - 100; // update position super.computeGeometry(); title.computeGeometry(); - list.computeGeometry(); + scrollable.setPosition(getInnerX(), getInnerY(), getInnerWidth(), getInnerHeight() - title.getHeight() - 15); } @Override public boolean touch(float x, float y) { - if (super.touch(x, y)) { - if (list.touch(x, y)) { - return true; - } - } - return false; + return scrollable.touch(x, y); + } + + @Override public boolean drag(float x, float y, int dx, int dy) + { + return scrollable.drag(x, y, dx, dy); } @Override public void draw(Batch batch) @@ -222,7 +224,7 @@ class MyList extends Patch if (tainted) computeGeometry(); super.draw(batch); title.draw(batch); - list.draw(batch); + scrollable.draw(batch); } @Override public void drawDebug(ShapeRenderer shapeRenderer) @@ -230,6 +232,6 @@ class MyList extends Patch if (!visible) return; super.drawDebug(shapeRenderer); title.drawDebug(shapeRenderer); - list.drawDebug(shapeRenderer); + scrollable.drawDebug(shapeRenderer); } } |