Skip to content

Commit 555d67a

Browse files
committed
pybricks.parameters.Image: Add Image.set_font.
Use this method to choose the font to use for draw_text and print. Refs: pybricks/support#2154
1 parent 6fa2dbe commit 555d67a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pybricks/parameters/pb_type_image.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,15 @@ static mp_obj_t pb_type_Image_print(size_t n_args, const mp_obj_t *pos_args, mp_
416416
}
417417
static MP_DEFINE_CONST_FUN_OBJ_KW(pb_type_Image_print_obj, 1, pb_type_Image_print);
418418

419+
static mp_obj_t pb_type_Image_set_font(mp_obj_t self_in, mp_obj_t font_in) {
420+
pb_type_Image_obj_t *self = MP_OBJ_TO_PTR(self_in);
421+
422+
self->image.print_font = pb_type_Font_get_font(font_in);
423+
424+
return mp_const_none;
425+
}
426+
static MP_DEFINE_CONST_FUN_OBJ_2(pb_type_Image_set_font_obj, pb_type_Image_set_font);
427+
419428
// dir(pybricks.parameters.Image)
420429
static const mp_rom_map_elem_t pb_type_Image_locals_dict_table[] = {
421430
// REVISIT: consider close() method and __enter__/__exit__ for context manager
@@ -431,6 +440,7 @@ static const mp_rom_map_elem_t pb_type_Image_locals_dict_table[] = {
431440
{ MP_ROM_QSTR(MP_QSTR_draw_circle), MP_ROM_PTR(&pb_type_Image_draw_circle_obj) },
432441
{ MP_ROM_QSTR(MP_QSTR_draw_text), MP_ROM_PTR(&pb_type_Image_draw_text_obj) },
433442
{ MP_ROM_QSTR(MP_QSTR_print), MP_ROM_PTR(&pb_type_Image_print_obj) },
443+
{ MP_ROM_QSTR(MP_QSTR_set_font), MP_ROM_PTR(&pb_type_Image_set_font_obj) },
434444
};
435445
static MP_DEFINE_CONST_DICT(pb_type_Image_locals_dict, pb_type_Image_locals_dict_table);
436446

0 commit comments

Comments
 (0)