def test_set_visual_debug_mode(self, _init_pygame, default_ui_manager: IUIManagerInterface, _display_surface_return_none): default_ui_manager.preload_fonts([{ 'name': 'fira_code', 'point_size': 8, 'style': 'regular' }]) element = UIElement(relative_rect=pygame.Rect(0, 0, 50, 50), manager=default_ui_manager, container=None, starting_height=0, layer_thickness=1) assert element.image is None element.set_visual_debug_mode(True) assert element.image is not None element.set_visual_debug_mode(False) assert element.image is None coloured_surface = pygame.Surface((50, 50)) coloured_surface.fill(pygame.Color(200, 80, 80, 255)) element.set_image(coloured_surface) assert element.pre_debug_image is None element.set_visual_debug_mode(True) assert element.pre_debug_image is not None element.set_visual_debug_mode(False) assert element.pre_debug_image is None
def test_add_element(self, _init_pygame, default_ui_manager: IUIManagerInterface, _display_surface_return_none): container = UIScrollingContainer(pygame.Rect(100, 100, 200, 200), manager=default_ui_manager) button = UIButton(relative_rect=pygame.Rect(0, 0, 50, 50), text="", manager=default_ui_manager) default_ui_manager.get_root_container().remove_element(button) container.get_container().add_element(button) assert len(container.get_container().elements) == 1
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
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_set_image(self, _init_pygame, default_ui_manager: IUIManagerInterface): element = UIElement(relative_rect=pygame.Rect(0, 0, 50, 50), manager=default_ui_manager, container=None, starting_height=0, layer_thickness=1) coloured_surface_1 = pygame.Surface((50, 50), flags=pygame.SRCALPHA, depth=32) coloured_surface_1.fill(pygame.Color(200, 80, 80, 255)) element.set_image(coloured_surface_1) assert element.image.get_at((10, 10)) == pygame.Color(200, 80, 80, 255) coloured_surface_2 = pygame.Surface((50, 50), flags=pygame.SRCALPHA, depth=32) coloured_surface_2.fill(pygame.Color(200, 150, 180, 255)) element.set_image_clip(pygame.Rect(0, 0, 25, 50)) element.set_image(coloured_surface_2) assert element.image.get_at( (10, 10)) == pygame.Color(200, 150, 180, 255) element.set_image_clip(pygame.Rect(0, 0, 0, 0)) element.set_image(coloured_surface_1) assert element.image == default_ui_manager.get_universal_empty_surface( ) element.set_image_clip(None) element.set_image(None) assert element.image is None
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()]
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
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())
def test_set_blocking(self, _init_pygame, default_ui_manager: IUIManagerInterface, _display_surface_return_none): window = UIWindow(pygame.Rect(200, 200, 200, 200), window_display_title="Test Window", manager=default_ui_manager, element_id='window') button = UIButton( relative_rect=pygame.Rect(10, 10, 150, 30), text="Test Button", tool_tip_text= "This is a test of the button's tool tip functionality.", manager=default_ui_manager, allow_double_clicks=True) default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': pygame.BUTTON_LEFT, 'pos': button.rect.center })) assert button.held default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONUP, { 'button': pygame.BUTTON_LEFT, 'pos': button.rect.center })) window.set_blocking(True) default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': pygame.BUTTON_LEFT, 'pos': button.rect.center })) assert not button.held