Add support for component focus and blur
This commit is contained in:
@@ -3,4 +3,20 @@ package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.BaseWidget;
|
||||
|
||||
public abstract class BaseComponent extends BaseWidget implements Component {
|
||||
protected boolean focused;
|
||||
|
||||
@Override
|
||||
public boolean isFocused() {
|
||||
return focused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void focus() {
|
||||
focused = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blur() {
|
||||
focused = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,15 @@ public abstract class BaseContainer extends BaseComponent implements Container {
|
||||
return childrenHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blur() {
|
||||
super.blur();
|
||||
|
||||
for (var child : children) {
|
||||
child.blur();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleKeyEvent(KeyEvent event) {
|
||||
for (var child : children) {
|
||||
|
||||
@@ -3,4 +3,9 @@ package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
||||
|
||||
public interface Component extends Widget {
|
||||
boolean isFocused();
|
||||
|
||||
void focus();
|
||||
|
||||
void blur();
|
||||
}
|
||||
|
||||
@@ -58,6 +58,13 @@ public class DefaultWindowManager extends BaseWidget implements WindowManager {
|
||||
window.onOpen(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAll() {
|
||||
for (var window : windows) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (windows.isEmpty()) {
|
||||
|
||||
@@ -10,4 +10,10 @@ public interface WindowManager extends Widget {
|
||||
void close();
|
||||
|
||||
int size();
|
||||
|
||||
default void closeAll() {
|
||||
for (int i = 0; i < size(); ++i) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user