Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TextBox): update Text patching to allow for proper dimension setting and text centering #463

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ exports[`ControlRow renders 1`] = `
"visible": true,
"w": 880,
"x": -40,
"y": 68,
"y": 52,
"zIndex": 0,
},
"Title": {
Expand Down Expand Up @@ -671,7 +671,7 @@ exports[`ControlRow renders 1`] = `
"enabled": true,
"flex": false,
"flexItem": false,
"h": 48,
"h": 32,
"hasFinalFocus": false,
"hasFocus": false,
"isComponent": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export default class InlineContent extends Base {

_notifyAncestors() {
this.fireAncestors('$loadedInlineContent', this);
this.signal('loadedInlineContent', this.finalW, this.multiLineHeight);
this.signal('loadedInlineContent', {
w: this.finalW,
h: this.multiLineHeight
});
}

_contentLoaded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,10 @@ describe('InlineContent', () => {
'$loadedInlineContent',
inlineContent
);
expect(inlineContent.signal).toHaveBeenCalledWith(
'loadedInlineContent',
inlineContent.finalW,
inlineContent.multiLineHeight
);
expect(inlineContent.signal).toHaveBeenCalledWith('loadedInlineContent', {
w: inlineContent.finalW,
h: inlineContent.multiLineHeight
});
});

it('should truncate content that exceeds the defined max lines', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,11 @@ exports[`ScrollWrapper renders 1`] = `
"textColor": 4294506490,
"type": "TextTexture",
"verticalAlign": "middle",
"w": 24,
"wordWrapWidth": 48,
},
"visible": true,
"w": 0,
"w": 24,
"x": 0,
"y": 2,
"zIndex": 0,
Expand All @@ -511,7 +512,7 @@ exports[`ScrollWrapper renders 1`] = `
"enabled": true,
"flex": false,
"flexItem": true,
"h": 513,
"h": 342,
"hasFinalFocus": false,
"hasFocus": false,
"isComponent": true,
Expand All @@ -534,7 +535,7 @@ exports[`ScrollWrapper renders 1`] = `
],
"type": "TextBox",
"visible": true,
"w": 46.5,
"w": 36,
"x": 0,
"y": 0,
"zIndex": 0,
Expand All @@ -545,7 +546,7 @@ exports[`ScrollWrapper renders 1`] = `
"enabled": true,
"flex": true,
"flexItem": true,
"h": 513,
"h": 342,
"isComponent": undefined,
"mount": 0,
"mountX": 0,
Expand Down Expand Up @@ -666,10 +667,11 @@ exports[`ScrollWrapper renders a content array 1`] = `
"textColor": 4294506490,
"type": "TextTexture",
"verticalAlign": "middle",
"w": 48,
"wordWrapWidth": 48,
},
"visible": true,
"w": 0,
"w": 48,
"x": 0,
"y": 2,
"zIndex": 0,
Expand All @@ -680,7 +682,7 @@ exports[`ScrollWrapper renders a content array 1`] = `
"enabled": true,
"flex": false,
"flexItem": true,
"h": 33,
"h": 22,
"hasFinalFocus": false,
"hasFocus": false,
"isComponent": true,
Expand All @@ -703,7 +705,7 @@ exports[`ScrollWrapper renders a content array 1`] = `
],
"type": "TextBox",
"visible": true,
"w": 12,
"w": 72,
"x": 0,
"y": 0,
"zIndex": 0,
Expand Down Expand Up @@ -754,10 +756,11 @@ exports[`ScrollWrapper renders a content array 1`] = `
"textColor": 4294506490,
"type": "TextTexture",
"verticalAlign": "middle",
"w": 48,
"wordWrapWidth": 48,
},
"visible": true,
"w": 0,
"w": 48,
"x": 0,
"y": 2,
"zIndex": 0,
Expand All @@ -768,7 +771,7 @@ exports[`ScrollWrapper renders a content array 1`] = `
"enabled": true,
"flex": false,
"flexItem": true,
"h": 513,
"h": 342,
"hasFinalFocus": false,
"hasFocus": false,
"isComponent": true,
Expand All @@ -791,7 +794,7 @@ exports[`ScrollWrapper renders a content array 1`] = `
],
"type": "TextBox",
"visible": true,
"w": 46.5,
"w": 72,
"x": 0,
"y": 0,
"zIndex": 0,
Expand Down Expand Up @@ -1318,10 +1321,11 @@ exports[`ScrollWrapper renders a content string 1`] = `
"textColor": 4294506490,
"type": "TextTexture",
"verticalAlign": "middle",
"w": 24,
"wordWrapWidth": 48,
},
"visible": true,
"w": 0,
"w": 24,
"x": 0,
"y": 2,
"zIndex": 0,
Expand All @@ -1332,7 +1336,7 @@ exports[`ScrollWrapper renders a content string 1`] = `
"enabled": true,
"flex": false,
"flexItem": true,
"h": 513,
"h": 342,
"hasFinalFocus": false,
"hasFocus": false,
"isComponent": true,
Expand All @@ -1355,7 +1359,7 @@ exports[`ScrollWrapper renders a content string 1`] = `
],
"type": "TextBox",
"visible": true,
"w": 46.5,
"w": 36,
"x": 0,
"y": 0,
"zIndex": 0,
Expand All @@ -1366,7 +1370,7 @@ exports[`ScrollWrapper renders a content string 1`] = `
"enabled": true,
"flex": true,
"flexItem": true,
"h": 513,
"h": 342,
"isComponent": undefined,
"mount": 0,
"mountX": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ export default class TextBox extends Base {
];
}

_setDimensions(w, h) {
_setDimensions({ w, h }) {
// This is where dimensions are looping and causing the component to stretch infinitely.
!this._isInlineContent && console.trace(w, h);

let width = w;
let height = h;
if (!this._isInlineContent) {
Expand All @@ -82,7 +85,8 @@ export default class TextBox extends Base {
const sizeChanged = this.w !== width || this.h !== height;

if (width && height && sizeChanged) {
this.h = height;
this.h =
height * (this._isInlineContent ? 1 : this.stage.getRenderPrecision());
if (!this.fixed) {
this.w = width;
}
Expand Down Expand Up @@ -197,14 +201,30 @@ export default class TextBox extends Base {
const fontStyle = this._textStyleSet;

if (this._Text) {
this._Text.patch({
let patchObj = {
w: w => w,
y: this.style.offsetY,
x: this.style.offsetX,
text: {
...lightningTextDefaults, // order matters this should always be first
...fontStyle
}
x: this.style.offsetX
};

const textString = JSON.stringify({
...lightningTextDefaults, // order matters this should always be first
...fontStyle
});

if (textString !== this._textString) {
patchObj = {
...patchObj,

text: {
...lightningTextDefaults, // order matters this should always be first
...fontStyle
}
};
this._textString = textString;
}

this._Text.patch(patchObj);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ exports[`TitleRow renders 1`] = `
"visible": true,
"w": 2220,
"x": 0,
"y": 68,
"y": 52,
"zIndex": 0,
},
"Title": {
Expand Down Expand Up @@ -344,7 +344,7 @@ exports[`TitleRow renders 1`] = `
"enabled": true,
"flex": false,
"flexItem": false,
"h": 48,
"h": 32,
"hasFinalFocus": false,
"hasFocus": false,
"isComponent": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports[`Tooltip renders 1`] = `
"enabled": true,
"flex": false,
"flexItem": false,
"h": 0,
"h": 33,
"isComponent": undefined,
"mount": 0,
"mountX": 0,
Expand All @@ -48,16 +48,18 @@ exports[`Tooltip renders 1`] = `
"fontFace": "Arial",
"fontSize": 20,
"fontStyle": "300",
"h": 33,
"lineHeight": 32,
"precision": 0.6666666666666666,
"text": "Tooltip",
"textBaseline": "bottom",
"textColor": 4279769113,
"type": "TextTexture",
"verticalAlign": "middle",
"w": 605.48291015625,
},
"visible": true,
"w": 0,
"w": 605.48291015625,
"x": 0,
"y": 2,
"zIndex": 0,
Expand Down Expand Up @@ -91,8 +93,8 @@ exports[`Tooltip renders 1`] = `
],
"type": "TextBox",
"visible": true,
"w": 10.5,
"x": 25.25,
"w": 908.224365234375,
"x": 474.1121826171875,
"y": 26.5,
"zIndex": 0,
},
Expand Down Expand Up @@ -124,10 +126,10 @@ exports[`Tooltip renders 1`] = `
"texture": {
"h": 73,
"type": "Bubble",
"w": 50.5,
"w": 948.224365234375,
},
"visible": true,
"w": 50.5,
"w": 948.224365234375,
"x": 0,
"y": 0,
"zIndex": 0,
Expand Down
Loading