Skip to content

Commit

Permalink
new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician committed Jan 5, 2022
1 parent 8839daf commit 3e260a8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ jobs:
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: lib/build/libs/MKUI.jar
tag: ${{ github.run_number }}
tag: ${{ github.run_number }}

- name: generate kotlin doc
run: ./gradlew dokkaHtml

- name: upload kotlin doc
run: |
mv lib/build/dokka/html/* docs/
git commit -am "[auto] upload kotlin docs"
git push
11 changes: 3 additions & 8 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id("org.jetbrains.kotlin.jvm") version "1.6.0"
kotlin("jvm") version "1.6.10"
id("org.jetbrains.dokka") version "1.6.10"

`java-library` //todo: why is this added
`maven-publish`
Expand All @@ -16,13 +17,7 @@ dependencies {
compileOnly("com.github.Anuken.Arc:arc-core:$mindustryVersion")
compileOnly("com.github.Anuken.Mindustry:core:$mindustryVersion")

compileOnly(platform("org.jetbrains.kotlin:kotlin-bom"))
compileOnly("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
testImplementation("com.github.Anuken.Arc:arc-core:$mindustryVersion")
testImplementation("com.github.Anuken.Mindustry:core:$mindustryVersion")
compileOnly(kotlin("stdlib-jdk8"))
}

tasks.withType<Jar> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
/** A package containg utility functions for Elements and Cells */
package com.github.mnemotechnician.mkui

import arc.scene.*
import arc.scene.ui.*
import arc.scene.ui.layout.*

/** casts the element to the specified class or returns null if it's not an instance of this class */
inline fun <reified T> Element.asOrNull() = if (this is T) this else null;
inline fun <reified T> Element.asOrNull() = if (this is T) this else null;

/** Returns the element inside a type-erased cell, casted to the providen class */
inline fun <reified T> Cell<Element>.getAs() = get() as T;

/** Returns the element inside a type-erased cell, casted to the providen class, or null if it's not an instance of this class or if the cell is empty */
inline fun <reified T> Cell<Element?>.getAsOrNull() = get()?.let {
if (this !is T) this else null
};

/** Changes the font size of the wrapped label and returns the cell */
fun Cell<Label>.scaleFont(scale: Float) = this.apply {
get().setFontScale(scale)
};

/** Changes the font size of the wrapped text button and returns the created cell */
fun Cell<TextButton>.scaleButtonFont(scale: Float) = this.apply {
get().label.setFontScale(scale)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import arc.scene.*
import arc.scene.ui.*
import arc.scene.ui.layout.*

/** Adds an element to the Group */
inline operator fun <T: Element> Group.plusAssign(other: T) { addChild(other) };

/** Adds an element to the Table and returns the created cell */
inline operator fun <T: Element> Table.plusAssign(other: T) { add(other) };

/** Returns the n-th child of a group */
inline fun Group.child(index: Int): Element = getChildren()[index];

Expand Down
12 changes: 12 additions & 0 deletions lib/src/main/kotlin/com/github/mnemotechnician/mkui/Groups.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,15 @@ inline fun Table.buttonGroup(background: Drawable = Styles.none, constructor: Ta
}
return add(table)
}

inline fun Table.scrollPane(style: ScrollPane.ScrollPaneStyle = Styles.defaultPane, element: Element): Cell<ScrollPane> {
return add(ScrollPane(element, style))
}

/** Creates a scroll pane containing a table constructed by a lambda and returns the created cell */
inline fun Table.scrollPane(style: ScrollPane.ScrollPaneStyle = Styles.defaultPane, constructor: Table.(ScrollPane) -> Unit): Cell<ScrollPane> {
val table = Table()
val pane = ScrollPane(table, style)
table.constructor(pane)
return add(pane)
}

0 comments on commit 3e260a8

Please sign in to comment.