-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
78 deletions.
There are no files selected for viewing
38 changes: 0 additions & 38 deletions
38
src/main/kotlin/com/neptuneclient/voidui/widgets/Column.kt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters