Example #1
0
    def test_enable(self, _init_pygame: None, default_ui_manager: UIManager,
                    _display_surface_return_none: None):
        scroll_bar = UIHorizontalScrollBar(relative_rect=pygame.Rect(
            0, 0, 200, 30),
                                           visible_percentage=0.25,
                                           manager=default_ui_manager)

        scroll_bar.disable()
        scroll_bar.enable()

        # process a mouse button down event
        scroll_bar.right_button.process_event(
            pygame.event.Event(pygame.MOUSEBUTTONDOWN, {
                'button': 1,
                'pos': scroll_bar.right_button.rect.center
            }))

        scroll_bar.update(0.1)

        # process a mouse button up event
        scroll_bar.right_button.process_event(
            pygame.event.Event(pygame.MOUSEBUTTONUP, {
                'button': 1,
                'pos': scroll_bar.right_button.rect.center
            }))

        assert scroll_bar.scroll_position != 0.0 and scroll_bar.is_enabled is True
Example #2
0
    def test_check_has_moved_recently(self, _init_pygame, default_ui_manager,
                                      _display_surface_return_none):
        scroll_bar = UIHorizontalScrollBar(relative_rect=pygame.Rect(
            100, 100, 150, 30),
                                           visible_percentage=0.7,
                                           manager=default_ui_manager)

        # move the scroll bar a bit
        scroll_bar.right_button.held = True
        scroll_bar.update(0.2)
        assert scroll_bar.check_has_moved_recently() is True
Example #3
0
    def test_check_update_buttons(self, _init_pygame, default_ui_manager,
                                  _display_surface_return_none):
        scroll_bar = UIHorizontalScrollBar(relative_rect=pygame.Rect(
            100, 100, 150, 30),
                                           visible_percentage=0.7,
                                           manager=default_ui_manager)

        # scroll down a bit then up again to exercise update
        scroll_bar.right_button.held = True
        scroll_bar.update(0.3)
        scroll_bar.right_button.held = False
        scroll_bar.left_button.held = True
        scroll_bar.update(0.3)

        assert scroll_bar.check_has_moved_recently() is True
Example #4
0
    def test_check_update_sliding_bar(self, _init_pygame, default_ui_manager,
                                      _display_surface_return_none):
        scroll_bar = UIHorizontalScrollBar(relative_rect=pygame.Rect(
            0, 0, 150, 30),
                                           visible_percentage=0.7,
                                           manager=default_ui_manager)

        # scroll down a bit then up again to exercise update
        default_ui_manager.mouse_position = (100, 15)
        scroll_bar.sliding_button.held = True
        scroll_bar.update(0.3)

        assert scroll_bar.grabbed_slider is True

        scroll_bar.sliding_button.held = False
        scroll_bar.update(0.3)

        assert scroll_bar.grabbed_slider is False