MCPcopy
hub / github.com/1j01/jspaint / constructor

Method constructor

src/OnCanvasTextBox.js:18–309  ·  view source on GitHub ↗

* @param {number} x * @param {number} y * @param {number} width * @param {number} height * @param {string=} starting_text

(x, y, width, height, starting_text = "")

Source from the content-addressed store, hash-verified

16 * @param {string=} starting_text
17 */
18 constructor(x, y, width, height, starting_text = "") {
19 super(x, y, width, height, true);
20
21 this.$el.addClass("textbox");
22 var edit_textarea = E("textarea");
23 this.$editor = $(edit_textarea).addClass("textbox-editor");
24
25 var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
26 svg.setAttribute("version", "1.1");
27 var foreignObject = document.createElementNS("http://www.w3.org/2000/svg", "foreignObject");
28 foreignObject.setAttribute("x", "0");
29 foreignObject.setAttribute("y", "0");
30 svg.append(foreignObject);
31
32 // inline styles so that they'll be serialized for the SVG
33 this.$editor.css({
34 position: "absolute",
35 left: "0",
36 top: "0",
37 right: "0",
38 bottom: "0",
39 padding: "0",
40 margin: "0",
41 border: "0",
42 resize: "none",
43 overflow: "hidden",
44 minWidth: "3em",
45 });
46 var render_textarea = /** @type HTMLTextAreaElement */ (edit_textarea.cloneNode(false));
47 foreignObject.append(render_textarea);
48
49 edit_textarea.value = starting_text;
50
51 this.canvas = make_canvas(width, height);
52 this.canvas.style.pointerEvents = "none";
53 this.$el.append(this.canvas);
54
55 const update_size = () => {
56 this.position();
57 this.$el.triggerHandler("update"); // update handles
58 this.$editor.add(render_textarea).css({
59 width: this.width,
60 height: this.height,
61 });
62 };
63
64 const auto_size = () => {
65 // Auto-expand, and apply minimum size.
66 if (text_tool_font.vertical) {
67 const old_width = this.width;
68 edit_textarea.style.width = "";
69 edit_textarea.style.minWidth = "0px";
70 edit_textarea.style.right = ""; // needed for when magnified
71 edit_textarea.setAttribute("rows", "1");
72 this.width = Math.max(edit_textarea.scrollWidth, this.width);
73 edit_textarea.removeAttribute("rows");
74 this.height = edit_textarea.scrollHeight;
75 edit_textarea.style.right = "0"; // doesn't seem to be needed?

Callers

nothing calls this directly

Calls 14

positionMethod · 0.95
EFunction · 0.90
make_canvasFunction · 0.90
make_css_cursorFunction · 0.90
update_helper_layerFunction · 0.90
$FontBoxFunction · 0.90
onMethod · 0.80
offMethod · 0.80
updateFunction · 0.70
focusMethod · 0.65
toggleMethod · 0.65
hideMethod · 0.65

Tested by

no test coverage detected