Skip to content

Commit e995375

Browse files
committed
Add displayio.Group.sort() method
1 parent e505c59 commit e995375

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

shared-bindings/displayio/Group.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,21 @@ STATIC mp_obj_t group_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t valu
328328
return mp_const_none;
329329
}
330330

331+
//| def sort(self, key: function, reverse: bool) -> None:
332+
//| """Sort the members of the group."""
333+
//| ...
334+
//|
335+
STATIC mp_obj_t displayio_group_obj_sort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
336+
displayio_group_t *self = native_group(pos_args[0]);
337+
mp_obj_t *args = m_new(mp_obj_t, n_args);
338+
for (size_t i = 1; i < n_args; ++i) {
339+
args[i] = pos_args[i];
340+
}
341+
args[0] = self->members;
342+
return mp_obj_list_sort(n_args, pos_args, kw_args);
343+
}
344+
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_group_sort_obj, 1, displayio_group_obj_sort);
345+
331346
STATIC const mp_rom_map_elem_t displayio_group_locals_dict_table[] = {
332347
{ MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&displayio_group_hidden_obj) },
333348
{ MP_ROM_QSTR(MP_QSTR_scale), MP_ROM_PTR(&displayio_group_scale_obj) },
@@ -338,6 +353,7 @@ STATIC const mp_rom_map_elem_t displayio_group_locals_dict_table[] = {
338353
{ MP_ROM_QSTR(MP_QSTR_index), MP_ROM_PTR(&displayio_group_index_obj) },
339354
{ MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&displayio_group_pop_obj) },
340355
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&displayio_group_remove_obj) },
356+
{ MP_ROM_QSTR(MP_QSTR_sort), MP_ROM_PTR(&displayio_group_sort_obj) },
341357
};
342358
STATIC MP_DEFINE_CONST_DICT(displayio_group_locals_dict, displayio_group_locals_dict_table);
343359

0 commit comments

Comments
 (0)