summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2021-03-02 09:59:58 -0800
committerGitHub <noreply@github.com>2021-03-02 09:59:58 -0800
commite4f0e47d9f0bb620f56b93c649197b16105ab5b2 (patch)
tree2a3b9b292039ba592866690f8f89d6f61e288123 /shared-bindings
parentce70b95990b45b4799055b6b7e7d347ac35257a0 (diff)
parentcb2cf81136c48695b1097fb2f601bce90e1086c9 (diff)
Merge pull request #4233 from pewpew-game/displayio-group-list
displayio: make Group use a python list internally
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/displayio/Group.c25
-rw-r--r--shared-bindings/displayio/Group.h2
2 files changed, 19 insertions, 8 deletions
diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c
index 386e270ab..c1c05504d 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 942a207f2..69c73bf4d 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);