Example #1
0
    def test_set_cursor_position(self, _init_pygame,
                                 default_ui_manager: UIManager):
        the_font = pygame.freetype.Font(None, 20)
        input_data = deque([
            TextLineChunkFTFont(text='hello ',
                                font=the_font,
                                underlined=False,
                                colour=pygame.Color('#FFFFFF'),
                                using_default_text_colour=False,
                                bg_colour=pygame.Color('#FF0000')),
            TextLineChunkFTFont(text='this is a',
                                font=the_font,
                                underlined=False,
                                colour=pygame.Color('#FFFFFF'),
                                using_default_text_colour=False,
                                bg_colour=pygame.Color('#FF0000')),
            TextLineChunkFTFont(text=' test',
                                font=the_font,
                                underlined=False,
                                colour=pygame.Color('#FFFFFF'),
                                using_default_text_colour=False,
                                bg_colour=pygame.Color('#FF0000')),
        ])

        layout = TextBoxLayout(input_data_queue=input_data,
                               layout_rect=pygame.Rect(0, 0, 100, 300),
                               view_rect=pygame.Rect(0, 0, 100, 150),
                               line_spacing=1.0)

        layout.set_cursor_position(13)

        assert layout.cursor_text_row is not None
        assert layout.cursor_text_row.cursor_index == 2
        assert layout.cursor_text_row.cursor_draw_width == 17
Example #2
0
    def test_backspace_at_cursor(self, _init_pygame,
                                 default_ui_manager: UIManager):
        the_font = pygame.freetype.Font(None, 20)
        input_data = deque([
            TextLineChunkFTFont(text='hello ',
                                font=the_font,
                                underlined=False,
                                colour=pygame.Color('#FFFFFF'),
                                using_default_text_colour=False,
                                bg_colour=pygame.Color('#FF0000')),
            TextLineChunkFTFont(text='this is a',
                                font=the_font,
                                underlined=False,
                                colour=pygame.Color('#FFFFFF'),
                                using_default_text_colour=True,
                                bg_colour=pygame.Color('#FF0000')),
            TextLineChunkFTFont(text=' test',
                                font=the_font,
                                underlined=False,
                                colour=pygame.Color('#FFFFFF'),
                                using_default_text_colour=False,
                                bg_colour=pygame.Color('#FF0000')),
        ])

        layout = TextBoxLayout(input_data_queue=input_data,
                               layout_rect=pygame.Rect(0, 0, 100, 300),
                               view_rect=pygame.Rect(0, 0, 100, 150),
                               line_spacing=1.0)

        layout.set_cursor_position(16)
        layout.backspace_at_cursor()
        layout.backspace_at_cursor()

        remaining_text = ''
        for row in layout.layout_rows:
            for chunk in row.items:
                remaining_text += chunk.text

        assert remaining_text == 'hello this is test'