Factor transformations into position and area for shapes' accessible outputs - addresses #4721#6122
Conversation
|
Tagging accessibility stewards @kungfuchicken, @cosmicbhejafry for feedback if you have a chance |
src/accessibility/outputs.js
Outdated
| if (args[1] < 0.4 * canvasHeight) { | ||
| p5.prototype._getPos = function (x, y) { | ||
| const untransformedPosition = new DOMPointReadOnly(x, y); | ||
| const currentTransform = this.drawingContext.getTransform(); |
There was a problem hiding this comment.
I think this might not work if this gets called when in WebGL mode. But if you detect WebGL mode, you can use new DOMMatrix(this._renderer.uMVMatrix.mat4) and the rest should work!
for shapes' accessible outputs
2dcdcc1 to
5a09fa4
Compare
|
Thank you, @davepagurek! I forgot that the 2D primitive functions could also be called in WEBGL mode. I really appreciate you sharing how to get the transform matrix from the WEBGL renderer because I had no idea! I've added a commit that accounts for WEBGL mode enough to not throw an error, but that brought me to other issues in WEBGL:
Currently in WEBGL (without this PR) 2D primitives get inaccurate descriptions, even without transformations. I think generating these position and area descriptions for WEBGL would be a very big undertaking, and maybe a different format for descriptions would better fit WEBGL. In the meantime, I think it would make sense to modify textOutput() and gridOutput() to only work in 2D and to throw a friendly error if called in WEBGL (along with modification to documentation). I'm happy to make those changes as well, if that sounds like a good plan. If so, would it be preferable for me to make those changes in a separate PR? |
|
Sure thing, this would be an improvement regardless of whether it works for WebGL mode! A follow-up PR sounds good to me. |
Addresses suggestion raised in #4721
Specifically this comment
Changes:
Currently, transformations are not taken into account for outputs generated through textOutput() or gridOutput(). This PR modifies _getPos and _getArea to be methods on the p5 prototype and to factor in the current transformations into their calculations.
You can see that in this example. Three squares are on the canvas in different positions with the square in the lower right being scaled down, but the text output describes only one shape because the arguments passed into square() are the same and because the color is the same.
Here's that same example with the build from this PR.
PR Checklist
npm run lintpasses