Add support for component focus and blur

This commit is contained in:
2021-03-13 12:36:47 +01:00
parent 68e0a793aa
commit f05158093a
6 changed files with 45 additions and 2 deletions

View File

@@ -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;
}
}

View File

@@ -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) {

View File

@@ -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();
}

View File

@@ -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()) {

View File

@@ -10,4 +10,10 @@ public interface WindowManager extends Widget {
void close();
int size();
default void closeAll() {
for (int i = 0; i < size(); ++i) {
close();
}
}
}

View File

@@ -46,12 +46,12 @@ public class GLFWInput implements Input {
}
@Override
public void addKeyEventHandler(KeyEventHandler handler) {
public void addKeyEventHandler(@NonNull KeyEventHandler handler) {
keyEventHandlers.addLast(handler);
}
@Override
public void removeKeyEventHandler(KeyEventHandler handler) {
public void removeKeyEventHandler(@NonNull KeyEventHandler handler) {
keyEventHandlers.remove(handler);
}
}