summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-05-18 17:03:24 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-05-18 17:03:24 +0200
commit0a63636e8e5ef6ebcae056e3cf2194a7792d228f (patch)
tree85fbdf7435df571620ad6866040bace04025f34e /core
parentc39bdc63b1911dcc3b7c827af38e4a026d1ab22e (diff)
downloadgdx-boardgame-0a63636e8e5ef6ebcae056e3cf2194a7792d228f.zip
gdx-boardgame-0a63636e8e5ef6ebcae056e3cf2194a7792d228f.tar.gz
ui : support Container.Pack.BEGIN/END
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Container.java23
1 files changed, 16 insertions, 7 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Container.java b/core/src/ch/asynk/gdx/boardgame/ui/Container.java
index 7275711..c9cff4e 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Container.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Container.java
@@ -10,9 +10,11 @@ public class Container extends Element
{
public static int DEFAULT_CHILD_COUNT = 2;
+ public enum Pack { BEGIN, END };
public enum Direction { FREE, HORIZONTAL, VERTICAL };
protected float spacing;
+ protected Pack pack;
protected Direction direction;
protected IterableSet<Element> children;
private Rectangle subArea;
@@ -32,6 +34,12 @@ public class Container extends Element
taint();
}
+ public void setPacking(Pack pack)
+ {
+ this.pack = pack;
+ taint();
+ }
+
public void setDirection(Direction direction)
{
this.direction = direction;
@@ -73,18 +81,18 @@ public class Container extends Element
};
float f = (area.width - c) / m;
subArea.set(area);
- subArea.x += subArea.width;
- subArea.width = 0;
+ boolean end = (pack == Pack.END);
+ if (end) subArea.x += subArea.width;
for (Element e : children) {
float available = e.rect.width;
if (Sizing.contains(e.sizing, Sizing.EXPAND_X))
available += f;
- subArea.x -= available;
subArea.width = available;
+ if (end) subArea.x -= available;
e.computeGeometry(subArea, true);
+ if (!end) subArea.x += available;
}
} else if (direction == Direction.VERTICAL) {
- // packs at the begining
int n = children.size();
int m = 0;
int c = 0;
@@ -95,15 +103,16 @@ public class Container extends Element
};
float f = (area.height - c) / m;
subArea.set(area);
- subArea.y += subArea.height;
- subArea.height = 0;
+ boolean begin = (pack == Pack.BEGIN);
+ if (begin) subArea.y += subArea.height;
for (Element e : children) {
float available = e.rect.height;
if (Sizing.contains(e.sizing, Sizing.EXPAND_Y))
available += f;
- subArea.y -= available;
subArea.height = available;
+ if (begin) subArea.y -= available;
e.computeGeometry(subArea, true);
+ if (!begin) subArea.y += available;
}
} else {
children.forEach( c -> c.computeGeometry(area, resized) );