@eva/plugin-ui 2.1.0-beta.2 → 2.1.0-beta.4

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.
@@ -508,6 +508,37 @@ function resolveViewRef(game, go, ref) {
508
508
  }
509
509
  return null;
510
510
  }
511
+ /**
512
+ * @pixi/ui ProgressBar 的非 nine-slice fillPaddings 只移动 fill.x/y,
513
+ * 不会自动把 fill view 缩成内层尺寸。DSL 常用的 inline color/shape
514
+ * 需要先扣除 padding,否则 fill 会向下或向右溢出,造成上下层偏差。
515
+ */
516
+ function normalizeProgressFillViewRef(ref, fillPaddings, fallbackSize) {
517
+ if (!ref)
518
+ return ref;
519
+ const paddings = normalizePaddings(fillPaddings);
520
+ if (paddings.top === 0 && paddings.right === 0 && paddings.bottom === 0 && paddings.left === 0) {
521
+ return ref;
522
+ }
523
+ const fallback = ref.fallback
524
+ ? normalizeProgressFillViewRef(ref.fallback, paddings, fallbackSize)
525
+ : undefined;
526
+ if ('color' in ref) {
527
+ const width = shrinkSize(ref.width, paddings.left + paddings.right);
528
+ const height = shrinkSize(ref.height, paddings.top + paddings.bottom);
529
+ return Object.assign(Object.assign(Object.assign({}, ref), { width,
530
+ height, radius: shrinkRadius(ref.radius, width, height) }), (fallback ? { fallback } : {}));
531
+ }
532
+ if ('shape' in ref) {
533
+ return Object.assign(Object.assign(Object.assign({}, ref), { shape: shrinkInlineShape(ref.shape, paddings, fallbackSize) }), (fallback ? { fallback } : {}));
534
+ }
535
+ if ('ui' in ref) {
536
+ return Object.assign(Object.assign(Object.assign({}, ref), { ui: shrinkInlineShape(ref.ui, paddings, fallbackSize) }), (fallback ? { fallback } : {}));
537
+ }
538
+ if (fallback)
539
+ return Object.assign(Object.assign({}, ref), { fallback });
540
+ return ref;
541
+ }
511
542
  function wrapBorrowedEntityView(childContainer, childName) {
512
543
  const wrapper = new Container();
513
544
  wrapper.label = childName ? `${childName}:view-ref` : 'plugin-ui-view-ref';
@@ -535,26 +566,28 @@ function resolveTexture(game, key) {
535
566
  }
536
567
  }
537
568
  function drawInlineShape(shape) {
538
- var _a, _b, _c;
569
+ var _a, _b, _c, _d, _e;
539
570
  if (!shape || !shape.type)
540
571
  return null;
541
572
  const g = new Graphics$1();
542
573
  const { style } = shape;
543
- const w = (_a = style.width) !== null && _a !== void 0 ? _a : 0;
544
- const h = (_b = style.height) !== null && _b !== void 0 ? _b : 0;
545
- const r = (_c = style.radius) !== null && _c !== void 0 ? _c : 0;
574
+ const x = (_a = style.x) !== null && _a !== void 0 ? _a : 0;
575
+ const y = (_b = style.y) !== null && _b !== void 0 ? _b : 0;
576
+ const w = (_c = style.width) !== null && _c !== void 0 ? _c : 0;
577
+ const h = (_d = style.height) !== null && _d !== void 0 ? _d : 0;
578
+ const r = (_e = style.radius) !== null && _e !== void 0 ? _e : 0;
546
579
  switch (shape.type) {
547
580
  case 'rect':
548
- g.rect(0, 0, w, h);
581
+ drawRect(g, x, y, w, h);
549
582
  break;
550
583
  case 'roundedRect':
551
- g.roundRect(0, 0, w, h, r);
584
+ drawRoundedRect(g, x, y, w, h, r);
552
585
  break;
553
586
  case 'circle':
554
- g.circle(r, r, r);
587
+ drawCircle(g, x + r, y + r, r);
555
588
  break;
556
589
  case 'ellipse':
557
- g.ellipse(w / 2, h / 2, w / 2, h / 2);
590
+ drawEllipse(g, x + w / 2, y + h / 2, w / 2, h / 2);
558
591
  break;
559
592
  }
560
593
  if (style.fill !== undefined)
@@ -576,6 +609,79 @@ function drawInlineShape(shape) {
576
609
  catch (_) { }
577
610
  return g;
578
611
  }
612
+ function drawRect(g, x, y, width, height) {
613
+ const anyGraphics = g;
614
+ if (typeof anyGraphics.rect === 'function') {
615
+ anyGraphics.rect(x, y, width, height);
616
+ return;
617
+ }
618
+ anyGraphics.drawRect(x, y, width, height);
619
+ }
620
+ function drawRoundedRect(g, x, y, width, height, radius) {
621
+ const anyGraphics = g;
622
+ if (typeof anyGraphics.roundRect === 'function') {
623
+ anyGraphics.roundRect(x, y, width, height, radius);
624
+ return;
625
+ }
626
+ anyGraphics.drawRoundedRect(x, y, width, height, radius);
627
+ }
628
+ function drawCircle(g, x, y, radius) {
629
+ const anyGraphics = g;
630
+ if (typeof anyGraphics.circle === 'function') {
631
+ anyGraphics.circle(x, y, radius);
632
+ return;
633
+ }
634
+ anyGraphics.drawCircle(x, y, radius);
635
+ }
636
+ function drawEllipse(g, x, y, halfWidth, halfHeight) {
637
+ const anyGraphics = g;
638
+ if (typeof anyGraphics.ellipse === 'function') {
639
+ anyGraphics.ellipse(x, y, halfWidth, halfHeight);
640
+ return;
641
+ }
642
+ anyGraphics.drawEllipse(x, y, halfWidth, halfHeight);
643
+ }
644
+ function normalizePaddings(fillPaddings) {
645
+ return {
646
+ top: readPadding(fillPaddings === null || fillPaddings === void 0 ? void 0 : fillPaddings.top),
647
+ right: readPadding(fillPaddings === null || fillPaddings === void 0 ? void 0 : fillPaddings.right),
648
+ bottom: readPadding(fillPaddings === null || fillPaddings === void 0 ? void 0 : fillPaddings.bottom),
649
+ left: readPadding(fillPaddings === null || fillPaddings === void 0 ? void 0 : fillPaddings.left),
650
+ };
651
+ }
652
+ function readPadding(value) {
653
+ if (typeof value !== 'number' || !Number.isFinite(value))
654
+ return 0;
655
+ return Math.max(0, value);
656
+ }
657
+ function shrinkSize(value, inset) {
658
+ return Math.max(0, value - inset);
659
+ }
660
+ function shrinkOptionalSize(value, fallback, inset) {
661
+ if (typeof value === 'number')
662
+ return shrinkSize(value, inset);
663
+ if (typeof fallback === 'number')
664
+ return shrinkSize(fallback, inset);
665
+ return value;
666
+ }
667
+ function shrinkRadius(radius, width, height) {
668
+ if (typeof radius !== 'number' || !Number.isFinite(radius))
669
+ return radius;
670
+ const limits = [radius];
671
+ if (typeof width === 'number')
672
+ limits.push(width / 2);
673
+ if (typeof height === 'number')
674
+ limits.push(height / 2);
675
+ return Math.max(0, Math.min(...limits));
676
+ }
677
+ function shrinkInlineShape(shape, paddings, fallbackSize) {
678
+ var _a;
679
+ const style = (_a = shape.style) !== null && _a !== void 0 ? _a : {};
680
+ const width = shrinkOptionalSize(style.width, fallbackSize === null || fallbackSize === void 0 ? void 0 : fallbackSize.width, paddings.left + paddings.right);
681
+ const height = shrinkOptionalSize(style.height, fallbackSize === null || fallbackSize === void 0 ? void 0 : fallbackSize.height, paddings.top + paddings.bottom);
682
+ const radius = shrinkRadius(style.radius, width, height);
683
+ return Object.assign(Object.assign({}, shape), { style: Object.assign(Object.assign(Object.assign(Object.assign({}, style), (width !== undefined ? { width } : {})), (height !== undefined ? { height } : {})), (radius !== undefined ? { radius } : {})) });
684
+ }
579
685
  /**
580
686
  * 在 GameObject 的 transform.children 中查找指定名字的子 entity。
581
687
  * 不递归 — plugin-ui 的视觉子项语义只允许直接子节点。
@@ -2658,12 +2764,16 @@ var UISystem$1 = UISystem;
2658
2764
  */
2659
2765
  function inlineResolveSpecialViews(name, c, game, go) {
2660
2766
  switch (name) {
2661
- case 'ProgressBar':
2767
+ case 'ProgressBar': {
2768
+ const fillView = c.nineSliceSprite
2769
+ ? c.fillView
2770
+ : normalizeProgressFillViewRef(c.fillView, c.fillPaddings, { width: c.width, height: c.height });
2662
2771
  c.__resolved_bg = resolveViewRef(game, go, c.bgView);
2663
- c.__resolved_fill = resolveViewRef(game, go, c.fillView);
2772
+ c.__resolved_fill = resolveViewRef(game, go, fillView);
2664
2773
  c.__resolved_bg_view = c.nineSliceSprite && c.bgView && 'texture' in c.bgView ? c.bgView.texture : c.__resolved_bg;
2665
2774
  c.__resolved_fill_view = c.nineSliceSprite && c.fillView && 'texture' in c.fillView ? c.fillView.texture : c.__resolved_fill;
2666
2775
  break;
2776
+ }
2667
2777
  case 'Select':
2668
2778
  c.__resolved_closedView = resolveViewRef(game, go, c.closedView);
2669
2779
  c.__resolved_openView = resolveViewRef(game, go, c.openView);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-ui",
3
- "version": "2.1.0-beta.2",
3
+ "version": "2.1.0-beta.4",
4
4
  "description": "@eva/plugin-ui",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-ui.esm.js",
@@ -19,9 +19,9 @@
19
19
  "license": "MIT",
20
20
  "homepage": "https://eva.js.org",
21
21
  "dependencies": {
22
- "@eva/eva.js": "2.1.0-beta.2",
23
- "@eva/plugin-renderer": "2.1.0-beta.2",
24
- "@eva/plugin-renderer-graphics": "2.1.0-beta.2",
22
+ "@eva/eva.js": "2.1.0-beta.4",
23
+ "@eva/plugin-renderer": "2.1.0-beta.4",
24
+ "@eva/plugin-renderer-graphics": "2.1.0-beta.4",
25
25
  "@pixi/ui": "^2.3.2",
26
26
  "pixi.js": "^8.17.0"
27
27
  }