diff --git a/ports/atmel-samd/boards/ugame10/mpconfigboard.mk b/ports/atmel-samd/boards/ugame10/mpconfigboard.mk index f7214704ce..2b0eedc014 100644 --- a/ports/atmel-samd/boards/ugame10/mpconfigboard.mk +++ b/ports/atmel-samd/boards/ugame10/mpconfigboard.mk @@ -18,6 +18,7 @@ CIRCUITPY_ANALOGIO = 1 CIRCUITPY_GAMEPAD = 1 CIRCUITPY_DISPLAYIO = 1 +CIRCUITPY_PULSEIO = 0 CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITMAPTOOLS = 0 diff --git a/py/objlist.c b/py/objlist.c index 51ec920be1..7aa4ee89c9 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -270,13 +270,10 @@ STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) { return mp_const_none; // return None, as per CPython } -STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) { - mp_check_self(MP_OBJ_IS_TYPE(args[0], &mp_type_list)); - mp_obj_list_t *self = mp_instance_cast_to_native_base(args[0], &mp_type_list); +inline mp_obj_t mp_obj_list_pop(mp_obj_list_t *self, size_t index) { if (self->len == 0) { mp_raise_IndexError_varg(translate("pop from empty %q"), MP_QSTR_list); } - size_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false); mp_obj_t ret = self->items[index]; self->len -= 1; memmove(self->items + index, self->items + index + 1, (self->len - index) * sizeof(mp_obj_t)); @@ -289,6 +286,13 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) { return ret; } +STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) { + mp_check_self(MP_OBJ_IS_TYPE(args[0], &mp_type_list)); + mp_obj_list_t *self = mp_instance_cast_to_native_base(args[0], &mp_type_list); + size_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false); + return mp_obj_list_pop(self, index); +} + STATIC void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, mp_obj_t binop_less_result) { MP_STACK_CHECK(); while (head < tail) { @@ -371,6 +375,15 @@ STATIC mp_obj_t list_index(size_t n_args, const mp_obj_t *args) { return mp_seq_index_obj(self->items, self->len, n_args, args); } +inline void mp_obj_list_insert(mp_obj_list_t *self, size_t index, mp_obj_t obj) { + mp_obj_list_append(MP_OBJ_FROM_PTR(self), mp_const_none); + + for (size_t i = self->len - 1; i > index; --i) { + self->items[i] = self->items[i - 1]; + } + self->items[index] = obj; +} + STATIC mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) { mp_check_self(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); mp_obj_list_t *self = mp_instance_cast_to_native_base(self_in, &mp_type_list); @@ -385,14 +398,7 @@ STATIC mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) { if ((size_t)index > self->len) { index = self->len; } - - mp_obj_list_append(self_in, mp_const_none); - - for (mp_int_t i = self->len-1; i > index; i--) { - self->items[i] = self->items[i-1]; - } - self->items[index] = obj; - + mp_obj_list_insert(self, index, obj); return mp_const_none; } diff --git a/py/objlist.h b/py/objlist.h index f02030557b..eb005e81cf 100644 --- a/py/objlist.h +++ b/py/objlist.h @@ -36,5 +36,7 @@ typedef struct _mp_obj_list_t { } mp_obj_list_t; void mp_obj_list_init(mp_obj_list_t *o, size_t n); +mp_obj_t mp_obj_list_pop(mp_obj_list_t *self, size_t index); +void mp_obj_list_insert(mp_obj_list_t *self, size_t index, mp_obj_t obj); #endif // MICROPY_INCLUDED_PY_OBJLIST_H diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index 386e270abd..c1c05504da 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -42,7 +42,7 @@ //| """Create a Group of a given size and scale. Scale is in one dimension. For example, scale=2 //| leads to a layer's pixel being 2x2 pixels when in the group. //| -//| :param int max_size: The maximum group size. +//| :param int max_size: Ignored. Will be removed in 7.x. //| :param int scale: Scale of layer pixels in one dimension. //| :param int x: Initial x position within the parent. //| :param int y: Initial y position within the parent.""" @@ -59,11 +59,6 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_int_t max_size = args[ARG_max_size].u_int; - if (max_size < 1) { - mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_max_size); - } - mp_int_t scale = args[ARG_scale].u_int; if (scale < 1) { mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_scale); @@ -71,7 +66,7 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg displayio_group_t *self = m_new_obj(displayio_group_t); self->base.type = &displayio_group_type; - common_hal_displayio_group_construct(self, max_size, scale, args[ARG_x].u_int, args[ARG_y].u_int); + common_hal_displayio_group_construct(self, scale, args[ARG_x].u_int, args[ARG_y].u_int); return MP_OBJ_FROM_PTR(self); } @@ -328,6 +323,21 @@ STATIC mp_obj_t group_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t valu return mp_const_none; } +//| def sort(self, key: function, reverse: bool) -> None: +//| """Sort the members of the group.""" +//| ... +//| +STATIC mp_obj_t displayio_group_obj_sort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + displayio_group_t *self = native_group(pos_args[0]); + mp_obj_t *args = m_new(mp_obj_t, n_args); + for (size_t i = 1; i < n_args; ++i) { + args[i] = pos_args[i]; + } + args[0] = MP_OBJ_FROM_PTR(self->members); + return mp_obj_list_sort(n_args, pos_args, kw_args); +} +MP_DEFINE_CONST_FUN_OBJ_KW(displayio_group_sort_obj, 1, displayio_group_obj_sort); + STATIC const mp_rom_map_elem_t displayio_group_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&displayio_group_hidden_obj) }, { MP_ROM_QSTR(MP_QSTR_scale), MP_ROM_PTR(&displayio_group_scale_obj) }, @@ -338,6 +348,7 @@ STATIC const mp_rom_map_elem_t displayio_group_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_index), MP_ROM_PTR(&displayio_group_index_obj) }, { MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&displayio_group_pop_obj) }, { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&displayio_group_remove_obj) }, + { MP_ROM_QSTR(MP_QSTR_sort), MP_ROM_PTR(&displayio_group_sort_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_group_locals_dict, displayio_group_locals_dict_table); diff --git a/shared-bindings/displayio/Group.h b/shared-bindings/displayio/Group.h index 942a207f2d..69c73bf4dc 100644 --- a/shared-bindings/displayio/Group.h +++ b/shared-bindings/displayio/Group.h @@ -33,7 +33,7 @@ extern const mp_obj_type_t displayio_group_type; displayio_group_t* native_group(mp_obj_t group_obj); -void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y); +void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t scale, mp_int_t x, mp_int_t y); uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self); void common_hal_displayio_group_set_scale(displayio_group_t* self, uint32_t scale); bool common_hal_displayio_group_get_hidden(displayio_group_t* self); diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c index 15cf5b8e48..42efeb18c2 100644 --- a/shared-module/displayio/Group.c +++ b/shared-module/displayio/Group.c @@ -27,6 +27,7 @@ #include "shared-bindings/displayio/Group.h" #include "py/runtime.h" +#include "py/objlist.h" #include "shared-bindings/displayio/TileGrid.h" #if CIRCUITPY_VECTORIO @@ -34,9 +35,9 @@ #endif -void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y) { - displayio_group_child_t* children = m_new(displayio_group_child_t, max_size); - displayio_group_construct(self, children, max_size, scale, x, y); +void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t scale, mp_int_t x, mp_int_t y) { + mp_obj_list_t *members = mp_obj_new_list(0, NULL); + displayio_group_construct(self, members, scale, x, y); } bool common_hal_displayio_group_get_hidden(displayio_group_t* self) { @@ -51,12 +52,19 @@ void common_hal_displayio_group_set_hidden(displayio_group_t* self, bool hidden) if (self->hidden_by_parent) { return; } - for (size_t i = 0; i < self->size; i++) { - mp_obj_t layer = self->children[i].native; - if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + for (size_t i = 0; i < self->members->len; i++) { + mp_obj_t layer; + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_tilegrid_type); + if (layer != MP_OBJ_NULL) { displayio_tilegrid_set_hidden_by_parent(layer, hidden); - } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { + continue; + } + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_group_type); + if (layer != MP_OBJ_NULL) { displayio_group_set_hidden_by_parent(layer, hidden); + continue; } } } @@ -70,12 +78,19 @@ void displayio_group_set_hidden_by_parent(displayio_group_t *self, bool hidden) if (self->hidden) { return; } - for (size_t i = 0; i < self->size; i++) { - mp_obj_t layer = self->children[i].native; - if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + for (size_t i = 0; i < self->members->len; i++) { + mp_obj_t layer; + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_tilegrid_type); + if (layer != MP_OBJ_NULL) { displayio_tilegrid_set_hidden_by_parent(layer, hidden); - } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { + continue; + } + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_group_type); + if (layer != MP_OBJ_NULL) { displayio_group_set_hidden_by_parent(layer, hidden); + continue; } } } @@ -86,16 +101,22 @@ uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self) { bool displayio_group_get_previous_area(displayio_group_t *self, displayio_area_t* area) { bool first = true; - for (size_t i = 0; i < self->size; i++) { - mp_obj_t layer = self->children[i].native; + for (size_t i = 0; i < self->members->len; i++) { + mp_obj_t layer; displayio_area_t layer_area; - if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_tilegrid_type); + if (layer != MP_OBJ_NULL) { if (!displayio_tilegrid_get_previous_area(layer, &layer_area)) { continue; } - } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { - if (!displayio_group_get_previous_area(layer, &layer_area)) { - continue; + } else { + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_group_type); + if (layer != MP_OBJ_NULL) { + if (!displayio_group_get_previous_area(layer, &layer_area)) { + continue; + } } } if (first) { @@ -120,18 +141,27 @@ static void _update_child_transforms(displayio_group_t* self) { if (!self->in_group) { return; } - for (size_t i = 0; i < self->size; i++) { - mp_obj_t layer = self->children[i].native; + for (size_t i = 0; i < self->members->len; i++) { + mp_obj_t layer; #if CIRCUITPY_VECTORIO - if (MP_OBJ_IS_TYPE(layer, &vectorio_vector_shape_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[i], &vectorio_vector_shape_type); + if (layer != MP_OBJ_NULL) { vectorio_vector_shape_update_transform(layer, &self->absolute_transform); + continue; } - else #endif - if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_tilegrid_type); + if (layer != MP_OBJ_NULL) { displayio_tilegrid_update_transform(layer, &self->absolute_transform); - } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { + continue; + } + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_group_type); + if (layer != MP_OBJ_NULL) { displayio_group_update_transform(layer, &self->absolute_transform); + continue; } } } @@ -210,21 +240,17 @@ void common_hal_displayio_group_set_y(displayio_group_t* self, mp_int_t y) { _update_child_transforms(self); } -static mp_obj_t _add_layer(displayio_group_t* self, mp_obj_t layer) { +static void _add_layer(displayio_group_t* self, mp_obj_t layer) { mp_obj_t native_layer; #if CIRCUITPY_VECTORIO native_layer = mp_instance_cast_to_native_base(layer, &vectorio_vector_shape_type); if (native_layer != MP_OBJ_NULL) { vectorio_vector_shape_update_transform(native_layer, &self->absolute_transform); - return native_layer; + return; } #endif - native_layer = mp_instance_cast_to_native_base(layer, &displayio_group_type); - if (native_layer == MP_OBJ_NULL) { - native_layer = mp_instance_cast_to_native_base(layer, &displayio_tilegrid_type); - if (native_layer == MP_OBJ_NULL) { - mp_raise_ValueError(translate("Layer must be a Group or TileGrid subclass.")); - } + native_layer = mp_instance_cast_to_native_base(layer, &displayio_tilegrid_type); + if (native_layer != MP_OBJ_NULL) { displayio_tilegrid_t* tilegrid = native_layer; if (tilegrid->in_group) { mp_raise_ValueError(translate("Layer already in a group.")); @@ -232,7 +258,10 @@ static mp_obj_t _add_layer(displayio_group_t* self, mp_obj_t layer) { tilegrid->in_group = true; } displayio_tilegrid_update_transform(tilegrid, &self->absolute_transform); - } else { + return; + } + native_layer = mp_instance_cast_to_native_base(layer, &displayio_group_type); + if (native_layer != MP_OBJ_NULL) { displayio_group_t* group = native_layer; if (group->in_group) { mp_raise_ValueError(translate("Layer already in a group.")); @@ -240,27 +269,34 @@ static mp_obj_t _add_layer(displayio_group_t* self, mp_obj_t layer) { group->in_group = true; } displayio_group_update_transform(group, &self->absolute_transform); + return; } - return native_layer; + mp_raise_ValueError(translate("Layer must be a Group or TileGrid subclass.")); } static void _remove_layer(displayio_group_t* self, size_t index) { - mp_obj_t layer = self->children[index].native; + mp_obj_t layer; displayio_area_t layer_area; bool rendered_last_frame = false; #if CIRCUITPY_VECTORIO - if (MP_OBJ_IS_TYPE(layer, &vectorio_vector_shape_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[index], &vectorio_vector_shape_type); + if (layer != MP_OBJ_NULL) { bool has_dirty_area = vectorio_vector_shape_get_dirty_area(layer, &layer_area); rendered_last_frame = has_dirty_area; vectorio_vector_shape_update_transform(layer, NULL); } - else #endif - if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[index], &displayio_tilegrid_type); + if (layer != MP_OBJ_NULL) { displayio_tilegrid_t* tilegrid = layer; rendered_last_frame = displayio_tilegrid_get_previous_area(tilegrid, &layer_area); displayio_tilegrid_update_transform(tilegrid, NULL); - } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { + } + layer = mp_instance_cast_to_native_base( + self->members->items[index], &displayio_group_type); + if (layer != MP_OBJ_NULL) { displayio_group_t* group = layer; rendered_last_frame = displayio_group_get_previous_area(group, &layer_area); displayio_group_update_transform(group, NULL); @@ -277,62 +313,40 @@ static void _remove_layer(displayio_group_t* self, size_t index) { } void common_hal_displayio_group_insert(displayio_group_t* self, size_t index, mp_obj_t layer) { - if (self->size == self->max_size) { - mp_raise_RuntimeError(translate("Group full")); - } - mp_obj_t native_layer = _add_layer(self, layer); - // Shift everything right. - for (size_t i = self->size; i > index; i--) { - self->children[i] = self->children[i - 1]; - } - self->children[index].native = native_layer; - self->children[index].original = layer; - self->size++; + _add_layer(self, layer); + mp_obj_list_insert(self->members, index, layer); } mp_obj_t common_hal_displayio_group_pop(displayio_group_t* self, size_t index) { - self->size--; - mp_obj_t item = self->children[index].original; _remove_layer(self, index); - - // Shift everything left. - for (size_t i = index; i < self->size; i++) { - self->children[i] = self->children[i + 1]; - } - self->children[self->size].native = NULL; - self->children[self->size].original = NULL; - return item; + return mp_obj_list_pop(self->members, index); } mp_int_t common_hal_displayio_group_index(displayio_group_t* self, mp_obj_t layer) { - for (size_t i = 0; i < self->size; i++) { - if (self->children[i].original == layer) { - return i; - } - } - return -1; + mp_obj_t args[] = {self->members, layer}; + mp_obj_t *index = mp_seq_index_obj( + self->members->items, self->members->len, 2, args); + return MP_OBJ_SMALL_INT_VALUE(index); } size_t common_hal_displayio_group_get_len(displayio_group_t* self) { - return self->size; + return self->members->len; } mp_obj_t common_hal_displayio_group_get(displayio_group_t* self, size_t index) { - return self->children[index].original; + return self->members->items[index]; } void common_hal_displayio_group_set(displayio_group_t* self, size_t index, mp_obj_t layer) { - mp_obj_t native_layer = _add_layer(self, layer); + _add_layer(self, layer); _remove_layer(self, index); - self->children[index].native = native_layer; - self->children[index].original = layer; + mp_obj_list_store(self, MP_OBJ_NEW_SMALL_INT(index), layer); } -void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y) { +void displayio_group_construct(displayio_group_t* self, mp_obj_list_t* members, uint32_t scale, mp_int_t x, mp_int_t y) { self->x = x; self->y = y; - self->children = child_array; - self->max_size = max_size; + self->members = members; self->item_removed = false; self->scale = scale; self->in_group = false; @@ -341,47 +355,61 @@ void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* bool displayio_group_fill_area(displayio_group_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t* buffer) { // Track if any of the layers finishes filling in the given area. We can ignore any remaining // layers at that point. - bool full_coverage = false; - for (int32_t i = self->size - 1; i >= 0 ; i--) { - mp_obj_t layer = self->children[i].native; + for (int32_t i = self->members->len - 1; i >= 0 ; i--) { + mp_obj_t layer; #if CIRCUITPY_VECTORIO - if (MP_OBJ_IS_TYPE(layer, &vectorio_vector_shape_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[i], &vectorio_vector_shape_type); + if (layer != MP_OBJ_NULL) { if (vectorio_vector_shape_fill_area(layer, colorspace, area, mask, buffer)) { - full_coverage = true; - break; + return true; } + continue; } - else #endif - if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_tilegrid_type); + if (layer != MP_OBJ_NULL) { if (displayio_tilegrid_fill_area(layer, colorspace, area, mask, buffer)) { - full_coverage = true; - break; + return true; } - } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { + continue; + } + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_group_type); + if (layer != MP_OBJ_NULL) { if (displayio_group_fill_area(layer, colorspace, area, mask, buffer)) { - full_coverage = true; - break; + return true; } + continue; } } - return full_coverage; + return false; } void displayio_group_finish_refresh(displayio_group_t *self) { self->item_removed = false; - for (int32_t i = self->size - 1; i >= 0 ; i--) { - mp_obj_t layer = self->children[i].native; + for (int32_t i = self->members->len - 1; i >= 0 ; i--) { + mp_obj_t layer; #if CIRCUITPY_VECTORIO - if (MP_OBJ_IS_TYPE(layer, &vectorio_vector_shape_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[i], &vectorio_vector_shape_type); + if (layer != MP_OBJ_NULL) { vectorio_vector_shape_finish_refresh(layer); + continue; } - else #endif - if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_tilegrid_type); + if (layer != MP_OBJ_NULL) { displayio_tilegrid_finish_refresh(layer); - } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { + continue; + } + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_group_type); + if (layer != MP_OBJ_NULL) { displayio_group_finish_refresh(layer); + continue; } } } @@ -392,18 +420,27 @@ displayio_area_t* displayio_group_get_refresh_areas(displayio_group_t *self, dis tail = &self->dirty_area; } - for (int32_t i = self->size - 1; i >= 0 ; i--) { - mp_obj_t layer = self->children[i].native; + for (int32_t i = self->members->len - 1; i >= 0 ; i--) { + mp_obj_t layer; #if CIRCUITPY_VECTORIO - if (MP_OBJ_IS_TYPE(layer, &vectorio_vector_shape_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[i], &vectorio_vector_shape_type); + if (layer != MP_OBJ_NULL) { tail = vectorio_vector_shape_get_refresh_areas(layer, tail); + continue; } - else #endif - if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) { + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_tilegrid_type); + if (layer != MP_OBJ_NULL) { tail = displayio_tilegrid_get_refresh_areas(layer, tail); - } else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) { + continue; + } + layer = mp_instance_cast_to_native_base( + self->members->items[i], &displayio_group_type); + if (layer != MP_OBJ_NULL) { tail = displayio_group_get_refresh_areas(layer, tail); + continue; } } diff --git a/shared-module/displayio/Group.h b/shared-module/displayio/Group.h index 5afaac1bae..0964e0a0ba 100644 --- a/shared-module/displayio/Group.h +++ b/shared-module/displayio/Group.h @@ -31,24 +31,18 @@ #include #include "py/obj.h" +#include "py/objlist.h" #include "shared-module/displayio/area.h" #include "shared-module/displayio/Palette.h" -typedef struct { - mp_obj_t native; - mp_obj_t original; -} displayio_group_child_t; - typedef struct { mp_obj_base_t base; - displayio_group_child_t* children; + mp_obj_list_t *members; displayio_buffer_transform_t absolute_transform; displayio_area_t dirty_area; // Catch all for changed area int16_t x; int16_t y; uint16_t scale; - uint16_t size; - uint16_t max_size; bool item_removed :1; bool in_group :1; bool hidden :1; @@ -56,7 +50,7 @@ typedef struct { uint8_t padding :4; } displayio_group_t; -void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y); +void displayio_group_construct(displayio_group_t* self, mp_obj_list_t* members, uint32_t scale, mp_int_t x, mp_int_t y); void displayio_group_set_hidden_by_parent(displayio_group_t *self, bool hidden); bool displayio_group_get_previous_area(displayio_group_t *group, displayio_area_t* area); bool displayio_group_fill_area(displayio_group_t *group, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer); diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index 9c9c66cd7f..1919cf4a47 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -270,15 +270,20 @@ displayio_tilegrid_t blinka_sprite = { }; #if CIRCUITPY_TERMINALIO -#define CHILD_COUNT 2 -displayio_group_child_t splash_children[2] = { - {&blinka_sprite, &blinka_sprite}, - {&supervisor_terminal_text_grid, &supervisor_terminal_text_grid} +mp_obj_t members[] = { &blinka_sprite, &supervisor_terminal_text_grid, }; +mp_obj_list_t splash_children = { + .base = {.type = &mp_type_list }, + .alloc = 2, + .len = 2, + .items = members, }; #else -#define CHILD_COUNT 1 -displayio_group_child_t splash_children[1] = { - {&blinka_sprite, &blinka_sprite}, +mp_obj_t members[] = { &blinka_sprite }; +mp_obj_list_t splash_children = { + .base = {.type = &mp_type_list }, + .alloc = 1, + .len = 1, + .items = members, }; #endif @@ -287,9 +292,7 @@ displayio_group_t circuitpython_splash = { .x = 0, .y = 0, .scale = 2, - .size = CHILD_COUNT, - .max_size = CHILD_COUNT, - .children = splash_children, + .members = &splash_children, .item_removed = false, .in_group = false, .hidden = false,