diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index 7b79f32291..3365d5d36e 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -41,19 +41,23 @@ //| //| Manage a group of sprites and groups and how they are inter-related. //| -//| .. class:: Group(*, max_size=4, scale=1) +//| .. class:: Group(*, max_size=4, scale=1, x=0, y=0) //| //| Create a Group of a given size and scale. Scale is in one dimension. For example, scale=2 //| leads to a layer's pixel being 2x2 pixels when in the group. //| //| :param int max_size: The maximum group size. //| :param int scale: Scale of layer pixels in one dimension. +//| :param int x: Initial x position within the parent. +//| :param int y: Initial y position within the parent. //| 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) { - enum { ARG_max_size, ARG_scale }; + enum { ARG_max_size, ARG_scale, ARG_x, ARG_y }; static const mp_arg_t allowed_args[] = { { MP_QSTR_max_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 4} }, { MP_QSTR_scale, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} }, + { MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, + { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -70,7 +74,7 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg displayio_group_t *self = m_new_obj(displayio_group_t); self->base.type = &displayio_group_type; - common_hal_displayio_group_construct(self, max_size, scale); + common_hal_displayio_group_construct(self, max_size, scale, args[ARG_x].u_int, args[ARG_y].u_int); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/displayio/Group.h b/shared-bindings/displayio/Group.h index d326dbf4de..fa3c329646 100644 --- a/shared-bindings/displayio/Group.h +++ b/shared-bindings/displayio/Group.h @@ -32,7 +32,7 @@ extern const mp_obj_type_t displayio_group_type; -void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale); +void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y); uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self); void common_hal_displayio_group_set_scale(displayio_group_t* self, uint32_t scale); mp_int_t common_hal_displayio_group_get_x(displayio_group_t* self); diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c index f6bc92dc74..20182863eb 100644 --- a/shared-module/displayio/Group.c +++ b/shared-module/displayio/Group.c @@ -29,9 +29,9 @@ #include "py/runtime.h" #include "shared-bindings/displayio/TileGrid.h" -void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale) { +void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y) { displayio_group_child_t* children = m_new(displayio_group_child_t, max_size); - displayio_group_construct(self, children, max_size, scale); + displayio_group_construct(self, children, max_size, scale, x, y); } uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self) { @@ -116,9 +116,9 @@ void common_hal_displayio_group_set(displayio_group_t* self, size_t index, mp_ob self->needs_refresh = true; } -void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale) { - self->x = 0; - self->y = 0; +void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y) { + self->x = x; + self->y = y; self->children = child_array; self->max_size = max_size; self->needs_refresh = false; diff --git a/shared-module/displayio/Group.h b/shared-module/displayio/Group.h index 61409959d8..7826b9e663 100644 --- a/shared-module/displayio/Group.h +++ b/shared-module/displayio/Group.h @@ -48,7 +48,7 @@ typedef struct { bool needs_refresh; } displayio_group_t; -void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale); +void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale, mp_int_t x, mp_int_t y); bool displayio_group_get_pixel(displayio_group_t *group, int16_t x, int16_t y, uint16_t *pixel); bool displayio_group_needs_refresh(displayio_group_t *self); void displayio_group_finish_refresh(displayio_group_t *self);