示例#1
0
    def test_align_right_row(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)

        simple_rect = SimpleTestLayoutRect(dimensions=(20, 30))
        simple_rect_2 = SimpleTestLayoutRect(dimensions=(50, 30))
        simple_rect_3 = SimpleTestLayoutRect(dimensions=(30, 30))
        layout_row.add_item(simple_rect)
        layout_row.add_item(simple_rect_2)
        layout_row.add_item(simple_rect_3)

        layout_row.horiz_center_row(text_box_layout.floating_rects)
        layout_row.align_right_row(
            floating_rects=text_box_layout.floating_rects,
            start_x=text_box_layout.layout_rect.width - 5)

        assert layout_row.left == 95
        assert layout_row.items[0].x == 95
        assert layout_row.items[1].x == 115
        assert layout_row.items[2].x == 165
        assert layout_row.items[2].right == 195
        assert layout_row.right == 195
示例#2
0
    def test_rewind_row(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)

        simple_rect = SimpleTestLayoutRect(dimensions=(200, 30))
        simple_rect_2 = SimpleTestLayoutRect(dimensions=(100, 30))
        simple_rect_3 = SimpleTestLayoutRect(dimensions=(80, 30))
        layout_row.add_item(simple_rect)
        layout_row.add_item(simple_rect_2)
        layout_row.add_item(simple_rect_3)

        rewound_data = deque([])
        layout_row.rewind_row(rewound_data)

        assert rewound_data.pop().width == simple_rect_3.width
        assert rewound_data.pop().width == simple_rect_2.width
        assert rewound_data.pop().width == simple_rect.width
示例#3
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')
示例#4
0
    def test_vert_align_items_to_row(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_2 = pygame.freetype.Font(None, 20)
        font_3 = pygame.freetype.Font(None, 10)
        text_chunk_1 = TextLineChunkFTFont(text='hello ',
                                           font=font_1,
                                           underlined=False,
                                           colour=pygame.Color('#FFFFFF'),
                                           using_default_text_colour=False,
                                           bg_colour=pygame.Color('#FF0000'))
        text_chunk_2 = TextLineChunkFTFont(text='this is a',
                                           font=font_2,
                                           underlined=False,
                                           colour=pygame.Color('#FFFFFF'),
                                           using_default_text_colour=False,
                                           bg_colour=pygame.Color('#FF0000'))
        text_chunk_3 = TextLineChunkFTFont(text=' test',
                                           font=font_3,
                                           underlined=False,
                                           colour=pygame.Color('#FFFFFF'),
                                           using_default_text_colour=False,
                                           bg_colour=pygame.Color('#FF0000'))
        layout_row.add_item(text_chunk_1)
        layout_row.add_item(text_chunk_2)
        layout_row.add_item(text_chunk_3)

        # not sure this is right, need to do some more visual testing of vertical
        # alignment of text rects with different height text on a single row.
        assert layout_row.items[0].y == 0
        assert layout_row.items[1].y == 7
        assert layout_row.items[2].y == 15

        layout_row.vert_align_items_to_row()

        assert layout_row.items[0].y == 0
        assert layout_row.items[1].y == 7
        assert layout_row.items[2].y == 15
示例#5
0
    def test_add_item(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)

        simple_rect = SimpleTestLayoutRect(dimensions=(200, 30))
        layout_row.add_item(simple_rect)

        assert len(layout_row.items) == 1
        assert layout_row.width == simple_rect.width
        assert layout_row.text_chunk_height == simple_rect.height
        assert layout_row.height == int(simple_rect.height * line_spacing)
示例#6
0
    def test_insert_text(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_row.insert_text(' this', 4)

        assert layout_row.items[0].text == 'test this'
示例#7
0
    def test_creation(self, _init_pygame, default_ui_manager: UIManager):
        input_data = deque([])
        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=1.0)
        layout_row = TextBoxLayoutRow(row_start_x=0,
                                      row_start_y=0,
                                      row_index=0,
                                      line_spacing=1.25,
                                      layout=text_box_layout)

        assert layout_row.width == 0
        assert layout_row.height == 0
示例#8
0
    def test_merge_adjacent_compatible_chunks(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_2 = pygame.freetype.Font(None, 20)
        text_chunk_1 = TextLineChunkFTFont(text='hello ',
                                           font=font_1,
                                           underlined=False,
                                           colour=pygame.Color('#FFFFFF'),
                                           using_default_text_colour=False,
                                           bg_colour=pygame.Color('#FF0000'))
        text_chunk_2 = TextLineChunkFTFont(text='this is a',
                                           font=font_1,
                                           underlined=False,
                                           colour=pygame.Color('#FFFFFF'),
                                           using_default_text_colour=False,
                                           bg_colour=pygame.Color('#FF0000'))
        text_chunk_3 = TextLineChunkFTFont(text=' test',
                                           font=font_2,
                                           underlined=False,
                                           colour=pygame.Color('#FFFFFF'),
                                           using_default_text_colour=False,
                                           bg_colour=pygame.Color('#FF0000'))
        layout_row.add_item(text_chunk_1)
        layout_row.add_item(text_chunk_2)
        layout_row.add_item(text_chunk_3)

        assert len(layout_row.items) == 3

        layout_row.merge_adjacent_compatible_chunks()

        assert len(layout_row.items) == 2
示例#9
0
    def test_at_start(self, _init_pygame, default_ui_manager: UIManager):
        input_data = deque([])
        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=1.0)
        layout_row = TextBoxLayoutRow(row_start_x=0,
                                      row_start_y=0,
                                      row_index=0,
                                      line_spacing=1.25,
                                      layout=text_box_layout)

        assert layout_row.at_start()
        simple_rect = SimpleTestLayoutRect(dimensions=(200, 30))
        layout_row.add_item(simple_rect)
        assert not layout_row.at_start()
示例#10
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