From c8eb11b624287f5cf3516b1dabe431a4d334499b Mon Sep 17 00:00:00 2001 From: Mamatha <mamathabandi1718@gmail.com> Date: Sat, 26 Apr 2025 21:24:36 +0530 Subject: [PATCH] Match the Text Wrapping Behavior to p5.js Documentation --- src/typography/loading_displaying.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/typography/loading_displaying.js b/src/typography/loading_displaying.js index f625db3d99..ac1dbbbca4 100644 --- a/src/typography/loading_displaying.js +++ b/src/typography/loading_displaying.js @@ -180,8 +180,29 @@ p5.prototype.loadFont = function(path, onSuccess, onError) { }; /** - * Draws text to the canvas. - * + * Specifies how text should wrap when displayed inside a text box using the text() function. + * + * When you use text() with width and height parameters, the text will wrap automatically. + * By default, p5.js wraps text based on whole words — it moves entire words to the next line + * when they don’t fit in the given width. + * + * If your text contains very long words or no spaces (like long URLs or technical terms), + * and you want it to wrap at the character level instead, use textWrap(CHAR). + * + * You can switch between word-based or character-based wrapping by passing either WORD or CHAR. + * + * @method textWrap + * @param {Constant} mode either WORD or CHAR + * + * @example + * textWrap(CHAR); + * text("TheQuickBrownFoxJumpsOverTheLazyDogWithoutAnySpaces", 10, 30, 150, 100); + * + * @example + * textWrap(WORD); + * text("This is a sentence that wraps based on word boundaries.", 10, 30, 150, 100); + */ + /** * The first parameter, `str`, is the text to be drawn. The second and third * parameters, `x` and `y`, set the coordinates of the text's bottom-left * corner. See <a href="#/p5/textAlign">textAlign()</a> for other ways to