def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface,
                  _display_surface_return_none):
        selection_list = UISelectionList(
            relative_rect=pygame.Rect(0, 0, 50, 80),
            item_list=[
                'item 1', 'item 2', 'item 3', 'item 4', 'item 5', 'item 6',
                'item 7', 'item 8', 'item 9', 'item 10', 'item 11', 'item 12',
                'item 13', 'item 14', 'item 15', 'item 16'
            ],
            manager=default_ui_manager,
            allow_multi_select=True)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 13

        selection_list_sprites = [
            default_ui_manager.get_root_container(), selection_list,
            selection_list.list_and_scroll_bar_container,
            selection_list.item_list_container, selection_list.scroll_bar,
            selection_list.scroll_bar.button_container,
            *selection_list.item_list_container.elements,
            selection_list.scroll_bar.top_button,
            selection_list.scroll_bar.bottom_button,
            selection_list.scroll_bar.sliding_button
        ]
        assert default_ui_manager.get_sprite_group().sprites(
        ) == selection_list_sprites
        selection_list.kill()
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        empty_ui_sprites = [default_ui_manager.get_root_container()]
        assert default_ui_manager.get_sprite_group().sprites(
        ) == empty_ui_sprites
예제 #2
0
    def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface,
                  _display_surface_return_none: None):
        window = UIWindow(pygame.Rect(0, 0, 200, 200),
                          window_display_title="Test Window",
                          manager=default_ui_manager)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 6
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container(), window,
            window._window_root_container, window.window_element_container,
            window.title_bar, window.close_window_button
        ]
        window.kill()

        confirm_event_fired = False
        event_object_id = None
        for event in pygame.event.get():
            if (event.type == pygame_gui.UI_WINDOW_CLOSE
                    and event.ui_element == window):
                confirm_event_fired = True
                event_object_id = event.ui_object_id
        assert confirm_event_fired
        assert event_object_id == 'window'
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container()
        ]
    def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface,
                  _display_surface_return_none):
        scroll_bar = UIHorizontalSlider(relative_rect=pygame.Rect(100, 100, 200, 30),
                                        start_value=50,
                                        value_range=(0, 100),
                                        manager=default_ui_manager)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 6
        assert default_ui_manager.get_sprite_group().sprites() == [default_ui_manager.get_root_container(),
                                                                   scroll_bar,
                                                                   scroll_bar.button_container,
                                                                   scroll_bar.left_button,
                                                                   scroll_bar.right_button,
                                                                   scroll_bar.sliding_button]
        scroll_bar.kill()
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        assert default_ui_manager.get_sprite_group().sprites() == [default_ui_manager.get_root_container()]
예제 #4
0
    def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface,
                  _display_surface_return_none):
        scroll_bar = UIVerticalScrollBar(relative_rect=pygame.Rect(100, 100, 30, 150),
                                         visible_percentage=0.7,
                                         manager=default_ui_manager)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 6
        scroll_bar_sprites = [default_ui_manager.get_root_container(),
                              scroll_bar,
                              scroll_bar.button_container,
                              scroll_bar.top_button,
                              scroll_bar.bottom_button,
                              scroll_bar.sliding_button]
        assert default_ui_manager.get_sprite_group().sprites() == scroll_bar_sprites
        scroll_bar.kill()
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        empty_sprites = [default_ui_manager.get_root_container()]
        assert default_ui_manager.get_sprite_group().sprites() == empty_sprites
예제 #5
0
    def __init__(self,
                 html_text: str,
                 hover_distance: Tuple[int, int],
                 manager: IUIManagerInterface,
                 parent_element: UIElement = None,
                 object_id: Union[str, None] = None,
                 anchors: Dict[str, str] = None):

        new_element_ids, new_object_ids = self._create_valid_ids(
            container=None,
            parent_element=parent_element,
            object_id=object_id,
            element_id='tool_tip')
        super().__init__(
            relative_rect=pygame.Rect((0, 0), (-1, -1)),
            manager=manager,
            container=None,
            starting_height=manager.get_sprite_group().get_top_layer() + 1,
            layer_thickness=1,
            element_ids=new_element_ids,
            object_ids=new_object_ids,
            anchors=anchors)

        self.text_block = None
        self.rect_width = None
        self.hover_distance_from_target = hover_distance

        self.rebuild_from_changed_theme_data()

        self.text_block = UITextBox(html_text,
                                    pygame.Rect(0, 0, self.rect_width, -1),
                                    manager=self.ui_manager,
                                    layer_starting_height=self._layer,
                                    parent_element=self)

        self.set_dimensions(self.text_block.rect.size)

        self.set_image(self.ui_manager.get_universal_empty_surface())