summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2019-12-16 12:19:40 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2019-12-16 12:19:40 +0100
commit5a8a247bb5e2889514daf01c848cbab9ad5f4c31 (patch)
tree08ac2066cd6283dd2e03fcb7ff48007f9b7a0bc6 /core/src/ch/asynk
parentb3e854d1d35e890fba2b6cea269d58e09581c119 (diff)
downloadgdx-boardgame-5a8a247bb5e2889514daf01c848cbab9ad5f4c31.zip
gdx-boardgame-5a8a247bb5e2889514daf01c848cbab9ad5f4c31.tar.gz
ui.Element : add taintParent boolean to propagate taint state up the UI tree
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Button.java2
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Element.java11
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Label.java2
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Menu.java10
4 files changed, 14 insertions, 11 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Button.java b/core/src/ch/asynk/gdx/boardgame/ui/Button.java
index 9bc1149..2b1638b 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Button.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Button.java
@@ -33,7 +33,7 @@ public class Button extends Patch
public void write(String text)
{
label.write(text);
- this.tainted = true; // might impact Button's geometry
+ taint(); // might impact Button's geometry
}
public void setLabelAlignment(Alignment alignment)
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Element.java b/core/src/ch/asynk/gdx/boardgame/ui/Element.java
index abefdd5..e1f9850 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Element.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Element.java
@@ -18,6 +18,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
protected Rectangle rect; // outer drawing coordinates
protected float x, y; // given position
protected boolean tainted; // geometry must be computed
+ protected boolean taintParent; // propagate tainted state up the tree
protected Element()
{
@@ -29,6 +30,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
this.rect = new Rectangle(0, 0, 0, 0);
this.x = this.y = 0;
this.tainted = true;
+ this.taintParent= false;
}
@Override public final float getX() { return rect.x; }
@@ -55,6 +57,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
public void taint()
{
this.tainted = true;
+ if (parent != null && taintParent) parent.taint();
}
@Override public void setPosition(float x, float y, float w, float h)
@@ -63,26 +66,26 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
this.y = y;
this.rect.width = w;
this.rect.height = h;
- this.tainted = true;
+ taint();
// rect.(x,y) will be set in computeGeometry
}
public void setParent(Element parent)
{
this.parent = parent;
- this.tainted = true;
+ taint();
}
@Override public void setPadding(float padding)
{
this.padding = padding;
- this.tainted = true;
+ taint();
}
public void setAlignment(Alignment alignment)
{
this.alignment = alignment;
- this.tainted = true;
+ taint();
}
@Override public final void centerOn(float cx, float cy)
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Label.java b/core/src/ch/asynk/gdx/boardgame/ui/Label.java
index 32ae814..68701ce 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Label.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Label.java
@@ -40,7 +40,7 @@ public class Label extends Element
{
this.text = text;
this.layout.setText(font, (text == null) ? "" : text);
- this.tainted = true;
+ taint();
}
@Override protected void computeGeometry()
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Menu.java b/core/src/ch/asynk/gdx/boardgame/ui/Menu.java
index aa62483..68f65c5 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Menu.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Menu.java
@@ -26,7 +26,7 @@ public class Menu extends Patch
{
this.title = new Label(font);
this.title.write(title);
- this.tainted = true;
+ taint();
}
public void setEntries(BitmapFont font, String[] entries)
@@ -37,13 +37,13 @@ public class Menu extends Patch
l.write(entries[i]);
this.entries[i] = l;
}
- this.tainted = true;
+ taint();
}
public void setLabelsOffset(int entriesOffset)
{
this.entriesOffset = entriesOffset;
- this.tainted = true;
+ taint();
}
public void setPaddings(int titlePadding, int labelPadding)
@@ -52,14 +52,14 @@ public class Menu extends Patch
for (Label label : entries) {
label.setPadding(labelPadding);
}
- this.tainted = true;
+ taint();
}
public void setSpacings(int titleSpacing, int entriesSpacing)
{
this.titleSpacing = titleSpacing;
this.entriesSpacing = entriesSpacing;
- this.tainted = true;
+ taint();
}
@Override public void computeGeometry()