-
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
1 parent
8839daf
commit 3e260a8
Showing
5 changed files
with
51 additions
and
10 deletions.
There are no files selected for viewing
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
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
21 changes: 20 additions & 1 deletion
21
lib/src/main/kotlin/com/github/mnemotechnician/mkui/ElementUtil.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 |
---|---|---|
@@ -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) | ||
} |
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
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