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;
|
import com.bartlomiejpluta.base.api.game.gui.base.BaseWidget;
|
||||||
|
|
||||||
public abstract class BaseComponent extends BaseWidget implements Component {
|
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;
|
return childrenHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void blur() {
|
||||||
|
super.blur();
|
||||||
|
|
||||||
|
for (var child : children) {
|
||||||
|
child.blur();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleKeyEvent(KeyEvent event) {
|
public void handleKeyEvent(KeyEvent event) {
|
||||||
for (var child : children) {
|
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;
|
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
||||||
|
|
||||||
public interface Component extends 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);
|
window.onOpen(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeAll() {
|
||||||
|
for (var window : windows) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (windows.isEmpty()) {
|
if (windows.isEmpty()) {
|
||||||
|
|||||||
@@ -10,4 +10,10 @@ public interface WindowManager extends Widget {
|
|||||||
void close();
|
void close();
|
||||||
|
|
||||||
int size();
|
int size();
|
||||||
|
|
||||||
|
default void closeAll() {
|
||||||
|
for (int i = 0; i < size(); ++i) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ public class GLFWInput implements Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addKeyEventHandler(KeyEventHandler handler) {
|
public void addKeyEventHandler(@NonNull KeyEventHandler handler) {
|
||||||
keyEventHandlers.addLast(handler);
|
keyEventHandlers.addLast(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeKeyEventHandler(KeyEventHandler handler) {
|
public void removeKeyEventHandler(@NonNull KeyEventHandler handler) {
|
||||||
keyEventHandlers.remove(handler);
|
keyEventHandlers.remove(handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user