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

Automatically adjust block colors to have a contrast ratio of 4.5 #9973

Merged
merged 4 commits into from
Apr 17, 2024

Conversation

riknoll
Copy link
Member

@riknoll riknoll commented Apr 16, 2024

Motivated by: microsoft/pxt-arcade#4870

This PR adds a little code to automatically adjust all block background colors to have a contrast ratio of at least 4.5 with white foreground text. The algorithm I'm using is pretty dumb: I just lower the luminosity until a color with the correct contrast ratio is generated and cache the result.

I placed this behind a feature flag for now because the general consensus is that this makes all the blocks look duller/uglier and creates a breaking change with old screenshots. The goal should be for us to eventually turn this on in all targets; we might have to adjust the base colors of some categories to make them more visually appealing though (arrays is particularly ugly).

Here is an upload target in micro:bit with the feature turned on:

https://makecode.microbit.org/app/36f327a321d404020e3804ed55f5a3567b2e929f-3d8dd326ca

@riknoll riknoll requested a review from a team April 16, 2024 19:32
@riknoll
Copy link
Member Author

riknoll commented Apr 16, 2024

also, should be noted that turning this flag on will fix microsoft/pxt-arcade#4870

@riknoll riknoll changed the title Automatically adjust blocks colors to have a contrast ratio of 4.5 Automatically adjust block colors to have a contrast ratio of 4.5 Apr 16, 2024
@srietkerk
Copy link
Contributor

Also, is there a reason that on start's color doesn't change?

@riknoll
Copy link
Member Author

riknoll commented Apr 16, 2024

ah, that would be because i missed on start! will fix

Copy link
Contributor

@srietkerk srietkerk left a comment

Choose a reason for hiding this comment

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

Just a question for my own understanding, otherwise looks good.

@@ -8,6 +8,12 @@ export function initOnStart() {
const onStartDef = pxt.blocks.getBlockDefinition(ts.pxtc.ON_START_TYPE);
Blockly.Blocks[ts.pxtc.ON_START_TYPE] = {
init: function () {
let colorOverride = pxt.appTarget.runtime?.onStartColor;
Copy link
Contributor

Choose a reason for hiding this comment

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

So we special-case the onStart block? Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

on-start is kind of a special builtin block because we give targets a lot of control over where it shows up. For example, in micro:bit it's in the basic category but everywhere else it's in loops. iirc we added this option for cue because they had an on-start that doesn't show up in any category, it was just always on the workspace and couldn't be deleted.

@riknoll riknoll merged commit e381259 into master Apr 17, 2024
6 checks passed
@riknoll riknoll deleted the dev/riknoll/accessible-block-colors branch April 17, 2024 16:30
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.

None yet

2 participants