Skip to content

add a new color picker block#11292

Merged
riknoll merged 8 commits into
masterfrom
dev/riknoll/arcade-color-picker
May 7, 2026
Merged

add a new color picker block#11292
riknoll merged 8 commits into
masterfrom
dev/riknoll/arcade-color-picker

Conversation

@riknoll
Copy link
Copy Markdown
Member

@riknoll riknoll commented May 4, 2026

adds a new color picker block! the motivation here is that we've always had a lot of targets/extensions that define multiple blocks for getting colors in various color spaces. for example, the neopixel extension in micro:bit, the circuit playground editor, pxt-ev3 (for the home button color), some of the boards in pxt-maker, the color fading extension in arcade, etc.

as a result, we have a lot of duplicated color space conversion code in our many repos. given how universal this is to all of our targets, this PR aims to create one color picker block to rule them all!

the new block natively supports all of the usual color formats:

  • RGB
  • HSV
  • HSL
  • CMYK
  • HEX strings

internally, the color is stored as HSV in a mutation on the block. the reason for this is that the HSV and HSL color spaces have a lot of points that map to the same color in the RGB derived color spaces, so if you compile down to RGB then you get a lot of jumping around for the various HSV and HSL channel values as the hue changes.

on hardware the colors are all actually stored as 24 bit RGB numbers which i believe is universally how we do it in all of our targets. there are new functions on the colorHelpers namespace for converting the various formats to 24 bit RGB.

the UI for the fields is a barebones HSV color picker:

color-picker2

like pauseuntil, this block is optional. unlike pauseuntil, we have a lot of targets where this block probably won't need to be in the default categories that come with the editor. for this reason, i had to a add a new scheme that allows extensions to contribute builtin blocks to the toolbox. in order to have this block appear in the toolbox, you simply need to define a function that has the builtinBlockId="makecode_color_picker" comment annotation like so:

    //% block
    //% builtinBlockId="makecode_color_picker"
    //% color=#0fbc11
    export function __colorPicker(value: number): number {
        return 0
    }

the color parameter is also necessary to make the block match the color of whatever category contains it. adding this will also add monaco toolbox entries for all the various colorHelper functions.

right now the builtinBlockId annotation only supports the color picker, but i plan to add support for pause until and other blocks in the future. the first place this block is going to be used is in the color fading extension in arcade (i have some devious plans to completely overhaul the APIs in that extension)

@riknoll riknoll requested a review from a team May 4, 2026 23:24
@THEb0nny
Copy link
Copy Markdown
Contributor

THEb0nny commented May 5, 2026

This is cool! I needed this earlier

@THEb0nny
Copy link
Copy Markdown
Contributor

THEb0nny commented May 5, 2026

I think the circle is enough to tell you which color I chose. I think the colored square on the left is unnecessary...

@THEb0nny THEb0nny mentioned this pull request May 5, 2026
Comment thread libs/pxt-common/pxt-helpers.ts
Comment thread pxtblocks/toolbox.ts
colorPickerBlock.readColorFromInputs();
}

let coorHSV = [0, 0, 0];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is coor short for coordinates or should this be color?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

should be color


const focus = () => {
// In firefox, stealing focus from the range input interrupts
// the dragging of the slider
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this mean Firefox handles focus changing by itself? Will there be problems with keyboard nav/screen readers in Firefox if we don't do this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this isn't new code; i copied it from the slider field which has already had a lot of accessibility work done on it. originally i just wanted to extend the slider field so that more of this code could be shared but it ended up being too cumbersome

};

// Configure event handler.
for (let i = 0; i < 3; i++) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible to make this more adjustable? If there's a scenario where we want to add another slider to the color picker widget, we would have to change this and the slider list below.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i don't think that scenario exists; the HSV color space only has three values

@riknoll
Copy link
Copy Markdown
Member Author

riknoll commented May 7, 2026

@THEb0nny i'm just copying what most color pickers do for the preview! plus i think having a nice big square makes it way easier to see changes take effect

@riknoll riknoll merged commit 11c03ac into master May 7, 2026
20 checks passed
@riknoll riknoll deleted the dev/riknoll/arcade-color-picker branch May 7, 2026 22:33
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