Skip to content

displayio: add, check "readonly" flag for groups #8923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions shared-module/displayio/Group.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include "shared-bindings/vectorio/VectorShape.h"
#endif

static void check_readonly(displayio_group_t *self) {
if (self->readonly) {
mp_raise_RuntimeError(MP_ERROR_TEXT("Read-only"));
}
}

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);
Expand All @@ -48,6 +53,7 @@ void common_hal_displayio_group_set_hidden(displayio_group_t *self, bool hidden)
if (self->hidden == hidden) {
return;
}
check_readonly(self);
self->hidden = hidden;
if (self->hidden_by_parent) {
return;
Expand Down Expand Up @@ -81,6 +87,7 @@ void displayio_group_set_hidden_by_parent(displayio_group_t *self, bool hidden)
if (self->hidden_by_parent == hidden) {
return;
}
check_readonly(self);
self->hidden_by_parent = hidden;
// If we're already hidden, then we're done.
if (self->hidden) {
Expand Down Expand Up @@ -209,6 +216,7 @@ void common_hal_displayio_group_set_scale(displayio_group_t *self, uint32_t scal
if (self->scale == scale) {
return;
}
check_readonly(self);
uint8_t parent_scale = self->absolute_transform.scale / self->scale;
self->absolute_transform.dx = self->absolute_transform.dx / self->scale * scale;
self->absolute_transform.dy = self->absolute_transform.dy / self->scale * scale;
Expand All @@ -225,6 +233,7 @@ void common_hal_displayio_group_set_x(displayio_group_t *self, mp_int_t x) {
if (self->x == x) {
return;
}
check_readonly(self);
if (self->absolute_transform.transpose_xy) {
int16_t dy = self->absolute_transform.dy / self->scale;
self->absolute_transform.y += dy * (x - self->x);
Expand All @@ -245,6 +254,7 @@ void common_hal_displayio_group_set_y(displayio_group_t *self, mp_int_t y) {
if (self->y == y) {
return;
}
check_readonly(self);
if (self->absolute_transform.transpose_xy) {
int8_t dx = self->absolute_transform.dx / self->scale;
self->absolute_transform.x += dx * (y - self->y);
Expand All @@ -257,6 +267,7 @@ void common_hal_displayio_group_set_y(displayio_group_t *self, mp_int_t y) {
}

static void _add_layer(displayio_group_t *self, mp_obj_t layer) {
check_readonly(self);
#if CIRCUITPY_VECTORIO
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, layer);
if (draw_protocol != NULL) {
Expand Down Expand Up @@ -294,6 +305,7 @@ static void _add_layer(displayio_group_t *self, mp_obj_t layer) {
}

static void _remove_layer(displayio_group_t *self, size_t index) {
check_readonly(self);
mp_obj_t layer;
displayio_area_t layer_area;
bool rendered_last_frame = false;
Expand Down Expand Up @@ -371,6 +383,7 @@ void displayio_group_construct(displayio_group_t *self, mp_obj_list_t *members,
self->item_removed = false;
self->scale = scale;
self->in_group = false;
self->readonly = false;
}

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) {
Expand Down
3 changes: 2 additions & 1 deletion shared-module/displayio/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ typedef struct {
bool in_group : 1;
bool hidden : 1;
bool hidden_by_parent : 1;
uint8_t padding : 4;
bool readonly : 1;
uint8_t padding : 3;
} displayio_group_t;

void displayio_group_construct(displayio_group_t *self, mp_obj_list_t *members, uint32_t scale, mp_int_t x, mp_int_t y);
Expand Down
3 changes: 2 additions & 1 deletion supervisor/shared/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,6 @@ displayio_group_t circuitpython_splash = {
.item_removed = false,
.in_group = false,
.hidden = false,
.hidden_by_parent = false
.hidden_by_parent = false,
.readonly = true,
};