Give every behavior variable one row shape on asset and instance
buildStructBlock only covered structs, so a placed instance drew numbers,
text, bools and lists through createFieldRow on a 64 px name column while
its struct block sat on the asset's grid below it. variableRows.ts now
builds the row for every variable kind on both sides; the edit option
decides what the owner may change (asset: rename, x, item kind; instance:
revert and push). Label and Button take a fixed width so the mark column
no longer shifts names when a list shows its item-kind picker.
The two structFields calls that became dead with 9f48257 are gone. The
e2e steps locate the Enabled toggle through __gm.inspectorField instead
of clicking a fixed offset from its label.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9f482573e5
commit
631cf54c72
17 files changed
+515
-472
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { type FederatedPointerEvent, Graphics, Text, CanvasTextMetrics } from 'pixi.js';
|
||||
import { drawControlBox } from '../draw';
|
||||
import { centreY } from '../math';
|
||||
import { Theme, textStyle } from '../Theme';
|
||||
import { Theme, textStyle, type TextStyleToken } from '../Theme';
|
||||
import { type Size, Widget } from '../Widget';
|
||||
import { truncate } from './Label';
|
||||
|
||||
@@ -12,6 +12,8 @@ export interface ButtonOptions {
|
||||
/** Floor only – for a button whose label changes between forms and must grow with them. */
|
||||
minWidth?: number;
|
||||
align?: 'center' | 'left';
|
||||
/** Text style of the label when the button is not on an accent fill. */
|
||||
style?: TextStyleToken;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
@@ -26,6 +28,7 @@ export class Button extends Widget {
|
||||
variant: NonNullable<ButtonOptions['variant']>;
|
||||
protected readonly align: NonNullable<ButtonOptions['align']>;
|
||||
protected readonly fixedWidth: number;
|
||||
private readonly style: TextStyleToken;
|
||||
onClick?: () => void;
|
||||
|
||||
constructor(text: string, options: ButtonOptions = {}) {
|
||||
@@ -39,7 +42,8 @@ export class Button extends Widget {
|
||||
this.fixedWidth = options.width ?? 0;
|
||||
this.minWidth = this.fixedWidth || (options.minWidth ?? 0);
|
||||
this.fullText = text;
|
||||
this.labelText = new Text({ text, style: textStyle(this.variant === 'primary' ? 'accent' : 'body') });
|
||||
this.style = options.style ?? 'body';
|
||||
this.labelText = new Text({ text, style: textStyle(this.variant === 'primary' ? 'accent' : this.style) });
|
||||
this.addChild(this.bg, this.labelText);
|
||||
|
||||
// Leaving while pressed cancels the click: a release elsewhere must not activate.
|
||||
@@ -148,7 +152,7 @@ export class Button extends Widget {
|
||||
this.bg.roundRect(0.5, 0.5, this.w - 1, this.h - 1, Theme.radius).stroke({ width: 1, color: stroke });
|
||||
}
|
||||
// Style first: it decides the glyph widths that the truncation then measures against.
|
||||
this.labelText.style = textStyle(this.onAccent ? 'accent' : 'body');
|
||||
this.labelText.style = textStyle(this.onAccent ? 'accent' : this.style);
|
||||
const label = this.labelText;
|
||||
label.text = truncate(this.fullText, label.style, this.labelSlot());
|
||||
const x = this.align === 'left' ? Theme.padding : (this.w - label.width) / 2;
|
||||
|
||||
@@ -7,6 +7,8 @@ export interface LabelOptions {
|
||||
style?: TextStyleToken;
|
||||
align?: 'left' | 'center' | 'right';
|
||||
padding?: number;
|
||||
/** Fixed width – a column that must not grow with a long text; the text is truncated instead. */
|
||||
width?: number;
|
||||
}
|
||||
|
||||
/** Single-line text that truncates with an ellipsis when narrower than its content. */
|
||||
@@ -15,6 +17,7 @@ export class Label extends Widget {
|
||||
private fullText: string;
|
||||
private readonly align: NonNullable<LabelOptions['align']>;
|
||||
private readonly padding: number;
|
||||
private readonly fixedWidth: number;
|
||||
|
||||
constructor(text = '', options: LabelOptions = {}) {
|
||||
super();
|
||||
@@ -22,6 +25,8 @@ export class Label extends Widget {
|
||||
this.fullText = text;
|
||||
this.align = options.align ?? 'left';
|
||||
this.padding = options.padding ?? 0;
|
||||
this.fixedWidth = options.width ?? 0;
|
||||
this.minWidth = this.fixedWidth;
|
||||
this.textNode = new Text({ text, style: textStyle(options.style ?? 'body') });
|
||||
this.addChild(this.textNode);
|
||||
this.minHeight = Theme.rowHeight;
|
||||
@@ -45,6 +50,7 @@ export class Label extends Widget {
|
||||
}
|
||||
|
||||
override measure(): Size {
|
||||
if (this.fixedWidth) return { w: this.fixedWidth, h: this.minHeight };
|
||||
const metrics = CanvasTextMetrics.measureText(this.fullText, this.textNode.style);
|
||||
return {
|
||||
w: Math.max(this.minWidth, Math.ceil(metrics.width) + this.padding * 2),
|
||||
|
||||
Reference in new issue
Block a user