Skip to content

Commit

Permalink
Add onGainedFocus event
Browse files Browse the repository at this point in the history
  • Loading branch information
nea89o committed Aug 24, 2024
1 parent 9515e12 commit 68448f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public boolean isInFocus() {
public void onLostFocus() {
}

/**
* This method is called by the gui context when an element gains focus. This does only get called if this element specifically is being {@link #isFocused() focused}.
*/
public void onGainedFocus() {
}

/**
* Walk the scene tree of this gui element, including children of children.
* By default, the visitor is called with only this element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ public class GuiContext {
public Runnable closeRequestHandler;

public void setFocusedElement(GuiComponent focusedElement) {
if (this.focusedElement == focusedElement) return;
GuiComponent oldElement = this.focusedElement;
if (oldElement != null)
oldElement.onLostFocus();
if (focusedElement != null)
focusedElement.onGainedFocus();
this.focusedElement = focusedElement;
}

Expand Down

0 comments on commit 68448f1

Please sign in to comment.