blockly-samples icon indicating copy to clipboard operation
blockly-samples copied to clipboard

multiple colour fields don't work in zelos

Open maribethb opened this issue 1 year ago • 0 comments

Category

  • Plugins

Component

field-colour

Describe the bug

A block that has multiple colour fields on it is not rendered correctly in zelos

To Reproduce

  1. Change the definition of the basic colour block to include two colour fields, e.g. add try this json
         {
          'type': 'colour_picker',
          'message0': '%1 %2',
          'args0': [
            {
              'type': 'field_colour',
              'name': 'COLOUR',
              'colour': '#ff0000',
            },
            {
              'type': 'field_colour',
              'name': 'COLOUR2',
              'colour': '#00ff00'
            }
          ],
          'output': 'Colour',
          'helpUrl': '%{BKY_COLOUR_PICKER_HELPURL}',
          'style': 'colour_blocks',
          'tooltip': '%{BKY_COLOUR_PICKER_TOOLTIP}',
          'extensions': ['parent_tooltip_when_inline'],
        },
    
  2. open the advanced workspace
  3. change renderer to zelos
  4. observe how the full-block experience is shown and only the second colour field is shown

Expected behavior

If there are multiple colour fields present on the block, don't use the full-block experience

Screenshots

Additional context

I don't have a solid understanding of how the full-block rendering works. The behavior is controlled by the https://github.com/google/blockly/blob/develop/core/renderers/zelos/constants.ts#L100-L101 FIELD_COLOUR_FULL_BLOCK property in the constantprovider, and used in the field_colour itself. If you set the constant to false in the zelos renderer, you'll see that both fields do appear in the block (though sized probably incorrectly). What I don't really understand is why blocks that include the colour field and a label field seem to work. There must be some interaction in the renderer that controls that type of behavior, but I don't know what it is.

However, that part might be irrelevant and all that needs to happen is that if the constant is true, we also check if this is the only field on the block. That's what we do for the field_text block.

This behavior has existed since we added the full-block feature to zelos so this behavior is not new to the plugin.

Workarounds

If you use the zelos renderer and are experiencing this bug, you can either:

  • Change your block definitions to use a block with two separate inputs, that you can then drag two different color blocks into (and use shadow blocks in your toolbox). This is better for your users anyway, as instead of being forced to use the color field, they can use the "random color" or "create color from rgb" blocks as well as the default color selector experience. Since this is probably a better option, I think this bug is low priority for the core team to fix, but if anyone wanted to open a PR to fix it, we would accept such a PR.
  • Create a custom renderer that overrides the FIELD_COLOUR_FULL_BLOCK constant and sets it to false. This will change all of your blocks that use colour fields.

maribethb avatar Jul 18 '23 21:07 maribethb