LayoutWidget

class LayoutWidget @JvmOverloads constructor(x: Pos = AbsPos(0), y: Pos = AbsPos(0), paddingW: Int = 8, paddingH: Int = paddingW, spacingW: Int = 4, spacingH: Int = spacingW) : Widget, Scalable

A powerful widget used to heuristically layout out multiple element widgets in a manner akin to web DOM layout. Widgets stored in a layout can be automatically repositioned, scaled, queried, and categorized. NOTE: LayoutWidget is not a ParentElement, it is expected that you extract the elements from the layout and add them as children to a parent that contains this layout. The layout is only for positioning.

Author

fzzyhmstrs

Since

0.6.0

Parameters

x

Pos, optional. The x position of this widget. Default is AbsPos of 0. This initial position can be overwritten later with setPos

y

Pos, optional. The y position of this widget. Default is AbsPos of 0. This initial position can be overwritten later with setPos

paddingW

Int, optional. Default 8px. The horizontal space given around the left/right edge of the layout (where the border would go visually). Unlike the DOM, there is no margin/padding duo, just padding.

paddingH

Int, optional. Default whatever paddingW is. The vertical space given around the top/bottom edge of the layout (where the border would go visually). Unlike the DOM, there is no margin/padding duo, just padding.

spacingW

Int, optional. Default 4. The horizontal space between elements. This can be modified per element as needed with pushSpacing and popSpacing

spacingH

Int, optional. Default whatever spacingW is. The vertical space between elements. This can be modified per element as needed with pushSpacing and popSpacing

Constructors

Link copied to clipboard
constructor(x: Pos = AbsPos(0), y: Pos = AbsPos(0), paddingW: Int = 8, paddingH: Int = paddingW, spacingW: Int = 4, spacingH: Int = spacingW)

Types

Link copied to clipboard
interface LayoutElement
Link copied to clipboard
sealed interface Position

A layout position to apply to a popup element

Functions

Link copied to clipboard
fun <E : Widget> add(id: String, element: E, vararg positions: LayoutWidget.Position): LayoutWidget

Adds an element, automatically keyed off the last added element (or "" if this is the first added element).

fun <E : Widget> add(id: String, element: E, parent: String, vararg positions: LayoutWidget.Position): LayoutWidget

Adds an element, keyed off a manually defined parent element.

Link copied to clipboard
fun categorize(children: MutableList<Element>, drawables: MutableList<Drawable>, selectables: MutableList<Selectable>, other: Consumer<Widget> = Consumer { _-> })

Categorizes the elements in this layout into the three constituent components many screens/parents care about, as well as providing a method for arbitrary categorization

Link copied to clipboard

Same as setH but returns itself, and won't recompute if the layout is empty. This is often used up front to, as the name implies, clamp the allowable height of a new layout before adding elements.

Link copied to clipboard

Same as setW but returns itself, and won't recompute if the layout is empty. This is often used up front to, as the name implies, clamp the allowable width of a new layout before adding elements.

Link copied to clipboard
fun compute(debug: Boolean = false): LayoutWidget
Link copied to clipboard

Recursively retrieves the named element. Starts with this layout's elements, then burrows into nested layouts' elements as applicable.

Link copied to clipboard

The horizontal padding of this layout.

Link copied to clipboard

The general horizontal spacing of this layout. Does not take into account the current state of the spacing stack.

Link copied to clipboard

The vertical padding of this layout.

Link copied to clipboard

The general vertical spacing of this layout. Does not take into account the current state of the spacing stack.

Link copied to clipboard
open override fun getHeight(): Int

Returns the height of this widget. If height has been clamped, will return that manual height, otherwise the automatically computed height.

Link copied to clipboard
open fun getNavigationFocus(): ScreenRect
Link copied to clipboard
open override fun getWidth(): Int

Returns the width of this widget. If width has been clamped, will return that manual width, otherwise the automatically computed width.

Link copied to clipboard
open override fun getX(): Int

Returns the current X screen position of this widget. Uses the position from the x

Link copied to clipboard
open override fun getY(): Int

Returns the current Y screen position of this widget. Uses the position from the y

Link copied to clipboard

Returns whether this layout has no elements yet.

Link copied to clipboard

Returns the id of the last element added to this widget, or "" if none have been added yet

Link copied to clipboard

Pops a set of custom spacing off this widgets spacing stack. If all custom spacings are popped, will revert to the default spacing provided in the constructor

Link copied to clipboard

Push a custom element spacing to this widgets spacing stack. any elements added after this push will be spaced using the top h/w spacing on that stack, or the default spacing provided in the widget constructor if no custom spacing exists on the stack

Link copied to clipboard
fun setDimensions(width: Int, height: Int)

Sets a manual width and height for this layout. Will override any automatically computed dimensions.

Link copied to clipboard
open override fun setH(height: Int)

Sets a manual height for this layout. Will override any automatically computed height

Link copied to clipboard
fun setPos(x: Pos, y: Pos): LayoutWidget

Sets the X and Y anchor positions this layout is positioned against. The widget will wrap the positions in a RelPos to avoid mutating external position state.

Link copied to clipboard
open override fun setPosition(x: Int, y: Int)

Sets the X and Y coordinate of this layout. This updates the x and y, so will overwrite and reference made with setPos.

Link copied to clipboard
open override fun setW(width: Int)

Sets a manual width for this layout. Will override any automatically computed widths.

Link copied to clipboard
open override fun setX(x: Int)

Sets the X coordinate of this layout. This updates the x, so will overwrite and reference made with setPos in the X dimension.

Link copied to clipboard
open override fun setY(y: Int)

Sets the Y coordinate of this layout. This updates the y, so will overwrite and reference made with setPos in the Y dimension.

Link copied to clipboard
fun update()