@energy8platform/game-engine 0.15.0 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -2944,24 +2944,29 @@ function measureChild(child, parentContentW = 0, parentContentH = 0) {
2944
2944
  const cfg = child._flexConfig;
2945
2945
  const resolvedLW = resolveDimension(cfg?.layoutWidth, parentContentW);
2946
2946
  const resolvedLH = resolveDimension(cfg?.layoutHeight, parentContentH);
2947
- if (resolvedLW !== undefined && resolvedLH !== undefined) {
2948
- return { w: resolvedLW, h: resolvedLH, ox: 0, oy: 0 };
2949
- }
2950
- // For FlexContainers, use their explicit or computed size
2947
+ // FlexContainer children are top-left origin by construction, so `ox/oy = 0`
2948
+ // is correct and we can skip the `getLocalBounds()` call entirely.
2951
2949
  if (child instanceof FlexContainer) {
2952
2950
  const fc = child;
2953
2951
  const w = fc._explicitWidth > 0 ? fc._explicitWidth : (fc._computedWidth > 0 ? fc._computedWidth : undefined);
2954
2952
  const h = fc._explicitHeight > 0 ? fc._explicitHeight : (fc._computedHeight > 0 ? fc._computedHeight : undefined);
2955
2953
  if (w !== undefined && h !== undefined) {
2956
- return { w, h, ox: 0, oy: 0 };
2954
+ return { w: resolvedLW ?? w, h: resolvedLH ?? h, ox: 0, oy: 0 };
2957
2955
  }
2958
2956
  }
2959
- // Use localBounds to get the true visual extent and origin offset.
2960
- // This handles children with non-zero anchors (e.g. Button, Label with centered text).
2957
+ // Use localBounds to get the true visual origin offset.
2958
+ // We take `ox/oy` from bounds unconditionally a user-supplied `layoutWidth/Height`
2959
+ // overrides the SIZE used by flex (protection against pre-paint bounds of 0), but
2960
+ // it must NOT erase the center-anchor compensation: Button/Label views are drawn at
2961
+ // `(-w/2..w/2)` and their bounds.x = -w/2 is what lets `layoutLine` place the
2962
+ // visible rectangle where the layout intends.
2961
2963
  const bounds = child.getLocalBounds();
2962
- const w = resolvedLW ?? bounds.width;
2963
- const h = resolvedLH ?? bounds.height;
2964
- return { w, h, ox: bounds.x, oy: bounds.y };
2964
+ return {
2965
+ w: resolvedLW ?? bounds.width,
2966
+ h: resolvedLH ?? bounds.height,
2967
+ ox: bounds.x,
2968
+ oy: bounds.y,
2969
+ };
2965
2970
  }
2966
2971
  /**
2967
2972
  * Set a child's main or cross dimension.
@@ -3450,30 +3455,35 @@ class FlexContainer extends Container {
3450
3455
  this._computedHeight = this._explicitHeight > 0 ? this._explicitHeight : (pt + naturalMainSize + pb);
3451
3456
  }
3452
3457
  // Position flexExclude children (absolute positioning).
3453
- // All position props describe the visual (bounds) rectangle, so we subtract
3454
- // `ox/oy` to compensate for children with a centered origin (Button, Label).
3458
+ // All position props describe the visual (bounds) rectangle. We derive the
3459
+ // visual rectangle directly from `getLocalBounds()` rather than the
3460
+ // layout-config `w`/`h` returned by measureChild — those may differ from
3461
+ // actual bounds when the user pins `layoutWidth`/`layoutHeight` to a value
3462
+ // that doesn't match the child's real visual extent (e.g. a Button whose
3463
+ // text overflows its configured `width`). Mixing layout size with real
3464
+ // bounds-origin would shift the visual center off the requested point.
3455
3465
  // `centerX/centerY` take precedence over `left/right` / `top/bottom` on each axis.
3456
3466
  for (const child of this._layoutChildren) {
3457
3467
  if (!child._flexConfig?.flexExclude)
3458
3468
  continue;
3459
3469
  const cfg = child._flexConfig;
3460
- const { w, h, ox, oy } = measureChild(child, pctRefW, pctRefH);
3470
+ const bounds = child.getLocalBounds();
3461
3471
  const cw = this._computedWidth;
3462
3472
  const ch = this._computedHeight;
3463
3473
  const centerX = resolveDimension(cfg.centerX, pctRefW);
3464
3474
  if (centerX !== undefined)
3465
- child.x = centerX - w / 2 - ox;
3475
+ child.x = centerX - bounds.x - bounds.width / 2;
3466
3476
  else if (cfg.left !== undefined)
3467
- child.x = cfg.left - ox;
3477
+ child.x = cfg.left - bounds.x;
3468
3478
  else if (cfg.right !== undefined)
3469
- child.x = cw - w - cfg.right - ox;
3479
+ child.x = cw - cfg.right - bounds.x - bounds.width;
3470
3480
  const centerY = resolveDimension(cfg.centerY, pctRefH);
3471
3481
  if (centerY !== undefined)
3472
- child.y = centerY - h / 2 - oy;
3482
+ child.y = centerY - bounds.y - bounds.height / 2;
3473
3483
  else if (cfg.top !== undefined)
3474
- child.y = cfg.top - oy;
3484
+ child.y = cfg.top - bounds.y;
3475
3485
  else if (cfg.bottom !== undefined)
3476
- child.y = ch - h - cfg.bottom - oy;
3486
+ child.y = ch - cfg.bottom - bounds.y - bounds.height;
3477
3487
  }
3478
3488
  }
3479
3489
  /** Computed content size (after layout) */