@@ -662,30 +662,34 @@ typedef struct _scrolling_string_t {
662662 mp_uint_t len;
663663 mp_obj_t ref;
664664 bool monospace;
665+ bool repeat;
665666} scrolling_string_t ;
666667
667668typedef struct _scrolling_string_iterator_t {
668669 mp_obj_base_t base;
669670 mp_obj_t ref;
670671 greyscale_t *img;
671672 char const *next_char;
673+ char const *start;
672674 char const *end;
673675 uint8_t offset;
674676 uint8_t offset_limit;
675677 bool monospace;
678+ bool repeat;
676679 char right;
677680} scrolling_string_iterator_t ;
678681
679682extern const mp_obj_type_t microbit_scrolling_string_type;
680683extern const mp_obj_type_t microbit_scrolling_string_iterator_type;
681684
682- mp_obj_t scrolling_string_image_iterable (const char * str, mp_uint_t len, mp_obj_t ref, bool monospace) {
685+ mp_obj_t scrolling_string_image_iterable (const char * str, mp_uint_t len, mp_obj_t ref, bool monospace, bool repeat ) {
683686 scrolling_string_t *result = m_new_obj (scrolling_string_t );
684687 result->base .type = µbit_scrolling_string_type;
685688 result->str = str;
686689 result->len = len;
687690 result->ref = ref;
688691 result->monospace = monospace;
692+ result->repeat = repeat;
689693 return result;
690694}
691695
@@ -709,34 +713,45 @@ STATIC unsigned int rightmost_non_blank_column(const unsigned char *font_data) {
709713 return 2 ;
710714}
711715
716+ static void restart (scrolling_string_iterator_t *iter) {
717+ iter->next_char = iter->start ;
718+ iter->offset = 0 ;
719+ if (iter->start < iter->end ) {
720+ iter->right = *iter->next_char ;
721+ if (iter->monospace ) {
722+ iter->offset_limit = 5 ;
723+ } else {
724+ iter->offset_limit = rightmost_non_blank_column (get_font_data_from_char (iter->right )) + 1 ;
725+ }
726+ } else {
727+ iter->right = ' ' ;
728+ iter->offset_limit = 5 ;
729+ }
730+ }
731+
712732STATIC mp_obj_t get_microbit_scrolling_string_iter (mp_obj_t o_in) {
713733 scrolling_string_t *str = (scrolling_string_t *)o_in;
714734 scrolling_string_iterator_t *result = m_new_obj (scrolling_string_iterator_t );
715735 result->base .type = µbit_scrolling_string_iterator_type;
716736 result->img = greyscale_new (5 ,5 );
717- result->offset = 0 ;
718- result->next_char = str->str ;
737+ result->start = str->str ;
719738 result->ref = str->ref ;
720739 result->monospace = str->monospace ;
721- result->end = result->next_char + str->len ;
722- if (str->len ) {
723- result->right = *result->next_char ;
724- if (result->monospace ) {
725- result->offset_limit = 5 ;
726- } else {
727- result->offset_limit = rightmost_non_blank_column (get_font_data_from_char (result->right )) + 1 ;
728- }
729- } else {
730- result->right = ' ' ;
731- result->offset_limit = 5 ;
732- }
740+ result->end = result->start + str->len ;
741+ result->repeat = str->repeat ;
742+ restart (result);
733743 return result;
734744}
735745
736746STATIC mp_obj_t microbit_scrolling_string_iter_next (mp_obj_t o_in) {
737747 scrolling_string_iterator_t *iter = (scrolling_string_iterator_t *)o_in;
738748 if (iter->next_char == iter->end && iter->offset == 5 ) {
739- return MP_OBJ_STOP_ITERATION;
749+ if (iter->repeat ) {
750+ restart (iter);
751+ iter->img ->clear ();
752+ } else {
753+ return MP_OBJ_STOP_ITERATION;
754+ }
740755 }
741756 iter->img ->shiftLeftInplace (1 );
742757 const unsigned char *font_data;
0 commit comments