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.elements.ClickBox
import fr.username404.snowygui.gui.elements.ClickButton
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.minecraft.network.chat.TranslatableComponent
object ClickGui: SnowyScreen() {
private var GuiDragging: Boolean = false
override val components: MutableSet<Element> = mutableSetOf(
ClickBox(4.0, 4.0, TranslatableComponent("snowy.clickbox.misc"), mutableListOf(
ClickButton(color = 0x6C9E9D),
ClickButton(color = 0x6C9E9D, Title = "Fullbright"),
ClickButton(color = 0x6C9E9D)
)),
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 kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.components.events.GuiEventListener
class ClickButton(
x: Double = 0.0, y: Double = 0.0,
width: Int = 73, height: Int = 8,
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 {
companion object {
enum class Type {
@ -43,9 +45,7 @@ class ClickButton(
if (wasWithinBounds) {
lightDown()
execAction()
}
return false
}; return false
}
override fun render(poseStack: PoseStack?) {
RenderSystem.disableTexture()
@ -53,5 +53,6 @@ class ClickButton(
defaultRectFunc()
RenderSystem.enableTexture()
RenderSystem.disableBlend()
if (Title != null) Minecraft.getInstance().font.draw(poseStack, Title, x.toFloat() + 1, y.toFloat(), TransparentColor)
}
}