Skip to content

Commit

Permalink
merged row and column into one file
Browse files Browse the repository at this point in the history
  • Loading branch information
Hobbyshop committed Apr 30, 2024
1 parent c5fadbb commit 1bd9189
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 78 deletions.
38 changes: 0 additions & 38 deletions src/main/kotlin/com/neptuneclient/voidui/widgets/Column.kt

This file was deleted.

38 changes: 0 additions & 38 deletions src/main/kotlin/com/neptuneclient/voidui/widgets/Row.kt

This file was deleted.

85 changes: 85 additions & 0 deletions src/main/kotlin/com/neptuneclient/voidui/widgets/flex.kt
Original file line number Diff line number Diff line change
@@ -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<Widget>, 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<Widget> {
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<Widget>,
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<Widget> {
return children
}

}

enum class MainAxisAlignment {
START, CENTER, END, SPACE_AROUND, SPACE_BETWEEN, SPACE_EVENLY
}

enum class CrossAxisAlignment {
START, CENTER, END, STRETCH
}
13 changes: 11 additions & 2 deletions src/test/kotlin/com/neptuneclient/voidui/tests/ScreenTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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")
)
Expand Down

0 comments on commit 1bd9189

Please sign in to comment.