Create Size Mode which includes modes: NORMAL, WRAP_CONTENT and MATCH_PARENT
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui.base;
|
||||
|
||||
public enum SizeMode {
|
||||
NORMAL,
|
||||
MATCH_PARENT,
|
||||
WRAP_CONTENT
|
||||
}
|
||||
@@ -19,6 +19,22 @@ public interface Widget {
|
||||
|
||||
float getHeight();
|
||||
|
||||
void setWidth(float width);
|
||||
|
||||
void setHeight(float height);
|
||||
|
||||
void setSize(float width, float height);
|
||||
|
||||
SizeMode getWidthMode();
|
||||
|
||||
void setWidthMode(SizeMode mode);
|
||||
|
||||
SizeMode getHeightMode();
|
||||
|
||||
void setHeightMode(SizeMode mode);
|
||||
|
||||
void setSizeMode(SizeMode widthMode, SizeMode heightMode);
|
||||
|
||||
void setMargin(float top, float right, float bottom, float left);
|
||||
|
||||
void setMargin(float top, float rightLeft, float bottom);
|
||||
|
||||
@@ -22,7 +22,7 @@ public abstract class BaseContainer extends Component implements Container {
|
||||
var theWidestChild = 0.0f;
|
||||
|
||||
for (var child : children) {
|
||||
var width = child.getMarginLeft() + child.getWidth() + child.getMarginRight();
|
||||
var width = child.getMarginLeft() + child.getActualWidth() + child.getMarginRight();
|
||||
if (width > theWidestChild) {
|
||||
theWidestChild = width;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public abstract class BaseContainer extends Component implements Container {
|
||||
var theHighestChild = 0.0f;
|
||||
|
||||
for (var child : children) {
|
||||
var height = child.getMarginTop() + child.getHeight() + child.getMarginBottom();
|
||||
var height = child.getMarginTop() + child.getActualHeight() + child.getMarginBottom();
|
||||
if (height > theHighestChild) {
|
||||
theHighestChild = height;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.SizeMode;
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
||||
|
||||
public abstract class Component implements Widget {
|
||||
protected Widget parent;
|
||||
|
||||
protected SizeMode widthMode = SizeMode.NORMAL;
|
||||
protected SizeMode heightMode = SizeMode.NORMAL;
|
||||
|
||||
protected float x;
|
||||
protected float y;
|
||||
|
||||
protected float width;
|
||||
protected float height;
|
||||
|
||||
protected float marginTop;
|
||||
protected float marginRight;
|
||||
protected float marginBottom;
|
||||
@@ -18,6 +25,74 @@ public abstract class Component implements Widget {
|
||||
protected float paddingBottom;
|
||||
protected float paddingLeft;
|
||||
|
||||
protected abstract float getContentWidth();
|
||||
|
||||
protected abstract float getContentHeight();
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
return widthMode == SizeMode.MATCH_PARENT
|
||||
? (parent != null ? parent.getWidth() : 0)
|
||||
: getActualWidth();
|
||||
}
|
||||
|
||||
protected float getActualWidth() {
|
||||
return paddingLeft + (widthMode == SizeMode.NORMAL ? width : getContentWidth()) + paddingRight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
return heightMode == SizeMode.MATCH_PARENT
|
||||
? (parent != null ? parent.getHeight() : 0)
|
||||
: getActualHeight();
|
||||
}
|
||||
|
||||
protected float getActualHeight() {
|
||||
return paddingTop + (heightMode == SizeMode.NORMAL ? height : getContentHeight()) + paddingBottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeight(float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(float width, float height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSizeMode(SizeMode widthMode, SizeMode heightMode) {
|
||||
this.widthMode = widthMode;
|
||||
this.heightMode = heightMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SizeMode getWidthMode() {
|
||||
return widthMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidthMode(SizeMode mode) {
|
||||
this.widthMode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SizeMode getHeightMode() {
|
||||
return heightMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeightMode(SizeMode mode) {
|
||||
this.heightMode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Widget getParent() {
|
||||
return parent;
|
||||
|
||||
@@ -6,13 +6,13 @@ import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
public class HLayout extends BaseContainer {
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
return paddingLeft + sumChildrenWidth() + paddingRight;
|
||||
protected float getContentWidth() {
|
||||
return sumChildrenWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
return paddingTop + maxChildrenHeight() + paddingBottom;
|
||||
protected float getContentHeight() {
|
||||
return maxChildrenHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,13 +6,13 @@ import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
public class VLayout extends BaseContainer {
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
return paddingLeft + maxChildrenWidth() + paddingRight;
|
||||
protected float getContentWidth() {
|
||||
return maxChildrenWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
return paddingTop + sumChildrenHeight() + paddingBottom;
|
||||
protected float getContentHeight() {
|
||||
return sumChildrenHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user