Package-level declarations

Types

Link copied to clipboard
class Clock

A simple class for timing of animations and things. Literally a delta function.

Link copied to clipboard
class Debugger(polyUI: PolyUI)

the debug utilities for PolyUI.

Link copied to clipboard
class Int2IntMap(initialCapacity: Int)

Simple map for Int to Int relations. Designed for small to medium maps with a low amount of entries (<1000).

Link copied to clipboard
data class Line(val string: String, val bounds: Vec2)
Link copied to clipboard
open class PolyUIBuilder

Java-style builder for creating a PolyUI instance.

Functions

Link copied to clipboard
fun <E> MutableList<E>.addIfAbsent(element: E)

Add the given element to this list if it is not in it already.

Link copied to clipboard
@ApiStatus.Internal
fun <E> MutableList<E>.addOrReplace(element: E): E?

Replace this given element if it already exists in this list using Any.equals, or append it to the end if it does not. This method is very strange and has one specific use case, which is for cases where referential equality is needed as well as structural equality. See more here.

Link copied to clipboard

append the given Char to this StringBuilder, repeated repeats times.

Link copied to clipboard
inline fun <T> Pair<T, T>.both(func: (T) -> Unit)

Perform the given function on both elements of this pair. The highest common type of both elements is used as the type of the parameter.

Link copied to clipboard
inline fun cl0(a: Float, b: Float): Float

Returns the value closer to zero.

Link copied to clipboard
inline fun cl1(a: Float, b: Float): Float

Returns the value closer to one.

Link copied to clipboard
fun CharSequence.closestToPoint(renderer: Renderer, font: Font, fontSize: Float, x: Float): Int

Returns the closest character index from the given string to the given point x.

Link copied to clipboard
inline fun Float.coerceWithin(a: Float, b: Float): Float

coerceIn which doesn't require a to be less than b.

Link copied to clipboard
fun <L : MutableList<E>, RandomAccess, E> L.cut(from: Int, to: Int): L

Returns this list, with all elements not in the range from..to removed.

Link copied to clipboard
inline fun <T> Ref.ObjectRef<T>.deref(): T

Return the value of this Ref.ObjectRef.

Link copied to clipboard
Link copied to clipboard
fun String.dropAt(index: Int = lastIndex, amount: Int = 1): String
Link copied to clipboard
Link copied to clipboard
inline fun <T> MutableList<T>.ensureSize(size: Int, initializer: (Int) -> T): MutableList<T>

Ensure that this list is at least size elements long, and if it is not, add elements to it using the given initializer.

Link copied to clipboard
inline fun <L : List<E>, RandomAccess, E> L.fastAll(predicate: (E) -> Boolean): Boolean

Returns true if all elements match the given predicate.

Link copied to clipboard
inline fun <L : List<E>, RandomAccess, E> L.fastAny(predicate: (E) -> Boolean): Boolean

Returns true if all elements match the given predicate.

Link copied to clipboard
inline fun <L : List<E>, RandomAccess, E> L.fastEach(func: (E) -> Unit)

no-alloc Iterable.forEach which utilizes RandomAccess to get the elements.

Link copied to clipboard
inline fun <L : List<E>, RandomAccess, E> L.fastEachIndexed(func: (Int, E) -> Unit)

no-alloc Iterable.forEachIndexed which utilizes RandomAccess to get the elements.

Link copied to clipboard
inline fun <L : List<E>, RandomAccess, E> L.fastEachReversed(func: (E) -> Unit)

no-alloc List.forEach which utilizes RandomAccess to get the elements, backwards.

Link copied to clipboard
inline fun <L : MutableList<E>, RandomAccess, E> L.fastRemoveIf(predicate: (E) -> Boolean)

no-alloc MutableList.removeIf which utilizes RandomAccess to get the elements.

Link copied to clipboard
inline fun <L : MutableList<E>, RandomAccess, E> L.fastRemoveIfReversed(predicate: (E) -> Boolean)

no-alloc MutableList.removeIf which utilizes RandomAccess to get the elements.

Link copied to clipboard
fun Int.gcd(b: Int): Int

Calculate the greatest common denominator of two integers.

Link copied to clipboard
fun <E : Enum<E>> EnumEntries<E>.getByName(name: String?, ignoreCase: Boolean = false): E?

Get an enum constant by its name, or null if name is null; or does not match any of this enum's constants.

Link copied to clipboard
fun getResourceStream(resourcePath: String, caller: Class<*> = PolyUI::class.java): InputStream

return a stream of the given resource or throws an exception.

Link copied to clipboard
fun getResourceStreamNullable(resourcePath: String, caller: Class<*> = PolyUI::class.java): InputStream?

return a stream of the given resource, or null.

Link copied to clipboard
inline fun String.image(): PolyImage
Link copied to clipboard

calculate the levenshtein distance between this string and the other string.

Link copied to clipboard
inline fun <L : List<E>, RandomAccess, E, R> L.mapToArray(transform: (E) -> R): Array<R>
inline fun <T, R> Collection<T>.mapToArray(transform: (T) -> R): Array<R>

Perform the given transform on every element in this list, and return a new array with the results.

inline fun <T, R> Array<T>.mapToArray(transform: (T) -> R): Array<R>

Perform the given transform on every element in this array, and return a new array with the results.

inline fun <K, V, R> Map<K, V>.mapToArray(transform: (Map.Entry<K, V>) -> R): Array<R>

Perform the given transform on every element in this map, and return a new array with the results.

Link copied to clipboard
inline fun <K, V> MutableMap<K, V>.maybeRemove(key: K, shouldRemove: Boolean): V?

Returns the value of the given key in the map, and if shouldRemove is true the value is also removed from the map.

Link copied to clipboard
inline fun min3(a: Int, b: Int, c: Int): Int

Returns the minimum value among three given ints.

Link copied to clipboard
inline fun <E> Array<E>.moveElement(from: Int, to: Int)

Moves the given element from the from index to the to index.

Link copied to clipboard
inline fun EnumEntries<*>.names(): List<String>

Return a list of the names of the entries in this enum.

Link copied to clipboard
inline fun <E> Collection<E>.nullIfEmpty(): Collection<E>?

Return null if this collection is empty, otherwise return this collection.

Link copied to clipboard
inline fun PolyUI.open(window: Window)
Link copied to clipboard
inline fun <T> T.ref(): Ref.ObjectRef<T>

Box the given value into a Ref.ObjectRef.

Link copied to clipboard
fun String.remove(char: Char): String
Link copied to clipboard
Link copied to clipboard
fun resourceExists(resourcePath: String, caller: Class<*> = PolyUI::class.java): Boolean
Link copied to clipboard
Link copied to clipboard
@JvmName(name = "simplifyRatio")
fun Vec2.simplifyRatio(): Vec2

Simplify a ratio of two integers.

Link copied to clipboard
inline fun <T> T.stdout(arg: Any? = null): T

print the object to stdout, then return it.

Link copied to clipboard
fun String.substringOr(fromIndex: Int, toIndex: Int, other: String): String
Link copied to clipboard
fun String.substringSafe(fromIndex: Int, toIndex: Int = lastIndex): String
Link copied to clipboard
fun String.substringToWidth(renderer: Renderer, font: Font, fontSize: Float, width: Float): Pair<String, String>

take the given string and cut it to the length, returning a pair of the string cut to the length, and the remainder.

Link copied to clipboard

Converts the InputStream into a byte array and close it.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline fun Double.toRadians(): Double
Link copied to clipboard
Link copied to clipboard
fun String.truncate(renderer: Renderer, font: Font, fontSize: Float, width: Float, limitText: String = "..."): String

Limit the given string to a width. If the string is too long, it will be cut to the width, and limitText will be appended to the end.

Link copied to clipboard
fun String.wrap(maxWidth: Float, renderer: Renderer, font: Font, fontSize: Float, lines: ArrayList<Line>?): ArrayList<Line>

Wrap the given text to the given width, inserting them into lines, or a new list is created if it is null. It also returned.