Skip to content

Commit 59f79ba

Browse files
committed
fix: allow for more methods to be called without a context
1 parent 83346e3 commit 59f79ba

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

common/src/main/java/io/github/notenoughupdates/moulconfig/gui/GuiComponent.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import io.github.notenoughupdates.moulconfig.common.IMinecraft;
2424
import lombok.Getter;
25+
import lombok.Setter;
2526
import org.jetbrains.annotations.NotNull;
2627

2728
import java.util.function.BiFunction;
@@ -34,16 +35,13 @@
3435
*/
3536
public abstract class GuiComponent {
3637
protected final IMinecraft mc = IMinecraft.instance;
38+
@Setter
3739
@Getter
3840
GuiContext context;
3941

4042
protected GuiComponent() {
4143
}
4244

43-
public void setContext(GuiContext context) {
44-
this.context = context;
45-
}
46-
4745
/**
4846
* Get the requested x size for this element. This is opposed to the actual size given in the {@link GuiImmediateContext context}. Giving this element less space than this may result in misaligned or overlapping rendering.
4947
*/
@@ -58,14 +56,15 @@ public void setContext(GuiContext context) {
5856
* Call this method to request focus in the current gui context.
5957
*/
6058
public void requestFocus() {
61-
context.setFocusedElement(this);
59+
if (context != null)
60+
context.setFocusedElement(this);
6261
}
6362

6463
/**
6564
* Unfocus this element only if this element is selected.
6665
*/
6766
public void blur() {
68-
if (context.getFocusedElement() == this)
67+
if (context != null && context.getFocusedElement() == this)
6968
context.setFocusedElement(null);
7069
}
7170

@@ -86,7 +85,7 @@ public void setFocus(boolean shouldFocus) {
8685
* @return true if this is focused directly, and has no focused child
8786
*/
8887
public boolean isFocused() {
89-
return context.getFocusedElement() == this;
88+
return context != null && context.getFocusedElement() == this;
9089
}
9190

9291
/**

0 commit comments

Comments
 (0)