diff --git a/src/client/java/io/wispforest/limelight/impl/ui/SearchFocusHandler.java b/src/client/java/io/wispforest/limelight/impl/ui/SearchFocusHandler.java new file mode 100644 index 0000000..4e2a60c --- /dev/null +++ b/src/client/java/io/wispforest/limelight/impl/ui/SearchFocusHandler.java @@ -0,0 +1,29 @@ +package io.wispforest.limelight.impl.ui; + +import io.wispforest.owo.ui.container.ScrollContainer; +import io.wispforest.owo.ui.core.Component; +import io.wispforest.owo.ui.core.ParentComponent; +import io.wispforest.owo.ui.util.FocusHandler; +import org.jetbrains.annotations.Nullable; + +public class SearchFocusHandler extends FocusHandler { + public SearchFocusHandler(ParentComponent root) { + super(root); + } + + @Override + public void focus(@Nullable Component component, Component.FocusSource source) { + super.focus(component, source); + + if (component == null) return; + + ParentComponent current = component.parent(); + while (current != null) { + if (current instanceof ScrollContainer scroll) { + scroll.scrollTo(component); + } + + current = current.parent(); + } + } +} diff --git a/src/client/java/io/wispforest/limelight/impl/ui/SearchRootFlowLayout.java b/src/client/java/io/wispforest/limelight/impl/ui/SearchRootFlowLayout.java index dc13906..d948bc4 100644 --- a/src/client/java/io/wispforest/limelight/impl/ui/SearchRootFlowLayout.java +++ b/src/client/java/io/wispforest/limelight/impl/ui/SearchRootFlowLayout.java @@ -1,6 +1,7 @@ package io.wispforest.limelight.impl.ui; import io.wispforest.owo.ui.container.FlowLayout; +import io.wispforest.owo.ui.core.ParentComponent; import io.wispforest.owo.ui.core.Sizing; import org.lwjgl.glfw.GLFW; @@ -23,4 +24,13 @@ public boolean onKeyPress(int keyCode, int scanCode, int modifiers) { return this.keyPressEvents.sink().onKeyPress(keyCode, scanCode, modifiers); } + + @Override + public void mount(ParentComponent parent, int x, int y) { + super.mount(parent, x, y); + + if (parent == null) { + this.focusHandler = new SearchFocusHandler(this); + } + } }