Skip to content

Commit ea45877

Browse files
committed
Accept x and y kwargs into Group for initial position.
1 parent 2169a62 commit ea45877

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

shared-bindings/displayio/Group.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,23 @@
4141
//|
4242
//| Manage a group of sprites and groups and how they are inter-related.
4343
//|
44-
//| .. class:: Group(*, max_size=4, scale=1)
44+
//| .. class:: Group(*, max_size=4, scale=1, x=0, y=0)
4545
//|
4646
//| Create a Group of a given size and scale. Scale is in one dimension. For example, scale=2
4747
//| leads to a layer's pixel being 2x2 pixels when in the group.
4848
//|
4949
//| :param int max_size: The maximum group size.
5050
//| :param int scale: Scale of layer pixels in one dimension.
51+
//| :param int x: Initial x position within the parent.
52+
//| :param int y: Initial y position within the parent.
5153
//|
5254
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) {
53-
enum { ARG_max_size, ARG_scale };
55+
enum { ARG_max_size, ARG_scale, ARG_x, ARG_y };
5456
static const mp_arg_t allowed_args[] = {
5557
{ MP_QSTR_max_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 4} },
5658
{ MP_QSTR_scale, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} },
59+
{ MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
60+
{ MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
5761
};
5862
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
5963
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
7074

7175
displayio_group_t *self = m_new_obj(displayio_group_t);
7276
self->base.type = &displayio_group_type;
73-
common_hal_displayio_group_construct(self, max_size, scale);
77+
common_hal_displayio_group_construct(self, max_size, scale, args[ARG_x].u_int, args[ARG_y].u_int);
7478

7579
return MP_OBJ_FROM_PTR(self);
7680
}

shared-bindings/displayio/Group.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
extern const mp_obj_type_t displayio_group_type;
3333

3434

35-
void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale);
35+
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);
3636
uint32_t common_hal_displayio_group_get_scale(displayio_group_t* self);
3737
void common_hal_displayio_group_set_scale(displayio_group_t* self, uint32_t scale);
3838
mp_int_t common_hal_displayio_group_get_x(displayio_group_t* self);

shared-module/displayio/Group.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include "py/runtime.h"
3030
#include "shared-bindings/displayio/TileGrid.h"
3131

32-
void common_hal_displayio_group_construct(displayio_group_t* self, uint32_t max_size, uint32_t scale) {
32+
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) {
3333
displayio_group_child_t* children = m_new(displayio_group_child_t, max_size);
34-
displayio_group_construct(self, children, max_size, scale);
34+
displayio_group_construct(self, children, max_size, scale, x, y);
3535
}
3636

3737
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
116116
self->needs_refresh = true;
117117
}
118118

119-
void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale) {
120-
self->x = 0;
121-
self->y = 0;
119+
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) {
120+
self->x = x;
121+
self->y = y;
122122
self->children = child_array;
123123
self->max_size = max_size;
124124
self->needs_refresh = false;

shared-module/displayio/Group.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef struct {
4848
bool needs_refresh;
4949
} displayio_group_t;
5050

51-
void displayio_group_construct(displayio_group_t* self, displayio_group_child_t* child_array, uint32_t max_size, uint32_t scale);
51+
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);
5252
bool displayio_group_get_pixel(displayio_group_t *group, int16_t x, int16_t y, uint16_t *pixel);
5353
bool displayio_group_needs_refresh(displayio_group_t *self);
5454
void displayio_group_finish_refresh(displayio_group_t *self);

0 commit comments

Comments
 (0)