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
	}
}
