net.peanuuutz.fork.ui.scene.component.DelegatingNativeWidgets.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fork-ui Show documentation
Show all versions of fork-ui Show documentation
Comprehensive API designed for Minecraft modders
The newest version!
package net.peanuuutz.fork.ui.scene.component
import net.minecraft.client.gui.Drawable
import net.minecraft.client.gui.Element
import net.minecraft.client.gui.ScreenRect
import net.minecraft.client.gui.navigation.GuiNavigation
import net.minecraft.client.gui.navigation.GuiNavigationPath
import net.minecraft.client.gui.widget.Widget
import net.minecraft.client.util.math.MatrixStack
fun DelegatingNativeWidget(
delegate: W
): DelegatingNativeWidget {
return when {
delegate is Drawable && delegate is Element -> DrawableInteractableWidget(delegate)
delegate is Drawable -> DrawableWidget(delegate)
delegate is Element -> InteractableWidget(delegate)
else -> PlaceholderWidget(delegate)
}
}
// ======== Internal ========
// -------- Interfaces --------
private sealed interface DelegatingDrawableWidget :
DelegatingNativeWidget, Drawable
where W : Widget, W : Drawable
{
override fun render(matrices: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
delegate.render(matrices, mouseX, mouseY, delta)
}
}
private sealed interface DelegatingInteractableWidget :
DelegatingNativeWidget, Element
where W : Widget, W : Element
{
override fun mouseMoved(mouseX: Double, mouseY: Double) {
delegate.mouseMoved(mouseX, mouseY)
}
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
return delegate.mouseClicked(mouseX, mouseY, button)
}
override fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean {
return delegate.mouseReleased(mouseX, mouseY, button)
}
override fun mouseDragged(mouseX: Double, mouseY: Double, button: Int, deltaX: Double, deltaY: Double): Boolean {
return delegate.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)
}
override fun mouseScrolled(mouseX: Double, mouseY: Double, amount: Double): Boolean {
return delegate.mouseScrolled(mouseX, mouseY, amount)
}
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
return delegate.keyPressed(keyCode, scanCode, modifiers)
}
override fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
return delegate.keyReleased(keyCode, scanCode, modifiers)
}
override fun charTyped(chr: Char, modifiers: Int): Boolean {
return delegate.charTyped(chr, modifiers)
}
override fun getNavigationPath(navigation: GuiNavigation): GuiNavigationPath? {
return delegate.getNavigationPath(navigation)
}
override fun isMouseOver(mouseX: Double, mouseY: Double): Boolean {
return delegate.isMouseOver(mouseX, mouseY)
}
override fun setFocused(focused: Boolean) {
delegate.isFocused = focused
}
override fun isFocused(): Boolean {
return delegate.isFocused
}
override fun getFocusedPath(): GuiNavigationPath? {
return delegate.focusedPath
}
override fun getNavigationFocus(): ScreenRect {
return super.getNavigationFocus()
}
}
// -------- Implementations --------
private class DrawableInteractableWidget(
override val delegate: W
) : DelegatingDrawableWidget, DelegatingInteractableWidget
where W : Widget, W : Drawable, W : Element
private class DrawableWidget(
override val delegate: W
) : DelegatingDrawableWidget
where W : Widget, W : Drawable
private class InteractableWidget(
override val delegate: W
) : DelegatingInteractableWidget
where W : Widget, W : Element
private class PlaceholderWidget(
override val delegate: W
) : DelegatingNativeWidget
where W : Widget