Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
06019f3
Add fontWidth() and clarify textWidth vs fontWidth docs in attributes.js
NalinDalal Sep 14, 2025
8f24e3e
Merge branch 'processing:dev-2.0' into dev-2.0
NalinDalal Sep 18, 2025
0aaf553
updated as per maintainers comment, only documentation is updated
NalinDalal Sep 18, 2025
486e2db
Add fontWidth() and clarify textWidth vs fontWidth docs in attributes…
NalinDalal Sep 18, 2025
944779c
Merge branch 'processing:dev-2.0' into dev-2.0
NalinDalal Sep 19, 2025
6633de2
aded docs for difference between textWidth and fontWidth with respect…
NalinDalal Sep 19, 2025
eb58aba
unnecesaary file introduced, removed it, cleanedup the thing i was su…
NalinDalal Sep 19, 2025
78ce6ac
Merge branch 'processing:dev-2.0' into dev-2.0
NalinDalal Sep 22, 2025
2759e37
docs updated as asked
NalinDalal Sep 22, 2025
3da06c0
removed things from previous pr
NalinDalal Sep 23, 2025
f911702
i think done, if not will ask maintainer
NalinDalal Sep 23, 2025
a0fae01
Merge branch 'dev-2.0' into dev-2.0
NalinDalal Sep 24, 2025
b218819
check, merge conflicts
NalinDalal Sep 24, 2025
cebc00c
Merge branch 'dev-2.0' into dev-2.0
NalinDalal Sep 25, 2025
e2bd6b1
Merge branch 'dev-2.0' into dev-2.0
NalinDalal Sep 29, 2025
8549b93
updated the docs as per suggesstion from perminder
NalinDalal Oct 3, 2025
cf75292
Merge branch 'dev-2.0' of https://github.com/NalinDalal/p5.js into de…
NalinDalal Oct 3, 2025
51534d6
Merge branch 'processing:dev-2.0' into dev-2.0
NalinDalal Oct 9, 2025
74601d0
fixes as per review
NalinDalal Oct 13, 2025
7cc2d8b
Merge branch 'dev-2.0' into dev-2.0
NalinDalal Oct 14, 2025
1ef5b37
Merge branch 'dev-2.0' into dev-2.0
NalinDalal Oct 15, 2025
84ee41e
updated the bad code and good code examples, so actually now can diff…
NalinDalal Oct 15, 2025
493ceed
Merge branch 'processing:dev-2.0' into dev-2.0
NalinDalal Oct 16, 2025
30d45e8
fix:inverted comma typos
NalinDalal Oct 16, 2025
95a02d7
invert typos
NalinDalal Oct 16, 2025
e8ae5d1
invert typos
NalinDalal Oct 16, 2025
218313c
invert typos
NalinDalal Oct 16, 2025
e10f7d0
invert typos
NalinDalal Oct 16, 2025
6a2e30b
invert typos
NalinDalal Oct 16, 2025
3dea4a1
invert typos
NalinDalal Oct 16, 2025
0f90b46
invert typos
NalinDalal Oct 16, 2025
2b0ead8
invert typos
NalinDalal Oct 16, 2025
dd4afcb
invert typos
NalinDalal Oct 16, 2025
86a3f24
invert typos
NalinDalal Oct 16, 2025
d1b961c
invert typos
NalinDalal Oct 16, 2025
0c0e5c8
invert typos
NalinDalal Oct 16, 2025
cb89f1e
invert typos
NalinDalal Oct 16, 2025
907cb87
invert typos
NalinDalal Oct 16, 2025
d3e7e7a
invert typos
NalinDalal Oct 16, 2025
8e60de2
invert typos
NalinDalal Oct 16, 2025
3b9f224
invert typos
NalinDalal Oct 16, 2025
f0b012f
invert typos
NalinDalal Oct 16, 2025
bcd8324
invert typos to do fix
NalinDalal Oct 16, 2025
b01a556
invert typos to do fix
NalinDalal Oct 16, 2025
ed84b40
invert typos to do fix
NalinDalal Oct 16, 2025
2ba8f22
invert typos to do fix
NalinDalal Oct 16, 2025
b082995
invert typos to do fix
NalinDalal Oct 16, 2025
fd71a5d
invert typos to do fix
NalinDalal Oct 16, 2025
a9fac53
invert typos to do fix
NalinDalal Oct 16, 2025
26dd043
invert typos to do fix
NalinDalal Oct 16, 2025
c15d11a
invert typos to do fix
NalinDalal Oct 16, 2025
89f8bad
invert typos to do fix
NalinDalal Oct 16, 2025
a8cd5db
invert typos to do fix
NalinDalal Oct 16, 2025
73841a3
invert typos to do fix
NalinDalal Oct 16, 2025
aef34ea
invert typos to do fix
NalinDalal Oct 16, 2025
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
6 changes: 5 additions & 1 deletion contributor_docs/contributing_to_the_p5js_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,11 @@ Finally, for every example you add, you are required to use the p5.js function `
* </div>
```

For more on `describe()` visit the [web accessibility contributor documentation](./web_accessibility/#describe).

For more on writing effective `describe()` calls:
- See the [Web Accessibility Contributor Doc](./web_accessibility.md#user-generated-accessible-canvas-descriptions) for technical details and examples.
- See the [Writing Accessible Canvas Descriptions tutorial](https://p5js.org/tutorials/writing-accessible-canvas-descriptions/) for best practices and rationale.
- See the [Documentation Style Guide section on describe()](./documentation_style_guide.md#canvas-accessibility-descriptions-describe) for Do/Don’t examples and summary guidance.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link won't work now because you removed this section on your latest commit?


With all the above you should have most of the tools needed to write and edit p5.js reference comments. However, there are a few more specialized usage of JSDoc style reference comments that you may come across in p5.js. These are situationally useful and not something that you need often.

Expand Down
26 changes: 26 additions & 0 deletions contributor_docs/documentation_style_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,32 @@ class Mover {

## Assets

# Canvas Accessibility Descriptions: `describe()`

To make p5.js sketches accessible, every example that draws to the canvas should include a call to [`describe()`](https://p5js.org/reference/#/p5/describe). This provides a concise, visual description for screen readers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: In the style of the rest of the doc, this can be 1 bullet point, followed by the bullet points of each of the best practices you have below

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the link is not correct.

Suggested change
To make p5.js sketches accessible, every example that draws to the canvas should include a call to [`describe()`](https://p5js.org/reference/#/p5/describe). This provides a concise, visual description for screen readers.
To make p5.js sketches accessible, every example that draws to the canvas should include a call to [`describe()`](https://p5js.org/reference/p5/describe). This provides a concise, visual description for screen readers.


**Best Practices for `describe()`:**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not needed - the whole style guide tries to be as compact as possible


- **Concise:** 1–3 sentences. Briefly describe what is visually present on the canvas.
- **Visual-Only:** Focus on what a sighted user would see. Do not describe code, instructions, or interactions unless they are visually represented.
- **Non-Redundant:** Avoid repeating information already available in the title or code comments.
- **Clarity:** Use simple, direct language. End with punctuation for screen reader clarity.

**Do/Don’t Examples:**

| Do | Don’t |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the style of the rest of this document, each of the above "best practices" should be illustrated with a "Good" and "Bad" example. Instead of splitting these and using sa table here, integrate illustrative examples in the list above.

| --- | --- |
| `describe('A blue rectangle in the center of a white canvas.');` | `describe('This code draws a rectangle.');` |
| `describe('A red heart and yellow circle over a pink background.');` | `describe('Click to draw a heart.');` |
| `describe('A black dot moves from bottom to top on a gray square.');` | `describe('A shape.');` |

**More Guidance:**

- See the [Web Accessibility Contributor Doc](./web_accessibility.md#user-generated-accessible-canvas-descriptions) for technical details and examples.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: consider simpler and more direct language. "New to writing accessible canvas descriptions? Please check the Web Accessibility Contributor Doc and Writing Accessible Canvas Descriptions tutorial next."

- See the [Writing Accessible Canvas Descriptions tutorial](https://p5js.org/tutorials/writing-accessible-canvas-descriptions/) for more best practices and rationale.
- Reference examples must include a `describe()` call. See [Contributing to the p5.js Reference](./contributing_to_the_p5js_reference.md#add-a-canvas-description-using-describe) for details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also not be repeated (this is not a universal suggestion - but the style guide tries to be very compact)



- Always load assets from a folder called "assets".

> Why? It models good project organization. It's also required for assets to load on the p5.js website. Place assets in the following folders to include them in our online documentation:
Expand Down
2 changes: 2 additions & 0 deletions contributor_docs/web_accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ When creating screen reader-accessible outputs, naming the colors used in the ca

### describe()

**See also:** [Documentation Style Guide: Canvas Accessibility Descriptions](./documentation_style_guide.md#canvas-accessibility-descriptions-describe) for best practices, Do/Don’t examples, and summary guidance on writing effective `describe()` calls.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this documentation is a more detailed doc than the above. What about something like: "describe() is one of the ways that p5.js sketches can be made accessible to screen readers. All contributions to the reference should include accessible canvas descriptions (see: Documentation Style Guide: Canvas Accessibility Descriptions)" - more focusing on the motivation of the style guide and its audience, than on passive description of its contents

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated it


The `describe()` function creates a sketch author-defined screen reader accessible description for the canvas. The first parameter should be a string with a description of the canvas. The second parameter is optional. If specified, it determines how the description is displayed. If a user passes `LABEL` as a second parameter, an additional `<div>` element is created next to the `<canvas>` element. The new `<div>` element contains a visible version of the same screen reader-accessible description embedded in the `<canvas>` element.

`describe()` is supported by several methods in [src/accessibility/describe.js](https://github.com/processing/p5.js/blob/main/src/accessibility/describe.js):
Expand Down
63 changes: 30 additions & 33 deletions src/type/textCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,45 +753,42 @@ function textCore(p5, fn) {
* line using the renderer’s measurement functions. The final width is determined as the maximum width
* among all these lines.
*
* For example, if the text contains multiple lines due to wrapping or explicit line breaks, textWidth()
* will return the width of the longest line.
*
* **Note:** In p5.js 2.0+, leading and trailing spaces are ignored.
* `textWidth(" Hello ")` returns the same width as `textWidth("Hello")`.
* For example, if the text contains multiple lines due to wrapping or explicit line breaks, textWidth()
* will return the width of the longest line.
*
* <b>Whitespace note:</b> In p5.js 2.0+, leading and trailing spaces are ignored when measuring the bounding box.
* <code>textWidth(" Hello ")</code> returns the same width as <code>textWidth("Hello")</code>.
* <code>textWidth(" ")</code> (a single space) may return 0, while <code>fontWidth(" ")</code> returns a nonzero width.
*
* <b>Comparison:</b>
* <ul>
* <li><code>fontWidth(' x y ')</code> includes all spaces; <code>textWidth(' x y ')</code> may ignore them.</li>
* <li><code>fontWidth(' ')</code> returns a nonzero width; <code>textWidth(' ')</code> may return 0.</li>
* </ul>
*
* @method textWidth
* @for p5
* @param {String} text The text to measure
* @returns {Number} The width of the text
*
* @example
* <div>
* <code>
* function setup() {
* createCanvas(200, 200);
* background(220);
*
* // Set text size and alignment
* textSize(48);
* textAlign(LEFT, TOP);
*
* let myText = "Hello";
*
* // Calculate the width of the text
* let tw = textWidth(myText);
*
* // Draw the text on the canvas
* fill(0);
* text(myText, 50, 50);
*
* // Display the text width below
* noStroke();
* fill(0);
* textSize(20);
* text("Text width: " + tw, 10, 150);
* }
* </code>
* </div>
* @example
* <div>
* <code>
* function setup() {
* createCanvas(200, 100);
* textSize(32);
* let s1 = 'x y';
* let s2 = ' x y ';
* let w1 = textWidth(s1);
* let w2 = textWidth(s2);
* text(s1, 10, 40);
* text(s2, 10, 80);
* line(10, 45, 10 + w1, 45); // underline tight width
* line(10, 85, 10 + w2, 85); // underline tight width (ignores whitespace)
* describe('Shows that textWidth for text with and without leading/trailing spaces is identical, as whitespace is ignored.');
* }
* </code>
* </div>
*
* @example
* <div>
Expand Down
Loading