Add titles to buttons

This commit is contained in:
Username404-59 2021-05-01 16:35:23 +02:00
parent 09536ddbb1
commit 0f0c4de85b
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 6 additions and 7 deletions

View File

@ -4,15 +4,13 @@ import fr.username404.snowygui.gui.Element
import fr.username404.snowygui.gui.SnowyScreen import fr.username404.snowygui.gui.SnowyScreen
import fr.username404.snowygui.gui.elements.ClickBox import fr.username404.snowygui.gui.elements.ClickBox
import fr.username404.snowygui.gui.elements.ClickButton import fr.username404.snowygui.gui.elements.ClickButton
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.minecraft.network.chat.TranslatableComponent import net.minecraft.network.chat.TranslatableComponent
object ClickGui: SnowyScreen() { object ClickGui: SnowyScreen() {
private var GuiDragging: Boolean = false private var GuiDragging: Boolean = false
override val components: MutableSet<Element> = mutableSetOf( override val components: MutableSet<Element> = mutableSetOf(
ClickBox(4.0, 4.0, TranslatableComponent("snowy.clickbox.misc"), mutableListOf( ClickBox(4.0, 4.0, TranslatableComponent("snowy.clickbox.misc"), mutableListOf(
ClickButton(color = 0x6C9E9D), ClickButton(color = 0x6C9E9D, Title = "Fullbright"),
ClickButton(color = 0x6C9E9D) ClickButton(color = 0x6C9E9D)
)), )),
ClickBox(90.0, 4.0, TranslatableComponent("snowy.clickbox.rendering"), mutableListOf( ClickBox(90.0, 4.0, TranslatableComponent("snowy.clickbox.rendering"), mutableListOf(

View File

@ -6,13 +6,15 @@ import fr.username404.snowygui.gui.ColoredElement
import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.components.events.GuiEventListener import net.minecraft.client.gui.components.events.GuiEventListener
class ClickButton( class ClickButton(
x: Double = 0.0, y: Double = 0.0, x: Double = 0.0, y: Double = 0.0,
width: Int = 73, height: Int = 8, width: Int = 73, height: Int = 8,
color: Int, private val kind: Type = Type.TOGGLE, color: Int, private val kind: Type = Type.TOGGLE,
val action: (() -> Unit)? = null private val Title: String? = null,
private val action: (() -> Unit)? = null,
): ColoredElement(x, y, width, height, color, 0.60F), GuiEventListener { ): ColoredElement(x, y, width, height, color, 0.60F), GuiEventListener {
companion object { companion object {
enum class Type { enum class Type {
@ -43,9 +45,7 @@ class ClickButton(
if (wasWithinBounds) { if (wasWithinBounds) {
lightDown() lightDown()
execAction() execAction()
} }; return false
return false
} }
override fun render(poseStack: PoseStack?) { override fun render(poseStack: PoseStack?) {
RenderSystem.disableTexture() RenderSystem.disableTexture()
@ -53,5 +53,6 @@ class ClickButton(
defaultRectFunc() defaultRectFunc()
RenderSystem.enableTexture() RenderSystem.enableTexture()
RenderSystem.disableBlend() RenderSystem.disableBlend()
if (Title != null) Minecraft.getInstance().font.draw(poseStack, Title, x.toFloat() + 1, y.toFloat(), TransparentColor)
} }
} }