-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add janky scrolling to newly focused element
this should be refined to not actually always scroll even when the element is already visible, but this works fine for now
- Loading branch information
1 parent
11a96c7
commit f605ae7
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/client/java/io/wispforest/limelight/impl/ui/SearchFocusHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters