| 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 |