Exemplo n.º 1
0
    def test_select(self, _init_pygame: None, default_ui_manager: UIManager,
                    _display_surface_return_none):
        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)

        button.update(0.01)
        button.update(0.01)
        button.update(0.01)
        button.update(0.01)
        button.update(0.01)

        empty_queue = len(button.drawable_shape.states_to_redraw_queue)

        button.select()

        assert (empty_queue == 0 and button.is_selected is True)
Exemplo n.º 2
0
    def test_update(self, _init_pygame, default_ui_manager: UIManager):
        """
        Test update does store button shapes in the long term cache
        """
        button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30),
                          text="Test",
                          manager=default_ui_manager)
        default_ui_manager.theme_update_acc = 5.0
        default_ui_manager.get_theme()._theme_file_last_modified = None
        starting_long_term_cache_size = len(
            default_ui_manager.ui_theme.shape_cache.cache_long_term_lookup)
        default_ui_manager.update(0.01)
        long_term_cache_size_after_update = len(
            default_ui_manager.ui_theme.shape_cache.cache_long_term_lookup)

        button.hovered = True
        button.select()
        default_ui_manager.update(0.01)

        assert long_term_cache_size_after_update > starting_long_term_cache_size
Exemplo n.º 3
0
    def test_update(self, _init_pygame, default_ui_manager: UIManager,
                    _display_surface_return_none):
        """
        Test update does store button shapes in the long term cache
        """
        button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30), text="Test", manager=default_ui_manager)
        default_ui_manager.theme_update_acc = 5.0
        default_ui_manager.get_theme()._theme_file_last_modified = None
        starting_long_term_cache_size = len(default_ui_manager.ui_theme.shape_cache.cache_long_term_lookup)
        default_ui_manager.update(0.01)
        long_term_cache_size_after_update = len(default_ui_manager.ui_theme.shape_cache.cache_long_term_lookup)

        button.hovered = True
        button.select()
        default_ui_manager.update(0.01)

        assert long_term_cache_size_after_update > starting_long_term_cache_size

        window = UIWindow(pygame.Rect(100, 100, 200, 200), window_display_title="Test Window",
                          manager=default_ui_manager, element_id='test_window',
                          resizable=True)

        default_ui_manager.mouse_position = (window.rect.left + window.shadow_width,
                                             window.rect.top + window.shadow_width)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[0]
        assert window.edge_hovering[1]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['xy']

        default_ui_manager.mouse_position = (window.rect.right - window.shadow_width,
                                             window.rect.top + window.shadow_width)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[2]
        assert window.edge_hovering[1]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['yx']

        default_ui_manager.mouse_position = (window.rect.left + window.shadow_width,
                                             window.rect.centery)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[0]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['xl']

        default_ui_manager.mouse_position = (window.rect.right - window.shadow_width,
                                             window.rect.centery)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[2]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['xr']

        default_ui_manager.mouse_position = (window.rect.centerx,
                                             window.rect.top + window.shadow_width)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[1]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['yt']

        default_ui_manager.mouse_position = (window.rect.centerx,
                                             window.rect.bottom - window.shadow_width)
        window.resizing_mode_active = False
        window.check_hover(0.05, False)
        assert window.edge_hovering[3]
        window.resizing_mode_active = True
        window.start_resize_rect = pygame.Rect(100, 100, 200, 200)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.resizing_window_cursors['yb']

        window.resizing_mode_active = False
        window.check_hover(0.05, False)

        default_ui_manager.update(0.05)
        assert default_ui_manager._active_cursor == default_ui_manager.active_user_cursor