Skip to content

Commit 1e16b3e

Browse files
committed
Tweaks based on dhalbert's feedback.
1 parent 70f40a0 commit 1e16b3e

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

shared-bindings/displayio/Group.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@
4343
//|
4444
//| .. class:: Group(*, max_size=4, scale=1)
4545
//|
46-
//| Create a Group of a given size.
46+
//| Create a Group of a given size and scale. Scale is in one dimension. For example, scale=2
47+
//| leads to a layer's pixel being 2x2 pixels when in the group.
4748
//|
4849
//| :param int max_size: The maximum group size.
50+
//| :param int scale: Scale of layer pixels in one dimension.
4951
//|
5052
STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
5153
enum { ARG_max_size, ARG_scale };
@@ -58,12 +60,12 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg
5860

5961
mp_int_t max_size = args[ARG_max_size].u_int;
6062
if (max_size < 1) {
61-
mp_raise_ValueError_varg(translate("Group must have %q at least 1"), MP_QSTR_max_size);
63+
mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_max_size);
6264
}
6365

6466
mp_int_t scale = args[ARG_scale].u_int;
6567
if (scale < 1) {
66-
mp_raise_ValueError_varg(translate("Group must have %q at least 1"), MP_QSTR_scale);
68+
mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_scale);
6769
}
6870

6971
displayio_group_t *self = m_new_obj(displayio_group_t);
@@ -76,7 +78,6 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg
7678
// Helper to ensure we have the native super class instead of a subclass.
7779
static displayio_group_t* native_group(mp_obj_t group_obj) {
7880
mp_obj_t native_group = mp_instance_cast_to_native_base(group_obj, &displayio_group_type);
79-
assert(native_group == MP_OBJ_NULL);
8081
return MP_OBJ_TO_PTR(native_group);
8182
}
8283

@@ -96,7 +97,7 @@ STATIC mp_obj_t displayio_group_obj_set_scale(mp_obj_t self_in, mp_obj_t scale_o
9697

9798
mp_int_t scale = mp_obj_get_int(scale_obj);
9899
if (scale < 1) {
99-
mp_raise_ValueError_varg(translate("Group must have %q at least 1"), MP_QSTR_scale);
100+
mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_scale);
100101
}
101102
common_hal_displayio_group_set_scale(self, scale);
102103
return mp_const_none;

shared-module/displayio/Group.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,26 @@ uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self) {
3939
}
4040

4141
void common_hal_displayio_group_set_scale(displayio_group_t* self, uint32_t scale) {
42+
self->needs_refresh = self->scale != scale;
4243
self->scale = scale;
43-
self->needs_refresh = true;
4444
}
4545

4646
mp_int_t common_hal_displayio_group_get_x(displayio_group_t* self) {
4747
return self->x;
4848
}
4949

5050
void common_hal_displayio_group_set_x(displayio_group_t* self, mp_int_t x) {
51+
self->needs_refresh = self->x != x;
5152
self->x = x;
52-
self->needs_refresh = true;
5353
}
5454

5555
mp_int_t common_hal_displayio_group_get_y(displayio_group_t* self) {
5656
return self->y;
5757
}
5858

5959
void common_hal_displayio_group_set_y(displayio_group_t* self, mp_int_t y) {
60+
self->needs_refresh = self->y != y;
6061
self->y = y;
61-
self->needs_refresh = true;
6262
}
6363

6464
void common_hal_displayio_group_insert(displayio_group_t* self, size_t index, mp_obj_t layer) {

0 commit comments

Comments
 (0)