Compare commits
1 Commits
e28daf3b4a
...
12b6886da8
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 12b6886da8 |
|
@ -13,7 +13,7 @@ object ASMR: ModInitializer {
|
||||||
CommandRegistry.INSTANCE.register(false) { dispatcher ->
|
CommandRegistry.INSTANCE.register(false) { dispatcher ->
|
||||||
val command = CommandManager.literal("uitest").executes {
|
val command = CommandManager.literal("uitest").executes {
|
||||||
try {
|
try {
|
||||||
MinecraftClient.getInstance().openScreen(TestScreen())
|
MinecraftClient.getInstance().openScreen(UITest())
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,23 @@
|
||||||
package net.shadowfacts.asmr
|
package net.shadowfacts.asmr
|
||||||
|
|
||||||
import net.shadowfacts.kiwidsl.dsl
|
import net.shadowfacts.kiwidsl.dsl
|
||||||
import net.shadowfacts.shadowui.Screen
|
import net.shadowfacts.shadowui.UIScreen
|
||||||
import net.shadowfacts.shadowui.View
|
import net.shadowfacts.shadowui.UIView
|
||||||
import net.shadowfacts.shadowui.Window
|
|
||||||
import net.shadowfacts.shadowui.util.Color
|
import net.shadowfacts.shadowui.util.Color
|
||||||
|
|
||||||
class TestScreen: Screen() {
|
class UITest: UIScreen() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
windows.add(Window().apply {
|
val red = addView(UIView().apply {
|
||||||
val red = addView(View().apply {
|
|
||||||
backgroundColor = Color(0xff0000)
|
backgroundColor = Color(0xff0000)
|
||||||
})
|
})
|
||||||
val green = addView(View().apply {
|
val green = addView(UIView().apply {
|
||||||
backgroundColor = Color(0x00ff00)
|
backgroundColor = Color(0x00ff00)
|
||||||
})
|
})
|
||||||
val blue = addView(View().apply {
|
val blue = addView(UIView().apply {
|
||||||
backgroundColor = Color(0x0000ff)
|
backgroundColor = Color(0x0000ff)
|
||||||
})
|
})
|
||||||
val purple = green.addSubview(View().apply {
|
val purple = green.addSubview(UIView().apply {
|
||||||
backgroundColor = Color(0x800080)
|
backgroundColor = Color(0x800080)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -46,7 +44,6 @@ class TestScreen: Screen() {
|
||||||
}
|
}
|
||||||
|
|
||||||
layout()
|
layout()
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@ package net.shadowfacts.shadowui
|
||||||
|
|
||||||
import no.birkett.kiwi.Variable
|
import no.birkett.kiwi.Variable
|
||||||
|
|
||||||
class LayoutVariable(val owner: View, val property: String): Variable("LayoutVariable") {
|
class LayoutVariable(val owner: UIView, val property: String): Variable("LayoutVariable") {
|
||||||
|
|
||||||
override fun getName() = "$owner.$property"
|
override fun getName() = "$owner.$property"
|
||||||
|
|
||||||
|
|
|
@ -2,26 +2,30 @@ package net.shadowfacts.shadowui
|
||||||
|
|
||||||
import net.minecraft.client.gui.screen.Screen
|
import net.minecraft.client.gui.screen.Screen
|
||||||
import net.minecraft.network.chat.TextComponent
|
import net.minecraft.network.chat.TextComponent
|
||||||
import net.shadowfacts.shadowui.geometry.Point
|
|
||||||
import no.birkett.kiwi.Solver
|
import no.birkett.kiwi.Solver
|
||||||
|
|
||||||
open class Screen: Screen(TextComponent("Screen")) {
|
open class UIScreen: Screen(TextComponent("UIScreen")) {
|
||||||
|
|
||||||
val windows = mutableListOf<Window>()
|
val solver = Solver()
|
||||||
|
|
||||||
fun addWindow(window: Window, index: Int? = null) {
|
val views = mutableListOf<UIView>()
|
||||||
if (index != null) {
|
|
||||||
windows.add(index, window)
|
fun addView(view: UIView): UIView {
|
||||||
} else {
|
views.add(view)
|
||||||
windows.add(window)
|
view.solver = solver
|
||||||
|
|
||||||
|
view.wasAdded()
|
||||||
|
|
||||||
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun layout() {
|
||||||
|
solver.updateVariables()
|
||||||
|
views.forEach(UIView::didLayout)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(mouseX: Int, mouseY: Int, delta: Float) {
|
override fun render(mouseX: Int, mouseY: Int, delta: Float) {
|
||||||
val mouse = Point(mouseX, mouseY)
|
views.forEach(UIView::draw)
|
||||||
windows.forEach {
|
|
||||||
it.draw(mouse, delta)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,12 +2,12 @@ package net.shadowfacts.shadowui
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager
|
import com.mojang.blaze3d.platform.GlStateManager
|
||||||
import net.shadowfacts.kiwidsl.dsl
|
import net.shadowfacts.kiwidsl.dsl
|
||||||
import net.shadowfacts.shadowui.geometry.Rect
|
import net.shadowfacts.shadowui.geometry.UIRect
|
||||||
import net.shadowfacts.shadowui.util.Color
|
import net.shadowfacts.shadowui.util.Color
|
||||||
import net.shadowfacts.shadowui.util.RenderHelper
|
import net.shadowfacts.shadowui.util.RenderHelper
|
||||||
import no.birkett.kiwi.Solver
|
import no.birkett.kiwi.Solver
|
||||||
|
|
||||||
class View {
|
class UIView {
|
||||||
|
|
||||||
lateinit var solver: Solver
|
lateinit var solver: Solver
|
||||||
|
|
||||||
|
@ -22,16 +22,16 @@ class View {
|
||||||
val centerYAnchor = LayoutVariable(this, "centerY")
|
val centerYAnchor = LayoutVariable(this, "centerY")
|
||||||
|
|
||||||
// The rectangle for this view in the coordinate system of the parent view.
|
// The rectangle for this view in the coordinate system of the parent view.
|
||||||
lateinit var frame: Rect
|
lateinit var frame: UIRect
|
||||||
// The rectangle for this view in its own coordinate system.
|
// The rectangle for this view in its own coordinate system.
|
||||||
lateinit var bounds: Rect
|
lateinit var bounds: UIRect
|
||||||
|
|
||||||
var backgroundColor = Color(0xff0000)
|
var backgroundColor = Color(0xff0000)
|
||||||
|
|
||||||
var parent: View? = null
|
var parent: UIView? = null
|
||||||
val subviews = mutableListOf<View>()
|
val subviews = mutableListOf<UIView>()
|
||||||
|
|
||||||
fun addSubview(view: View): View {
|
fun addSubview(view: UIView): UIView {
|
||||||
subviews.add(view)
|
subviews.add(view)
|
||||||
view.parent = this
|
view.parent = this
|
||||||
view.solver = solver
|
view.solver = solver
|
||||||
|
@ -55,12 +55,12 @@ class View {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun didLayout() {
|
fun didLayout() {
|
||||||
subviews.forEach(View::didLayout)
|
subviews.forEach(UIView::didLayout)
|
||||||
|
|
||||||
val parentLeft = parent?.leftAnchor?.value ?: 0.0
|
val parentLeft = parent?.leftAnchor?.value ?: 0.0
|
||||||
val parentTop = parent?.topAnchor?.value ?: 0.0
|
val parentTop = parent?.topAnchor?.value ?: 0.0
|
||||||
frame = Rect(leftAnchor.value - parentLeft, topAnchor.value - parentTop, widthAnchor.value, heightAnchor.value)
|
frame = UIRect(leftAnchor.value - parentLeft, topAnchor.value - parentTop, widthAnchor.value, heightAnchor.value)
|
||||||
bounds = Rect(0.0, 0.0, widthAnchor.value, heightAnchor.value)
|
bounds = UIRect(0.0, 0.0, widthAnchor.value, heightAnchor.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun draw() {
|
fun draw() {
|
||||||
|
@ -71,7 +71,7 @@ class View {
|
||||||
|
|
||||||
drawContent()
|
drawContent()
|
||||||
|
|
||||||
subviews.forEach(View::draw)
|
subviews.forEach(UIView::draw)
|
||||||
|
|
||||||
GlStateManager.popMatrix()
|
GlStateManager.popMatrix()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
package net.shadowfacts.shadowui
|
|
||||||
|
|
||||||
import net.shadowfacts.shadowui.geometry.Point
|
|
||||||
import no.birkett.kiwi.Solver
|
|
||||||
|
|
||||||
class Window {
|
|
||||||
|
|
||||||
var solver = Solver()
|
|
||||||
|
|
||||||
val views = mutableListOf<View>()
|
|
||||||
|
|
||||||
fun <T: View> addView(view: T): T {
|
|
||||||
views.add(view)
|
|
||||||
view.solver = solver
|
|
||||||
|
|
||||||
view.wasAdded()
|
|
||||||
|
|
||||||
return view
|
|
||||||
}
|
|
||||||
|
|
||||||
fun layout() {
|
|
||||||
solver.updateVariables()
|
|
||||||
views.forEach(View::didLayout)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun draw(mouse: Point, delta: Float) {
|
|
||||||
views.forEach(View::draw)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package net.shadowfacts.shadowui.geometry
|
|
||||||
|
|
||||||
class Point(val x: Double, val y: Double) {
|
|
||||||
|
|
||||||
constructor(x: Int, y: Int): this(x.toDouble(), y.toDouble())
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.shadowfacts.shadowui.geometry
|
package net.shadowfacts.shadowui.geometry
|
||||||
|
|
||||||
data class Rect(val left: Double, val top: Double, val width: Double, val height: Double) {
|
data class UIRect(val left: Double, val top: Double, val width: Double, val height: Double) {
|
||||||
|
|
||||||
val right: Double
|
val right: Double
|
||||||
get() = left + width
|
get() = left + width
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package net.shadowfacts.shadowui.util
|
package net.shadowfacts.shadowui.util
|
||||||
|
|
||||||
import net.minecraft.client.gui.DrawableHelper
|
import net.minecraft.client.gui.DrawableHelper
|
||||||
import net.shadowfacts.shadowui.geometry.Rect
|
import net.shadowfacts.shadowui.geometry.UIRect
|
||||||
|
|
||||||
object RenderHelper {
|
object RenderHelper {
|
||||||
|
|
||||||
fun fill(rect: Rect, color: Color) {
|
fun fill(rect: UIRect, color: Color) {
|
||||||
DrawableHelper.fill(rect.left.toInt(), rect.top.toInt(), rect.right.toInt(), rect.bottom.toInt(), color.argb)
|
DrawableHelper.fill(rect.left.toInt(), rect.top.toInt(), rect.right.toInt(), rect.bottom.toInt(), color.argb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue