3434#include "shared-bindings/vectorio/VectorShape.h"
3535#endif
3636
37+ static void check_readonly (displayio_group_t * self ) {
38+ if (self -> readonly ) {
39+ mp_raise_RuntimeError (MP_ERROR_TEXT ("Read-only" ));
40+ }
41+ }
3742
3843void common_hal_displayio_group_construct (displayio_group_t * self , uint32_t scale , mp_int_t x , mp_int_t y ) {
3944 mp_obj_list_t * members = mp_obj_new_list (0 , NULL );
@@ -48,6 +53,7 @@ void common_hal_displayio_group_set_hidden(displayio_group_t *self, bool hidden)
4853 if (self -> hidden == hidden ) {
4954 return ;
5055 }
56+ check_readonly (self );
5157 self -> hidden = hidden ;
5258 if (self -> hidden_by_parent ) {
5359 return ;
@@ -81,6 +87,7 @@ void displayio_group_set_hidden_by_parent(displayio_group_t *self, bool hidden)
8187 if (self -> hidden_by_parent == hidden ) {
8288 return ;
8389 }
90+ check_readonly (self );
8491 self -> hidden_by_parent = hidden ;
8592 // If we're already hidden, then we're done.
8693 if (self -> hidden ) {
@@ -209,6 +216,7 @@ void common_hal_displayio_group_set_scale(displayio_group_t *self, uint32_t scal
209216 if (self -> scale == scale ) {
210217 return ;
211218 }
219+ check_readonly (self );
212220 uint8_t parent_scale = self -> absolute_transform .scale / self -> scale ;
213221 self -> absolute_transform .dx = self -> absolute_transform .dx / self -> scale * scale ;
214222 self -> absolute_transform .dy = self -> absolute_transform .dy / self -> scale * scale ;
@@ -225,6 +233,7 @@ void common_hal_displayio_group_set_x(displayio_group_t *self, mp_int_t x) {
225233 if (self -> x == x ) {
226234 return ;
227235 }
236+ check_readonly (self );
228237 if (self -> absolute_transform .transpose_xy ) {
229238 int16_t dy = self -> absolute_transform .dy / self -> scale ;
230239 self -> absolute_transform .y += dy * (x - self -> x );
@@ -245,6 +254,7 @@ void common_hal_displayio_group_set_y(displayio_group_t *self, mp_int_t y) {
245254 if (self -> y == y ) {
246255 return ;
247256 }
257+ check_readonly (self );
248258 if (self -> absolute_transform .transpose_xy ) {
249259 int8_t dx = self -> absolute_transform .dx / self -> scale ;
250260 self -> absolute_transform .x += dx * (y - self -> y );
@@ -257,6 +267,7 @@ void common_hal_displayio_group_set_y(displayio_group_t *self, mp_int_t y) {
257267}
258268
259269static void _add_layer (displayio_group_t * self , mp_obj_t layer ) {
270+ check_readonly (self );
260271 #if CIRCUITPY_VECTORIO
261272 const vectorio_draw_protocol_t * draw_protocol = mp_proto_get (MP_QSTR_protocol_draw , layer );
262273 if (draw_protocol != NULL ) {
@@ -294,6 +305,7 @@ static void _add_layer(displayio_group_t *self, mp_obj_t layer) {
294305}
295306
296307static void _remove_layer (displayio_group_t * self , size_t index ) {
308+ check_readonly (self );
297309 mp_obj_t layer ;
298310 displayio_area_t layer_area ;
299311 bool rendered_last_frame = false;
@@ -371,6 +383,7 @@ void displayio_group_construct(displayio_group_t *self, mp_obj_list_t *members,
371383 self -> item_removed = false;
372384 self -> scale = scale ;
373385 self -> in_group = false;
386+ self -> readonly = false;
374387}
375388
376389bool displayio_group_fill_area (displayio_group_t * self , const _displayio_colorspace_t * colorspace , const displayio_area_t * area , uint32_t * mask , uint32_t * buffer ) {
0 commit comments