Create RELATIVE size mode and rename other size modes
This commit is contained in:
@@ -5,8 +5,8 @@ import com.bartlomiejpluta.base.api.game.input.KeyEvent;
|
||||
public abstract class BaseWidget implements Widget {
|
||||
protected Widget parent;
|
||||
|
||||
protected SizeMode widthMode = SizeMode.NORMAL;
|
||||
protected SizeMode heightMode = SizeMode.NORMAL;
|
||||
protected SizeMode widthMode = SizeMode.AUTO;
|
||||
protected SizeMode heightMode = SizeMode.AUTO;
|
||||
|
||||
protected float x;
|
||||
protected float y;
|
||||
@@ -30,26 +30,26 @@ public abstract class BaseWidget implements Widget {
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
return widthMode == SizeMode.MATCH_PARENT
|
||||
? (parent != null ? parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight() - marginLeft - marginRight : 0)
|
||||
return widthMode == SizeMode.RELATIVE
|
||||
? (parent != null ? width * parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight() - marginLeft - marginRight : 0)
|
||||
: getActualWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getActualWidth() {
|
||||
return paddingLeft + (widthMode == SizeMode.NORMAL ? width : getContentWidth()) + paddingRight;
|
||||
return paddingLeft + (widthMode == SizeMode.ABSOLUTE ? width : getContentWidth()) + paddingRight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
return heightMode == SizeMode.MATCH_PARENT
|
||||
? (parent != null ? parent.getHeight() - parent.getPaddingTop() - parent.getPaddingBottom() - marginTop - marginBottom : 0)
|
||||
return heightMode == SizeMode.RELATIVE
|
||||
? (parent != null ? height * parent.getHeight() - parent.getPaddingTop() - parent.getPaddingBottom() - marginTop - marginBottom : 0)
|
||||
: getActualHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getActualHeight() {
|
||||
return paddingTop + (heightMode == SizeMode.NORMAL ? height : getContentHeight()) + paddingBottom;
|
||||
return paddingTop + (heightMode == SizeMode.ABSOLUTE ? height : getContentHeight()) + paddingBottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui.base;
|
||||
|
||||
public enum SizeMode {
|
||||
NORMAL,
|
||||
MATCH_PARENT,
|
||||
WRAP_CONTENT
|
||||
AUTO,
|
||||
ABSOLUTE,
|
||||
RELATIVE
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public abstract class BaseWindow extends BaseWidget implements Window {
|
||||
protected GUI gui;
|
||||
protected WindowManager manager;
|
||||
protected Component content;
|
||||
protected WindowPosition windowPosition;
|
||||
protected WindowPosition windowPosition = WindowPosition.CENTER;
|
||||
|
||||
protected BaseWindow(Context context, GUI gui) {
|
||||
this.context = context;
|
||||
|
||||
@@ -21,7 +21,8 @@ public final class WindowManager extends BaseWidget {
|
||||
}
|
||||
|
||||
public WindowManager(DisplayMode displayMode) {
|
||||
super.setSizeMode(SizeMode.MATCH_PARENT, SizeMode.MATCH_PARENT);
|
||||
super.setSizeMode(SizeMode.RELATIVE, SizeMode.RELATIVE);
|
||||
super.setSize(1f, 1f);
|
||||
this.displayMode = displayMode;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user