Create ComponentWrapper

This commit is contained in:
2021-03-19 14:10:37 +01:00
parent 8fb4e7a08e
commit bf8f896c81
2 changed files with 42 additions and 5 deletions

View File

@@ -0,0 +1,37 @@
package com.bartlomiejpluta.base.api.game.gui.component;
import com.bartlomiejpluta.base.api.game.context.Context;
import com.bartlomiejpluta.base.api.game.gui.base.GUI;
import com.bartlomiejpluta.base.api.game.screen.Screen;
import static java.util.Objects.requireNonNull;
public abstract class ComponentWrapper extends BaseComponent {
protected Component component;
protected ComponentWrapper(Context context, GUI gui) {
super(context, gui);
}
@Override
public void add(Component component) {
this.component = requireNonNull(component);
component.setParent(this);
}
@Override
protected float getContentWidth() {
return component.getWidth();
}
@Override
protected float getContentHeight() {
return component.getHeight();
}
@Override
public void draw(Screen screen, GUI gui) {
component.setPosition(x, y);
component.draw(screen, gui);
}
}

View File

@@ -27,27 +27,27 @@ public final class WindowManager extends BaseWidget {
}
@Override
protected float getContentWidth() {
protected final float getContentWidth() {
return 0;
}
@Override
protected float getContentHeight() {
protected final float getContentHeight() {
return 0;
}
@Override
public void setSizeMode(SizeMode widthMode, SizeMode heightMode) {
public final void setSizeMode(SizeMode widthMode, SizeMode heightMode) {
throw new UnsupportedOperationException("Window Manager is hardcoded to be of MATCH_PARENT mode");
}
@Override
public void setWidthMode(SizeMode mode) {
public final void setWidthMode(SizeMode mode) {
throw new UnsupportedOperationException("Window Manager is hardcoded to be of MATCH_PARENT mode");
}
@Override
public void setHeightMode(SizeMode mode) {
public final void setHeightMode(SizeMode mode) {
throw new UnsupportedOperationException("Window Manager is hardcoded to be of MATCH_PARENT mode");
}