Пример #1
0
    def test_clear(self, _init_pygame, default_ui_manager: UIManager):
        input_data = deque([])
        line_spacing = 1.25
        text_box_layout = TextBoxLayout(input_data_queue=input_data,
                                        layout_rect=pygame.Rect(
                                            0, 0, 200, 300),
                                        view_rect=pygame.Rect(0, 0, 200, 150),
                                        line_spacing=line_spacing)
        layout_row = TextBoxLayoutRow(row_start_x=0,
                                      row_start_y=0,
                                      row_index=0,
                                      line_spacing=line_spacing,
                                      layout=text_box_layout)

        font_1 = pygame.freetype.Font(None, 30)
        font_1.origin = True
        font_1.pad = True
        text_chunk_1 = TextLineChunkFTFont(text='D',
                                           font=font_1,
                                           underlined=False,
                                           colour=pygame.Color('#FFFFFF'),
                                           using_default_text_colour=False,
                                           bg_colour=pygame.Color('#00000000'))

        layout_row.add_item(text_chunk_1)
        layout_surface = pygame.Surface((200, 300),
                                        depth=32,
                                        flags=pygame.SRCALPHA)
        layout_surface.fill((0, 0, 0, 0))
        layout_row.finalise(layout_surface)
        assert layout_surface.get_at((18, 18)) == pygame.Color('#FFFFFF')

        layout_row.clear()
        assert layout_surface.get_at((18, 18)) == pygame.Color('#00000000')
Пример #2
0
    def test_set_cursor_position(self):
        input_data = deque([])
        line_spacing = 1.25
        text_box_layout = TextBoxLayout(input_data_queue=input_data,
                                        layout_rect=pygame.Rect(
                                            0, 0, 200, 300),
                                        view_rect=pygame.Rect(0, 0, 200, 150),
                                        line_spacing=line_spacing)
        layout_row = TextBoxLayoutRow(row_start_x=0,
                                      row_start_y=0,
                                      row_index=0,
                                      line_spacing=line_spacing,
                                      layout=text_box_layout)

        font_1 = pygame.freetype.Font(None, 30)
        font_1.origin = True
        font_1.pad = True
        text_chunk_1 = TextLineChunkFTFont(text='test',
                                           font=font_1,
                                           underlined=False,
                                           colour=pygame.Color('#FFFFFF'),
                                           using_default_text_colour=False,
                                           bg_colour=pygame.Color('#00000000'))

        layout_row.add_item(text_chunk_1)

        layout_surface = pygame.Surface((200, 300),
                                        depth=32,
                                        flags=pygame.SRCALPHA)
        layout_surface.fill((0, 0, 0, 0))
        layout_row.finalise(layout_surface)
        layout_row.toggle_cursor()

        assert layout_row.edit_cursor_active is True
        assert layout_surface.get_at((1, 5)) == pygame.Color('#FFFFFF')
        assert layout_row.cursor_index == 0
        assert layout_row.cursor_draw_width == 0

        layout_row.set_cursor_position(3)

        layout_row.toggle_cursor()
        layout_row.toggle_cursor()

        assert layout_row.edit_cursor_active is True
        assert layout_surface.get_at((1, 5)) == pygame.Color('#00000000')
        assert layout_row.cursor_index == 3
        assert layout_row.cursor_draw_width == 44