Refactor Widget
This commit is contained in:
@@ -3,11 +3,8 @@ package com.bartlomiejpluta.base.api.game.gui;
|
||||
public abstract class Component implements Widget {
|
||||
protected Widget parent;
|
||||
|
||||
protected float absX;
|
||||
protected float absY;
|
||||
|
||||
protected float width;
|
||||
protected float height;
|
||||
protected float x;
|
||||
protected float y;
|
||||
|
||||
protected float marginTop;
|
||||
protected float marginRight;
|
||||
@@ -29,43 +26,29 @@ public abstract class Component implements Widget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAbsoluteX() {
|
||||
return absX;
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAbsoluteY() {
|
||||
return absY;
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAbsoluteX(float x) {
|
||||
this.absX = x;
|
||||
public void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAbsoluteY(float y) {
|
||||
this.absY = y;
|
||||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeight(float height) {
|
||||
this.height = height;
|
||||
public void setPosition(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,14 +31,14 @@ public class HBox extends Container {
|
||||
|
||||
@Override
|
||||
public void draw(Screen screen, GUI gui) {
|
||||
var currentX = absX + paddingLeft;
|
||||
var currentY = absY + paddingTop;
|
||||
var currentX = x + paddingLeft;
|
||||
var currentY = y + paddingTop;
|
||||
|
||||
for (var child : children) {
|
||||
var childAbsX = currentX + child.getMarginLeft();
|
||||
var childAbsY = currentY + child.getMarginTop();
|
||||
child.setAbsoluteX(childAbsX);
|
||||
child.setAbsoluteY(childAbsY);
|
||||
child.setX(childAbsX);
|
||||
child.setY(childAbsY);
|
||||
|
||||
currentX += child.getMarginLeft() + child.getWidth() + child.getMarginRight();
|
||||
|
||||
|
||||
@@ -31,14 +31,14 @@ public class VBox extends Container {
|
||||
|
||||
@Override
|
||||
public void draw(Screen screen, GUI gui) {
|
||||
var currentX = absX + paddingLeft;
|
||||
var currentY = absY + paddingTop;
|
||||
var currentX = x + paddingLeft;
|
||||
var currentY = y + paddingTop;
|
||||
|
||||
for (var child : children) {
|
||||
var childAbsX = currentX + child.getMarginLeft();
|
||||
var childAbsY = currentY + child.getMarginTop();
|
||||
child.setAbsoluteX(childAbsX);
|
||||
child.setAbsoluteY(childAbsY);
|
||||
child.setX(childAbsX);
|
||||
child.setY(childAbsY);
|
||||
|
||||
currentY += child.getMarginTop() + child.getHeight() + child.getMarginBottom();
|
||||
|
||||
|
||||
@@ -5,22 +5,20 @@ import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
public interface Widget {
|
||||
Widget getParent();
|
||||
|
||||
float getAbsoluteX();
|
||||
float getX();
|
||||
|
||||
float getAbsoluteY();
|
||||
float getY();
|
||||
|
||||
void setAbsoluteX(float x);
|
||||
void setX(float x);
|
||||
|
||||
void setAbsoluteY(float y);
|
||||
void setY(float y);
|
||||
|
||||
void setPosition(float x, float y);
|
||||
|
||||
float getWidth();
|
||||
|
||||
float getHeight();
|
||||
|
||||
void setWidth(float width);
|
||||
|
||||
void setHeight(float height);
|
||||
|
||||
void setMargin(float top, float right, float bottom, float left);
|
||||
|
||||
void setMargin(float top, float rightLeft, float bottom);
|
||||
|
||||
Reference in New Issue
Block a user