summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2019-12-17 12:20:29 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2019-12-17 12:20:46 +0100
commitf2fef564a73139d31344b7a89856196d60a49ba2 (patch)
tree3feaf587a99dc35974b9a795a0785c1d1deeabea /core/src/ch/asynk
parentb9f8b1d6b136d565cd0a8e18040eaff621a91c4d (diff)
downloadgdx-boardgame-f2fef564a73139d31344b7a89856196d60a49ba2.zip
gdx-boardgame-f2fef564a73139d31344b7a89856196d60a49ba2.tar.gz
Menu : use relative positioning instead of absolute
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Menu.java26
1 files changed, 12 insertions, 14 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Menu.java b/core/src/ch/asynk/gdx/boardgame/ui/Menu.java
index 68f65c5..243b000 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Menu.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Menu.java
@@ -26,6 +26,7 @@ public class Menu extends Patch
{
this.title = new Label(font);
this.title.write(title);
+ this.title.setParent(this);
taint();
}
@@ -35,6 +36,7 @@ public class Menu extends Patch
for (int i = 0; i < entries.length; i++) {
Label l = new Label(font);
l.write(entries[i]);
+ l.setParent(this);
this.entries[i] = l;
}
taint();
@@ -64,6 +66,7 @@ public class Menu extends Patch
@Override public void computeGeometry()
{
+ // compute width and height
title.computeGeometry();
float h = title.getHeight();
float w = title.getWidth();
@@ -74,24 +77,19 @@ public class Menu extends Patch
if (t > w)
w = t;
}
- h += (titleSpacing + (entriesSpacing * (entries.length - 1)) + (2 * padding));
- w += (2 * padding);
+ rect.width = w + (2 * padding);
+ rect.height = h + (titleSpacing + (entriesSpacing * (entries.length - 1)) + (2 * padding));
- rect.width = w;
- rect.height = h;
+ // compute position
super.computeGeometry();
- float x = getInnerX();
- float y = getInnerY();
-
- // setPosition() will trigger computeGeometry() from within draw()
- for (int i = entries.length - 1; i >= 0; i--) {
- entries[i].setPosition(x + entriesOffset, y);
- y += entries[i].getHeight() + entriesSpacing;
+ float y = - title.getHeight() - padding;
+ title.setPosition(0, y);
+ y -= titleSpacing;
+ for (Label l : entries) {
+ l.setPosition(x + entriesOffset, y - l.getHeight());
+ y -= (l.getHeight() + entriesSpacing);
}
- y -= entriesSpacing;
- y += titleSpacing;
- title.setPosition(x, y);
}
public Integer touched()