PolyUI

class PolyUI @JvmOverloads constructor(drawables: Drawable, val renderer: Renderer, settings: Settings? = null, inputManager: InputManager? = null, translator: Translator? = null, backgroundColor: PolyColor? = null, masterAlignment: Align = Align(cross = Align.Cross.Start, pad = Vec2.ZERO), colors: Colors = DarkTheme(), size: Vec2? = null)

PolyUI

PolyUI is a declarative UI framework developed for, and by Polyfrost.

It is designed to be lightweight, fast, extensible and easy to use, while still being very powerful. Make sure to check out the examples for more information.

PolyUI is split into two parts, being PolyUI and its logic, and it's accompanying Renderer implementation. This allows us to have PolyUI in many places, including inside Minecraft! It is declarative, meaning that you don't have to worry about the logic of the UI, just the layout and the components.

Rendering Pipeline

PolyUI has the policy of 'render what you need ONLY WHEN you need it'. Most of the time, PolyUI will be drawing frame buffers to the screen instead of drawing directly to the screen, as long as they are suitably complex for it to be worth it; or not drawing at all! This allows us to have a very fast rendering pipeline, and allows us to have a lot of components on screen at once, without a performance hit.

Rendering can be requested by components, and if so, it will be rendered during the next frame. This should only be requested if it is necessary, for example to do an animation or something.

During a render cycle, PolyUI will systematically go through every layout, and render it to its framebuffer or to the screen. Each layout will then render its components and child layouts, and so on. Rendering happens in three steps:

  • preRender: This will do pre-rendering logic, such as setting up transformations, updating animations, and more.

  • render: This is where the actual rendering happens.

  • postRender: This will do post-rendering logic, such as cleaning up transformations.

Check out some components to see how this works.

How it Works

Components are the interactive parts of the UI, such as buttons, text fields, etc.

Interactions are driven by events, which thanks to Kotlin's inlining are a zero-overhead way of distributing events, such as mouse clicks, or key presses.

PolyUI also supports a variety of animations and transitions, which can be used to make your UI more dynamic, along with dynamically adding and removing components.

Constructors

Link copied to clipboard
constructor(vararg drawables: Drawable, renderer: Renderer, settings: Settings? = null, inputManager: InputManager? = null, translator: Translator? = null, backgroundColor: PolyColor? = null, masterAlignment: Align = Align(cross = Align.Cross.Start, pad = Vec2.ZERO), colors: Colors = DarkTheme(), size: Vec2? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

returns true if render pausing is possible.

Link copied to clipboard
Link copied to clipboard

Access the system clipboard as a string.

Link copied to clipboard
Link copied to clipboard

Colors attached to this PolyUI instance. This contains all the colors needed for the UI.

Link copied to clipboard

The cursor currently being displayed.

Link copied to clipboard

the debugger attached to this PolyUI instance.

Link copied to clipboard
var delta: Long

the time since the last frame, in nanoseconds. It is used internally a lot for animations, etc.

Link copied to clipboard

weather this PolyUI instance drew on this frame.

Link copied to clipboard

Fonts attached to this PolyUI instance. This contains all the fonts needed for the UI.

Link copied to clipboard
Link copied to clipboard

this property stores the initial size of this PolyUI instance. It is used to make sure that new objects experience the same resizing as others.

Link copied to clipboard

Get the KeyBinder for this PolyUI instance.

Link copied to clipboard

This is the root layout of the UI. It is the parent of all other layouts.

Link copied to clipboard

Monospace font attached to this PolyUI instance. This is used for debugging and other purposes.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val size: Vec2
Link copied to clipboard
Link copied to clipboard

The window this polyUI was opened with.

Functions

Link copied to clipboard
Link copied to clipboard
fun cleanup()

cleanup the polyUI instance. This will delete all resources, and render this instance unusable.

Link copied to clipboard
fun every(nanos: Long, repeats: Int = 0, func: () -> Unit): Clock.Executor

add a function that is called every nanos nanoseconds.

Link copied to clipboard
fun focus(focusable: Drawable)

Sets the focus to the specified focusable element.

Link copied to clipboard
fun getKeyName(key: Int): String

Return the key name for the given key code, or "Unknown" if the key is not mapped / no window is present.

Link copied to clipboard
fun PolyUI.open(window: Window)
Link copied to clipboard

Remove a clock-based executor from this PolyUI instance.

Link copied to clipboard
fun render(): Long

Perform a render cycle.

Link copied to clipboard
fun resize(newWidth: Float, newHeight: Float, force: Boolean = false)

Resize this PolyUI instance.

Link copied to clipboard
inline fun timed(msg: String? = null, block: () -> Unit): Long

Time the block and return how long it took, as well as logging with the msg if debug is active.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun unfocus()