Better check box label
This commit is contained in:
parent
19d8eca2e5
commit
ece5b2a936
@ -4,6 +4,7 @@ import net.minecraft.network.chat.Component
|
|||||||
import net.minecraft.world.entity.player.Inventory
|
import net.minecraft.world.entity.player.Inventory
|
||||||
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
import ru.dbotthepony.mc.otm.client.screen.MatteryScreen
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.Dock
|
import ru.dbotthepony.mc.otm.client.screen.panels.Dock
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.DockProperty
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.FramePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.button.CheckBoxLabelInputPanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.input.NetworkedStringInputPanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.input.NetworkedStringInputPanel
|
||||||
@ -20,6 +21,7 @@ class HoloSignScreen(menu: HoloSignMenu, inventory: Inventory, title: Component)
|
|||||||
|
|
||||||
val lock = CheckBoxLabelInputPanel(this, frame, menu.locked, TranslatableComponent("otm.gui.lock_holo_screen"))
|
val lock = CheckBoxLabelInputPanel(this, frame, menu.locked, TranslatableComponent("otm.gui.lock_holo_screen"))
|
||||||
lock.dock = Dock.BOTTOM
|
lock.dock = Dock.BOTTOM
|
||||||
|
lock.dockMargin = DockProperty(2f, 2f, 2f, 2f)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.client.screen.panels.button
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.screens.Screen
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.Label
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
abstract class AbstractCheckBoxLabelPanel<out S : Screen> @JvmOverloads constructor(
|
||||||
|
screen: S,
|
||||||
|
parent: EditablePanel<*>?,
|
||||||
|
x: Float = 0f,
|
||||||
|
y: Float = 0f,
|
||||||
|
width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f,
|
||||||
|
height: Float = CheckBoxPanel.REGULAR_DIMENSIONS
|
||||||
|
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
||||||
|
abstract val checkbox: CheckBoxPanel<S>
|
||||||
|
abstract val label: Label<S>
|
||||||
|
|
||||||
|
override fun performLayout() {
|
||||||
|
super.performLayout()
|
||||||
|
|
||||||
|
checkbox.x = dockPadding.left
|
||||||
|
checkbox.y = dockPadding.top + (height / 2f - checkbox.height / 2f).roundToInt().toFloat()
|
||||||
|
|
||||||
|
label.x = checkbox.x + checkbox.width + 4f
|
||||||
|
label.y = ((height - dockPadding.top - dockPadding.bottom) / 2f - font.lineHeight / 2f).roundToInt().toFloat()
|
||||||
|
label.width = width - checkbox.width - dockPadding.right
|
||||||
|
}
|
||||||
|
}
|
@ -2,10 +2,12 @@ package ru.dbotthepony.mc.otm.client.screen.panels.button
|
|||||||
|
|
||||||
import net.minecraft.client.gui.screens.Screen
|
import net.minecraft.client.gui.screens.Screen
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
|
import ru.dbotthepony.mc.otm.client.screen.panels.Dock
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.Label
|
import ru.dbotthepony.mc.otm.client.screen.panels.Label
|
||||||
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.BooleanInputWithFeedback
|
||||||
import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback
|
import ru.dbotthepony.mc.otm.menu.input.IPlayerInputWithFeedback
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
open class CheckBoxLabelInputPanel<out S : Screen> @JvmOverloads constructor(
|
open class CheckBoxLabelInputPanel<out S : Screen> @JvmOverloads constructor(
|
||||||
screen: S,
|
screen: S,
|
||||||
@ -16,8 +18,8 @@ open class CheckBoxLabelInputPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
y: Float = 0f,
|
y: Float = 0f,
|
||||||
width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f,
|
width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f,
|
||||||
height: Float = CheckBoxPanel.REGULAR_DIMENSIONS
|
height: Float = CheckBoxPanel.REGULAR_DIMENSIONS
|
||||||
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
) : AbstractCheckBoxLabelPanel<S>(screen, parent, x, y, width, height) {
|
||||||
val widget get() = checkbox.widget
|
val widget get() = checkbox.widget
|
||||||
val checkbox = CheckBoxInputPanel(screen = screen, parent = this, widget = widget, x = 0f, y = 0f, width = CheckBoxPanel.REGULAR_DIMENSIONS, height = CheckBoxPanel.REGULAR_DIMENSIONS)
|
override val checkbox = CheckBoxInputPanel(screen = screen, parent = this, widget = widget, x = 0f, y = 0f, width = CheckBoxPanel.REGULAR_DIMENSIONS, height = CheckBoxPanel.REGULAR_DIMENSIONS)
|
||||||
val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text)
|
override val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import net.minecraft.client.gui.screens.Screen
|
|||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
import ru.dbotthepony.mc.otm.client.screen.panels.EditablePanel
|
||||||
import ru.dbotthepony.mc.otm.client.screen.panels.Label
|
import ru.dbotthepony.mc.otm.client.screen.panels.Label
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
open class CheckBoxLabelPanel<out S : Screen> @JvmOverloads constructor(
|
open class CheckBoxLabelPanel<out S : Screen> @JvmOverloads constructor(
|
||||||
screen: S,
|
screen: S,
|
||||||
@ -13,8 +14,7 @@ open class CheckBoxLabelPanel<out S : Screen> @JvmOverloads constructor(
|
|||||||
y: Float = 0f,
|
y: Float = 0f,
|
||||||
width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f,
|
width: Float = CheckBoxPanel.REGULAR_DIMENSIONS + 120f,
|
||||||
height: Float = CheckBoxPanel.REGULAR_DIMENSIONS
|
height: Float = CheckBoxPanel.REGULAR_DIMENSIONS
|
||||||
) : EditablePanel<S>(screen, parent, x, y, width, height) {
|
) : AbstractCheckBoxLabelPanel<S>(screen, parent, x, y, width, height) {
|
||||||
val checkbox =
|
override val checkbox = CheckBoxPanel(screen, this, 0f, 0f, CheckBoxPanel.REGULAR_DIMENSIONS, CheckBoxPanel.REGULAR_DIMENSIONS)
|
||||||
CheckBoxPanel(screen, this, 0f, 0f, CheckBoxPanel.REGULAR_DIMENSIONS, CheckBoxPanel.REGULAR_DIMENSIONS)
|
override val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text)
|
||||||
val label = Label(screen, this, CheckBoxPanel.REGULAR_DIMENSIONS + 4f, 4f, text = text)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user