Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AccessibleRole::Image and use it in the AboutSlint widget #7593

Merged
merged 4 commits into from
Feb 18, 2025

Conversation

DataTriny
Copy link
Contributor

Introduces a new AccessibleRole to represent images and maps it to the appropriate role for each accessibility backend. The role could be set by default but (1) it would probably have to be done in a compiler pass and (2) the Image widget is already used extensively to represent icons and other visual elements that really should not be part of the accessibility tree, so it would be annoying to set accessible-role: none everywhere.

I took this opportunity to improve the AboutSlint widget. I chose "#MadeWithSlint" as the label because I think this is the most important piece of information carried out by the image, but this is your branding so feel free to suggest something else.

@DataTriny DataTriny changed the title Accessible image Add AccessibleRole::Image and use it in the AboutSlint widget Feb 10, 2025
@ogoffart
Copy link
Member

We set the default role for Text there.

fn apply_builtin(e: &ElementRc) {

But it is true that if in practice, the images won't have a label by default so it might not be so useful to apply the role if no label is set?
I'll let you be the judge of that.

The patch looks good but perhaps the documentation of the image role could be extended a bit to explain that it is not set by default (if we choose not to set it by default) and what kind of image it should apply to in combination to what other accessible properties.

Copy link
Member

@tronical tronical left a comment

Choose a reason for hiding this comment

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

My guts feeling is that it makes sense to let this be opt-in: exposing the image to assistive tech when there is a label, and otherwise not.

(I thought perhaps it would make sense to have a default for the label extracted from image metadata, but that may not be translated or contextually correct)

@DataTriny
Copy link
Contributor Author

Even images without alternative description can be useful these days. If I launch the Gallery app with the Windows Narrator running, then go to the About tab, navigate to the image and press CapsLock+Control+D, the image is described as "A logo for a company". Not super great, but I think recent VoiceOver versions have better image recognition models built-in. If we make images accessible by default, I'm afraid they will be cluttered by irrelevant nodes. We'd have to hide the "check-mark" icon on the CheckBox for instance because keeping it would be annoying.

I agree that the accessible role should be mentioned on the documentation of the Image element.

@ogoffart
Copy link
Member

I think recent VoiceOver versions have better image recognition models built-in.

How is the image data given to the model?

@tronical
Copy link
Member

Perhaps via grabbing the pixels from the framebuffer? The bounds of the image/node within the window are known.

@DataTriny
Copy link
Contributor Author

Perhaps via grabbing the pixels from the framebuffer? The bounds of the image/node within the window are known.

Yes I think that's exactly how it works. But for that the assistive technology have to know that there is a node on which it can perform image recognition, hence this new role.

I'll do the documentation tomorrow.

@DataTriny
Copy link
Contributor Author

I'm not entirely sure whether images should be part of the accessibility tree by default or not, and I wouldn't want to make a bad choice for Slint. I'm going to reach out to more knowledgeable people to discuss this matter and I'll update you here.

@DataTriny
Copy link
Contributor Author

I'm setting the accessible role on all images and I've hidden icons on widgets.

There should probably be a test somewhere to check that the role is set by default, but I'm not sure where would it live?

Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

Thanks a lot.
This looks good.

Just an idea, but you'll tell me if it is a good or a bad one: what if the role was only set if the image had a accessible-label property set?
OR maybe that's too magical and confusing and we still want the screen reader to know of all image by default even if they don't have a label.

There should probably be a test somewhere to check that the role is set by default, but I'm not sure where would it live?

Maybe in tests/cases/elements/image.slint ? Add something like img1.accessible-role == AccessibleRole.image in the test property.

@DataTriny
Copy link
Contributor Author

I've updated the first commit to keep a clean git history. I've added Rust and C++ tests in tests/cases/elements/image.slint and I have updated the documentation to mention that images get a default accessible role before showing how to change this if desired.

what if the role was only set if the image had a accessible-label property set?

This would break a currently defined rule which prevents setting any accessibility related property unless accessible-role is also set, so this would be confusing I guess. This would also make it impossible to have an image without a label. Even though this is something we want to ignore, we still may want to let the user do that?

@DataTriny
Copy link
Contributor Author

Can't get the C++ test to work apparently. Well it's not my thing, I guess one of you can spot the obvious mistake in there.

Co-authored-by: Olivier Goffart <[email protected]>
@ogoffart ogoffart merged commit 90c337f into slint-ui:master Feb 18, 2025
39 checks passed
@ogoffart
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants