diff --git a/src/main/kotlin/com/neptuneclient/voidui/widgets/Column.kt b/src/main/kotlin/com/neptuneclient/voidui/widgets/Column.kt deleted file mode 100644 index fce135f..0000000 --- a/src/main/kotlin/com/neptuneclient/voidui/widgets/Column.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.neptuneclient.voidui.widgets - -import com.neptuneclient.voidui.framework.* -import kotlin.math.max - -/** - * A group widget which lets you place widgets in a cloumn. - * - * @param children The widgets in the row. - * @param gap The gap between the widgets. - */ -class Column(private val children: Array, private val gap: Float = 0f) : GroupWidget() { - - override fun layout(constraints: BoxConstraints) { - var w = 0f - var h = gap * (children.size - 1) - children.forEach { - it.layout(constraints) - w = max(w, it.size.width) - h += it.size.height - } - size = constraints.constrain(Size(w, h)) - } - - override fun postLayoutInit(parentOffset: Offset, parent: Widget) { - var y = parentOffset.y - children.forEach { - it.postLayoutInit(Offset(parentOffset.x, y), this) - y += it.size.height + gap - } - offset = parentOffset - } - - override fun buildGroup(): Array { - return children - } - -} diff --git a/src/main/kotlin/com/neptuneclient/voidui/widgets/Row.kt b/src/main/kotlin/com/neptuneclient/voidui/widgets/Row.kt deleted file mode 100644 index 774e509..0000000 --- a/src/main/kotlin/com/neptuneclient/voidui/widgets/Row.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.neptuneclient.voidui.widgets - -import com.neptuneclient.voidui.framework.* -import kotlin.math.max - -/** - * A group widget which lets you place widgets in a row. - * - * @param children The widgets in the row. - * @param gap The gap between the widgets. - */ -class Row(private val children: Array, private val gap: Float = 0f) : GroupWidget() { - - override fun layout(constraints: BoxConstraints) { - var w = gap * (children.size - 1) - var h = 0f - children.forEach { - it.layout(constraints) - w += it.size.width - h = max(h, it.size.height) - } - size = constraints.constrain(Size(w, h)) - } - - override fun postLayoutInit(parentOffset: Offset, parent: Widget) { - var x = parentOffset.x - children.forEach { - it.postLayoutInit(Offset(x, parentOffset.y), this) - x += it.size.width + gap - } - offset = parentOffset - } - - override fun buildGroup(): Array { - return children - } - -} \ No newline at end of file diff --git a/src/main/kotlin/com/neptuneclient/voidui/widgets/flex.kt b/src/main/kotlin/com/neptuneclient/voidui/widgets/flex.kt new file mode 100644 index 0000000..847e554 --- /dev/null +++ b/src/main/kotlin/com/neptuneclient/voidui/widgets/flex.kt @@ -0,0 +1,85 @@ +package com.neptuneclient.voidui.widgets + +import com.neptuneclient.voidui.framework.* +import kotlin.math.max + +/** + * A group widget which lets you place widgets in a row. + * + * @param children The widgets in the row. + * @param gap The gap between the widgets. + */ +class Row(private val children: Array, private val gap: Float = 0f) : GroupWidget() { + + override fun layout(constraints: BoxConstraints) { + var w = gap * (children.size - 1) + var h = 0f + children.forEach { + it.layout(constraints) + w += it.size.width + h = max(h, it.size.height) + } + size = constraints.constrain(Size(w, h)) + } + + override fun postLayoutInit(parentOffset: Offset, parent: Widget) { + var x = parentOffset.x + children.forEach { + it.postLayoutInit(Offset(x, parentOffset.y), this) + x += it.size.width + gap + } + offset = parentOffset + } + + override fun buildGroup(): Array { + return children + } + +} + +/** + * A group widget which lets you place widgets in a cloumn. + * + * @param children The widgets in the row. + * @param gap The gap between the widgets. + */ +class Column( + private val children: Array, + private val gap: Float = 0f, + private val mainAxisAlignment: MainAxisAlignment = MainAxisAlignment.START, + private val crossAxisAlignment: CrossAxisAlignment = CrossAxisAlignment.START, +) : GroupWidget() { + + override fun layout(constraints: BoxConstraints) { + var w = 0f + var h = gap * (children.size - 1) + children.forEach { + it.layout(constraints) + w = max(w, it.size.width) + h += it.size.height + } + size = constraints.constrain(Size(w, h)) + } + + override fun postLayoutInit(parentOffset: Offset, parent: Widget) { + var y = parentOffset.y + children.forEach { + it.postLayoutInit(Offset(parentOffset.x, y), this) + y += it.size.height + gap + } + offset = parentOffset + } + + override fun buildGroup(): Array { + return children + } + +} + +enum class MainAxisAlignment { + START, CENTER, END, SPACE_AROUND, SPACE_BETWEEN, SPACE_EVENLY +} + +enum class CrossAxisAlignment { + START, CENTER, END, STRETCH +} \ No newline at end of file diff --git a/src/test/kotlin/com/neptuneclient/voidui/tests/ScreenTest.kt b/src/test/kotlin/com/neptuneclient/voidui/tests/ScreenTest.kt index 87fc695..7f20b68 100644 --- a/src/test/kotlin/com/neptuneclient/voidui/tests/ScreenTest.kt +++ b/src/test/kotlin/com/neptuneclient/voidui/tests/ScreenTest.kt @@ -12,6 +12,7 @@ import com.neptuneclient.voidui.framework.Widget import com.neptuneclient.voidui.objects.Border import com.neptuneclient.voidui.objects.CornerRadius import com.neptuneclient.voidui.objects.EdgeInsets +import com.neptuneclient.voidui.objects.TextAlign import com.neptuneclient.voidui.utils.image import com.neptuneclient.voidui.widgets.* import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable @@ -20,7 +21,7 @@ import java.awt.Color fun EpicButton(label: String): Widget { return Container( - color = Color(140, 60, 255), + color = Color(69, 99, 255), cornerRadius = CornerRadius.all(10f), border = Border(1f, Color(255, 255, 255, 100)), width = 240f, @@ -37,13 +38,21 @@ class TestScreen(voidUI: VoidUI) : Screen(voidUI) { override fun build(): Widget { return Container( - color = Color(16, 14, 20), + color = Color(14, 15, 20), cornerRadius = CornerRadius.all(10f), padding = EdgeInsets.all(20f), child = Column( gap = 20f, + crossAxisAlignment = CrossAxisAlignment.STRETCH, children = arrayOf( + Container( + color = Color.RED, + child = Text( + label = "Neptune popo main menu", + align = TextAlign.CENTER + ) + ), EpicButton("Singleplayer"), EpicButton("Multiplayer") )