From f93f246dec7158c27537ca5d69506a6e4135d6e0 Mon Sep 17 00:00:00 2001 From: Astha Mishra Date: Wed, 25 Feb 2026 12:39:42 +0530 Subject: [PATCH] Docs: Clarify whitespace behavior in textWidth() (Fixes #7745) --- src/typography/attributes.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/typography/attributes.js b/src/typography/attributes.js index d6a5eb8d5e..08f79085e9 100644 --- a/src/typography/attributes.js +++ b/src/typography/attributes.js @@ -253,6 +253,19 @@ p5.prototype.textStyle = function(theStyle) { /** * Calculates the maximum width of a string of text drawn when * text() is called. + * * + *

Note:

+ *

+ * In p5.js 2.0, textWidth() may return 0 when + * measuring a string that contains only whitespace characters, + * such as a single space (' '). In earlier versions, + * whitespace contributed to the measured width. + *

+ *

+ * This behavior differs from fontWidth(), which measures + * individual glyph widths, including whitespace. + *

+ * * * @method textWidth * @param {String} str string of text to measure.