-
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
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/com/neptuneclient/voidui/widgets/Column.kt
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,38 @@ | ||
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<Widget>, 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(h, 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 | ||
} | ||
|
||
} |
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,38 @@ | ||
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 | ||
} | ||
|
||
} |
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