Skip to content

Commit

Permalink
lab/text: add with/without word wrap option to # of lines block (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
AshimeeAlt committed Jun 9, 2024
1 parent 49c1bea commit 2b0318f
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions extensions/lab/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,25 @@
opcode: "getLines",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate("# of lines"),
hideFromPalette: true,
disableMonitor: true,
extensions: ["colours_looks"],
},
{
opcode: "getLinesV2",
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate({
default: "# of lines [WITH_WORD_WRAP]",
description:
"[WITH_WORD_WRAP] is a menu with choices 'with word wrap' and 'without word wrap'",
}),
hideFromPalette: compatibilityMode,
arguments: {
WITH_WORD_WRAP: {
type: Scratch.ArgumentType.STRING,
menu: "twWordWrap",
},
},
disableMonitor: true,
extensions: ["colours_looks"],
},
Expand Down Expand Up @@ -1179,6 +1197,19 @@
acceptReporters: true,
items: "getFonts",
},
twWordWrap: {
acceptReporters: true,
items: [
{
text: Scratch.translate("with word wrap"),
value: "with word wrap",
},
{
text: Scratch.translate("without word wrap"),
value: "without word wrap",
},
],
},
},
};
}
Expand Down Expand Up @@ -1382,6 +1413,18 @@
return text.split("\n").length;
}

getLinesV2(args, util) {
const drawableID = util.target.drawableID;
const skin = renderer._allDrawables[drawableID].skin;
if (!(skin instanceof TextCostumeSkin)) return 0;

const state = this._getState(util.target);
if (Scratch.Cast.toString(args.WITH_WORD_WRAP) === "with word wrap") {
return state.skin.lines.length;
}
return state.skin.text.split("\n").length;
}

setAlignment(args, util) {
// see setWidth
const state = this._getState(util.target);
Expand Down

0 comments on commit 2b0318f

Please sign in to comment.