@@ -195,6 +195,21 @@ STATIC mp_obj_t displayio_group_obj_insert(mp_obj_t self_in, mp_obj_t index_obj,
195
195
}
196
196
MP_DEFINE_CONST_FUN_OBJ_3 (displayio_group_insert_obj , displayio_group_obj_insert );
197
197
198
+
199
+ //| .. method:: index(layer)
200
+ //|
201
+ //| Returns the index of the first copy of layer. Raises ValueError if not found.
202
+ //|
203
+ STATIC mp_obj_t displayio_group_obj_index (mp_obj_t self_in , mp_obj_t layer ) {
204
+ displayio_group_t * self = native_group (self_in );
205
+ mp_int_t index = common_hal_displayio_group_index (self , layer );
206
+ if (index < 0 ) {
207
+ mp_raise_ValueError (translate ("object not in sequence" ));
208
+ }
209
+ return MP_OBJ_NEW_SMALL_INT (index );
210
+ }
211
+ MP_DEFINE_CONST_FUN_OBJ_2 (displayio_group_index_obj , displayio_group_obj_index );
212
+
198
213
//| .. method:: pop(i=-1)
199
214
//|
200
215
//| Remove the ith item and return it.
@@ -217,6 +232,20 @@ STATIC mp_obj_t displayio_group_obj_pop(size_t n_args, const mp_obj_t *pos_args,
217
232
}
218
233
MP_DEFINE_CONST_FUN_OBJ_KW (displayio_group_pop_obj , 1 , displayio_group_obj_pop );
219
234
235
+
236
+ //| .. method:: remove(layer)
237
+ //|
238
+ //| Remove the first copy of layer. Raises ValueError if it is not present.
239
+ //|
240
+ STATIC mp_obj_t displayio_group_obj_remove (mp_obj_t self_in , mp_obj_t layer ) {
241
+ mp_obj_t index = displayio_group_obj_index (self_in , layer );
242
+ displayio_group_t * self = native_group (self_in );
243
+
244
+ common_hal_displayio_group_pop (self , MP_OBJ_SMALL_INT_VALUE (index ));
245
+ return mp_const_none ;
246
+ }
247
+ MP_DEFINE_CONST_FUN_OBJ_2 (displayio_group_remove_obj , displayio_group_obj_remove );
248
+
220
249
//| .. method:: __len__()
221
250
//|
222
251
//| Returns the number of layers in a Group
@@ -281,7 +310,9 @@ STATIC const mp_rom_map_elem_t displayio_group_locals_dict_table[] = {
281
310
{ MP_ROM_QSTR (MP_QSTR_y ), MP_ROM_PTR (& displayio_group_y_obj ) },
282
311
{ MP_ROM_QSTR (MP_QSTR_append ), MP_ROM_PTR (& displayio_group_append_obj ) },
283
312
{ MP_ROM_QSTR (MP_QSTR_insert ), MP_ROM_PTR (& displayio_group_insert_obj ) },
313
+ { MP_ROM_QSTR (MP_QSTR_index ), MP_ROM_PTR (& displayio_group_index_obj ) },
284
314
{ MP_ROM_QSTR (MP_QSTR_pop ), MP_ROM_PTR (& displayio_group_pop_obj ) },
315
+ { MP_ROM_QSTR (MP_QSTR_remove ), MP_ROM_PTR (& displayio_group_remove_obj ) },
285
316
};
286
317
STATIC MP_DEFINE_CONST_DICT (displayio_group_locals_dict , displayio_group_locals_dict_table );
287
318
0 commit comments