Gradient is not working with lv.draw_rect_dsc_t

Setting the gradient in lv_canvas in lv.draw_rect_dsc_t always results in black and which (the LVGL default) colors. See this canvas example:
image

The same in MP:
image

Strange.
It’s related specifically to bg_grad.
If I set, for example, rect_dsc.bg_color = lv.palette_main(lv.PALETTE.RED) instead of grad, then it works as expected.
I’m not sure why it behaves differently on MP, need to debug this more deeply. Maybe something related to the display driver.

It’s really interesting that lv.palette_main(lv.PALETTE.RED) works. Thank you for looking into it.

I think I know what the problem is.

A C array is converted to a Python list. Updating the list does not update back the array.
As a workaround, the whole array can be set, instead of setting individual array elements:

rect_dsc.bg_grad.stops = [
    lv.gradient_stop_t({'color': lv.palette_main(lv.PALETTE.RED)}),
    lv.gradient_stop_t({'color': lv.palette_main(lv.PALETTE.BLUE), 'frac':0xff})
]

Online example

I’ll think of ways to fix this, here is an issue to track this:

Great, thank you!