dreamworkAPI
Ctrl K
GitHub
classDocs / ViewportLayout

ViewportLayout

classclientmenusource
Object → ViewportLayout

A named set of CSS / viewport length descriptors that resolve to floored pixels and refresh when the window is resized.

Indexing a registered alias (hud.hex) returns the cached integer pixel length. Unknown keys fall through to the class prototype.

Handlers attached with :attach / :once run after the shared pixel cache is recomputed on OnScreenSizeChanged.

Construction raises ValueError if any descriptor cannot be parsed.

lua
local hud = ViewportLayout( {
    hex = "1vmin",
    t = "2vmin",
    h = "10cm",
    me = "12mm",
    d = "120px"
} )

print( hud.hex ) -- floored pixels for "1vmin"

hud:attach( function( layout, old_width, old_height, new_width, new_height )
    print( layout.hex ) -- refreshed after resize
end )

Constructor

ViewportLayout(definitions: table<string, string>): table<string, integer>

Static functions

#ViewportLayout.parse

clientmenunodiscardsource
function ViewportLayout.parse(descriptor: string): integer

Parses a display length string into floored CSS pixels.

Raises ValueError with "missing magnitude", "missing unit type", or "unsupported unit" when the descriptor cannot be parsed.

lua
ViewportLayout.parse( "120px" ) -- 120
ViewportLayout.parse( "10cm" )  -- floored CSS pixels at 96 DPI
ViewportLayout.parse( "1vmin" ) -- floored pixels from current window size
Parameters
NameTypeDescription
descriptorstringThe length quantity string to parse ("<number><ViewportUnit>").
Returns
TypeNameDescription
integerpixelsThe floored pixel length.

Methods

attachAttaches a handler that runs after this layout's pixel values are refreshed on screen resize.
awaitWaits for the next screen-size refresh of this layout.
clearRemoves every resize handler attached to this layout.
detachDetaches a previously attached resize handler.
onceAttaches a one-shot resize handler that detaches itself before running.

#ViewportLayout:attach

clientmenusource
function ViewportLayout:attach(handler: fun( layout: ViewportLayout, old_width: integer, old_height: integer, new_width: integer, new_height: integer ) | Hook | Event)

Attaches a handler that runs after this layout's pixel values are refreshed on screen resize.

Attaching the same handler twice is a no-op, handlers run in protected mode.

Parameters
NameTypeDescription
handlerfun( layout: ViewportLayout, old_width: integer, old_height: integer, new_width: integer, new_height: integer ) | Hook | EventThe callback or callable object.

#ViewportLayout:await

clientmenuasyncsource
async function ViewportLayout:await(): ViewportLayout, integer, integer, integer, integer

Waits for the next screen-size refresh of this layout.

Returns
TypeNameDescription
ViewportLayoutlayout
integerold_width
integerold_height
integernew_width
integernew_height

#ViewportLayout:clear

clientmenusource
function ViewportLayout:clear()

Removes every resize handler attached to this layout.

#ViewportLayout:detach

clientmenusource
function ViewportLayout:detach(handler: fun( layout: ViewportLayout, old_width: integer, old_height: integer, new_width: integer, new_height: integer ) | Hook | Event): boolean

Detaches a previously attached resize handler.

Parameters
NameTypeDescription
handlerfun( layout: ViewportLayout, old_width: integer, old_height: integer, new_width: integer, new_height: integer ) | Hook | EventThe exact handler reference.
Returns
TypeNameDescription
booleanremovedtrue if the handler was attached.

#ViewportLayout:once

clientmenusource
function ViewportLayout:once(handler: fun( layout: ViewportLayout, old_width: integer, old_height: integer, new_width: integer, new_height: integer ) | Hook | Event)

Attaches a one-shot resize handler that detaches itself before running.

Parameters
NameTypeDescription
handlerfun( layout: ViewportLayout, old_width: integer, old_height: integer, new_width: integer, new_height: integer ) | Hook | EventThe callback or callable object.
Generated from the dreamwork meta branch.