MCPcopy Index your code
hub / github.com/KilledByAPixel/LittleJS / updateTransforms

Method updateTransforms

plugins/uiSystem.js:130–153  ·  view source on GitHub ↗
(o)

Source from the content-addressed store, hash-verified

128 // set object position based on anchor target (parent box, or canvas for roots),
129 // self-pivot, and localPos offset
130 function updateTransforms(o)
131 {
132 let targetPos, targetSize;
133 if (o.parent)
134 {
135 targetPos = o.parent.pos;
136 targetSize = o.parent.size;
137 }
138 else
139 {
140 // anchor to canvas in native coords (handles nativeHeight if set)
141 targetPos = uiSystem.screenToNative(mainCanvasSize.scale(.5));
142 targetSize = uiSystem.nativeHeight
143 ? vec2(mainCanvasSize.x * uiSystem.nativeHeight / mainCanvasSize.y,
144 uiSystem.nativeHeight)
145 : mainCanvasSize;
146 }
147
148 const a = o.anchor;
149 o.pos = targetPos
150 .add(targetSize.multiply(a).scale(.5)) // anchor point on target
151 .subtract(o.size.multiply(a).scale(.5)) // pivot shift on self
152 .add(o.localPos); // user offset
153 }
154
155 // setup recursive update and render
156 // update in reverse order to detect mouse enter/leave

Callers

nothing calls this directly

Calls 6

vec2Function · 0.85
screenToNativeMethod · 0.80
scaleMethod · 0.45
addMethod · 0.45
subtractMethod · 0.45
multiplyMethod · 0.45

Tested by

no test coverage detected