Create working scaffolding of Component Inflater
This commit is contained in:
@@ -53,17 +53,17 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(float width) {
|
||||
public void setWidth(Float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeight(float height) {
|
||||
public void setHeight(Float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(float width, float height) {
|
||||
public void setSize(Float width, Float height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
@@ -115,23 +115,23 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setX(float x) {
|
||||
public void setX(Float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setY(float y) {
|
||||
public void setY(Float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(float x, float y) {
|
||||
public void setPosition(Float x, Float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMargin(float top, float right, float bottom, float left) {
|
||||
public void setMargin(Float top, Float right, Float bottom, Float left) {
|
||||
this.marginTop = top;
|
||||
this.marginRight = right;
|
||||
this.marginBottom = bottom;
|
||||
@@ -139,7 +139,7 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMargin(float top, float rightLeft, float bottom) {
|
||||
public void setMargin(Float top, Float rightLeft, Float bottom) {
|
||||
this.marginTop = top;
|
||||
this.marginRight = rightLeft;
|
||||
this.marginBottom = bottom;
|
||||
@@ -147,7 +147,7 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMargin(float topBottom, float rightLeft) {
|
||||
public void setMargin(Float topBottom, Float rightLeft) {
|
||||
this.marginTop = topBottom;
|
||||
this.marginRight = rightLeft;
|
||||
this.marginBottom = topBottom;
|
||||
@@ -155,7 +155,7 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMargin(float all) {
|
||||
public void setMargin(Float all) {
|
||||
this.marginTop = all;
|
||||
this.marginRight = all;
|
||||
this.marginBottom = all;
|
||||
@@ -163,22 +163,22 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMarginTop(float margin) {
|
||||
public void setMarginTop(Float margin) {
|
||||
this.marginTop = margin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMarginRight(float margin) {
|
||||
public void setMarginRight(Float margin) {
|
||||
this.marginRight = margin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMarginBottom(float margin) {
|
||||
public void setMarginBottom(Float margin) {
|
||||
this.marginBottom = margin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMarginLeft(float margin) {
|
||||
public void setMarginLeft(Float margin) {
|
||||
this.marginLeft = margin;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPadding(float top, float right, float bottom, float left) {
|
||||
public void setPadding(Float top, Float right, Float bottom, Float left) {
|
||||
this.paddingTop = top;
|
||||
this.paddingRight = right;
|
||||
this.paddingBottom = bottom;
|
||||
@@ -211,7 +211,7 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPadding(float top, float rightLeft, float bottom) {
|
||||
public void setPadding(Float top, Float rightLeft, Float bottom) {
|
||||
this.paddingTop = top;
|
||||
this.paddingRight = rightLeft;
|
||||
this.paddingBottom = bottom;
|
||||
@@ -219,7 +219,7 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPadding(float topBottom, float rightLeft) {
|
||||
public void setPadding(Float topBottom, Float rightLeft) {
|
||||
this.paddingTop = topBottom;
|
||||
this.paddingRight = rightLeft;
|
||||
this.paddingBottom = topBottom;
|
||||
@@ -227,7 +227,7 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPadding(float all) {
|
||||
public void setPadding(Float all) {
|
||||
this.paddingTop = all;
|
||||
this.paddingRight = all;
|
||||
this.paddingBottom = all;
|
||||
@@ -235,22 +235,22 @@ public abstract class BaseWidget implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaddingTop(float padding) {
|
||||
public void setPaddingTop(Float padding) {
|
||||
this.paddingTop = padding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaddingRight(float padding) {
|
||||
public void setPaddingRight(Float padding) {
|
||||
this.paddingRight = padding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaddingBottom(float padding) {
|
||||
public void setPaddingBottom(Float padding) {
|
||||
this.paddingBottom = padding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaddingLeft(float padding) {
|
||||
public void setPaddingLeft(Float padding) {
|
||||
this.paddingLeft = padding;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@ public interface Widget extends KeyEventHandler {
|
||||
|
||||
float getY();
|
||||
|
||||
void setX(float x);
|
||||
void setX(Float x);
|
||||
|
||||
void setY(float y);
|
||||
void setY(Float y);
|
||||
|
||||
void setPosition(float x, float y);
|
||||
void setPosition(Float x, Float y);
|
||||
|
||||
float getWidth();
|
||||
|
||||
@@ -26,11 +26,11 @@ public interface Widget extends KeyEventHandler {
|
||||
|
||||
float getActualHeight();
|
||||
|
||||
void setWidth(float width);
|
||||
void setWidth(Float width);
|
||||
|
||||
void setHeight(float height);
|
||||
void setHeight(Float height);
|
||||
|
||||
void setSize(float width, float height);
|
||||
void setSize(Float width, Float height);
|
||||
|
||||
SizeMode getWidthMode();
|
||||
|
||||
@@ -42,21 +42,21 @@ public interface Widget extends KeyEventHandler {
|
||||
|
||||
void setSizeMode(SizeMode widthMode, SizeMode heightMode);
|
||||
|
||||
void setMargin(float top, float right, float bottom, float left);
|
||||
void setMargin(Float top, Float right, Float bottom, Float left);
|
||||
|
||||
void setMargin(float top, float rightLeft, float bottom);
|
||||
void setMargin(Float top, Float rightLeft, Float bottom);
|
||||
|
||||
void setMargin(float topBottom, float rightLeft);
|
||||
void setMargin(Float topBottom, Float rightLeft);
|
||||
|
||||
void setMargin(float all);
|
||||
void setMargin(Float all);
|
||||
|
||||
void setMarginTop(float margin);
|
||||
void setMarginTop(Float margin);
|
||||
|
||||
void setMarginRight(float margin);
|
||||
void setMarginRight(Float margin);
|
||||
|
||||
void setMarginBottom(float margin);
|
||||
void setMarginBottom(Float margin);
|
||||
|
||||
void setMarginLeft(float margin);
|
||||
void setMarginLeft(Float margin);
|
||||
|
||||
float getMarginTop();
|
||||
|
||||
@@ -66,21 +66,21 @@ public interface Widget extends KeyEventHandler {
|
||||
|
||||
float getMarginLeft();
|
||||
|
||||
void setPadding(float top, float right, float bottom, float left);
|
||||
void setPadding(Float top, Float right, Float bottom, Float left);
|
||||
|
||||
void setPadding(float top, float rightLeft, float bottom);
|
||||
void setPadding(Float top, Float rightLeft, Float bottom);
|
||||
|
||||
void setPadding(float topBottom, float rightLeft);
|
||||
void setPadding(Float topBottom, Float rightLeft);
|
||||
|
||||
void setPadding(float all);
|
||||
void setPadding(Float all);
|
||||
|
||||
void setPaddingTop(float padding);
|
||||
void setPaddingTop(Float padding);
|
||||
|
||||
void setPaddingRight(float padding);
|
||||
void setPaddingRight(Float padding);
|
||||
|
||||
void setPaddingBottom(float padding);
|
||||
void setPaddingBottom(Float padding);
|
||||
|
||||
void setPaddingLeft(float padding);
|
||||
void setPaddingLeft(Float padding);
|
||||
|
||||
float getPaddingTop();
|
||||
|
||||
|
||||
@@ -2,9 +2,26 @@ package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.BaseWidget;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
public abstract class BaseComponent extends BaseWidget implements Component {
|
||||
protected boolean focused;
|
||||
|
||||
@Override
|
||||
public Iterable<Component> getChildren() {
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Component component) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Component component) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFocused() {
|
||||
return focused;
|
||||
|
||||
@@ -5,8 +5,16 @@ import com.bartlomiejpluta.base.api.game.input.KeyEvent;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
public abstract class BaseContainer extends BaseComponent implements Container {
|
||||
protected final List<Component> children = new LinkedList<>();
|
||||
private final List<Component> readOnlyChildren = unmodifiableList(children);
|
||||
|
||||
@Override
|
||||
public Iterable<Component> getChildren() {
|
||||
return readOnlyChildren;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Component component) {
|
||||
|
||||
@@ -3,6 +3,12 @@ package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
||||
|
||||
public interface Component extends Widget {
|
||||
Iterable<Component> getChildren();
|
||||
|
||||
void add(Component component);
|
||||
|
||||
void remove(Component component);
|
||||
|
||||
boolean isFocused();
|
||||
|
||||
void focus();
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
|
||||
public interface Container extends Component {
|
||||
void add(Component component);
|
||||
|
||||
void remove(Component component);
|
||||
}
|
||||
|
||||
@@ -7,23 +7,27 @@ import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public class Label extends BaseComponent {
|
||||
private final GUI gui;
|
||||
// private final GUI gui;
|
||||
|
||||
private String text = "";
|
||||
private String font;
|
||||
private float fontSize;
|
||||
private int alignment = GUI.ALIGN_LEFT;
|
||||
private final Color color;
|
||||
private Color color;
|
||||
|
||||
private final float[] bounds = new float[4];
|
||||
|
||||
public Label(GUI gui, String font) {
|
||||
this.gui = requireNonNull(gui);
|
||||
this.font = requireNonNull(font);
|
||||
public Label() {
|
||||
|
||||
this.color = this.gui.createColor();
|
||||
}
|
||||
|
||||
// public Label(GUI gui, String font) {
|
||||
// this.gui = requireNonNull(gui);
|
||||
// this.font = requireNonNull(font);
|
||||
//
|
||||
// this.color = this.gui.createColor();
|
||||
// }
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
@@ -44,7 +48,7 @@ public class Label extends BaseComponent {
|
||||
return fontSize;
|
||||
}
|
||||
|
||||
public void setFontSize(float fontSize) {
|
||||
public void setFontSize(Float fontSize) {
|
||||
this.fontSize = fontSize;
|
||||
}
|
||||
|
||||
@@ -52,7 +56,7 @@ public class Label extends BaseComponent {
|
||||
return alignment;
|
||||
}
|
||||
|
||||
public void setAlignment(int alignment) {
|
||||
public void setAlignment(Integer alignment) {
|
||||
this.alignment = alignment;
|
||||
}
|
||||
|
||||
@@ -60,7 +64,7 @@ public class Label extends BaseComponent {
|
||||
return color.getRed();
|
||||
}
|
||||
|
||||
public void setRed(float value) {
|
||||
public void setRed(Float value) {
|
||||
color.setRed(value);
|
||||
}
|
||||
|
||||
@@ -68,7 +72,7 @@ public class Label extends BaseComponent {
|
||||
return color.getGreen();
|
||||
}
|
||||
|
||||
public void setGreen(float value) {
|
||||
public void setGreen(Float value) {
|
||||
color.setGreen(value);
|
||||
}
|
||||
|
||||
@@ -76,7 +80,7 @@ public class Label extends BaseComponent {
|
||||
return color.getBlue();
|
||||
}
|
||||
|
||||
public void setBlue(float value) {
|
||||
public void setBlue(Float value) {
|
||||
color.setBlue(value);
|
||||
}
|
||||
|
||||
@@ -84,15 +88,15 @@ public class Label extends BaseComponent {
|
||||
return color.getAlpha();
|
||||
}
|
||||
|
||||
public void setAlpha(float value) {
|
||||
public void setAlpha(Float value) {
|
||||
color.setAlpha(value);
|
||||
}
|
||||
|
||||
public void setColor(float red, float green, float blue, float alpha) {
|
||||
public void setColor(Float red, Float green, Float blue, Float alpha) {
|
||||
color.setRGBA(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
public void setColor(float red, float green, float blue) {
|
||||
public void setColor(Float red, Float green, Float blue) {
|
||||
color.setRGB(red, green, blue);
|
||||
}
|
||||
|
||||
@@ -116,4 +120,9 @@ public class Label extends BaseComponent {
|
||||
gui.fill();
|
||||
gui.putTextBox(x + paddingLeft, y + paddingTop, getWidth() - paddingLeft - paddingRight, text, bounds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Label[" + text + "]";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user