Ejemplo n.º 1
0
    def get_scrollbar_thickness(self,
                                orientation: str,
                                visible: bool = True) -> int:
        """
        Return the scroll thickness of the area. If it's hidden return zero.

        :param orientation: Orientation of the scroll. See :py:mod:`pygame_menu.locals`
        :param visible: If ``True`` returns the real thickness depending if it is visible or not
        :return: Thickness in px
        """
        assert_orientation(orientation)
        assert isinstance(visible, bool)

        if visible:
            total = 0
            for sbar in self._scrollbars:
                if sbar.get_orientation() == orientation and sbar.is_visible():
                    total += sbar.get_thickness()
            return total

        if orientation == ORIENTATION_HORIZONTAL:
            return int(self._rect.height - self._view_rect.height)
        elif orientation == ORIENTATION_VERTICAL:
            return int(self._rect.width - self._view_rect.width)

        return 0
Ejemplo n.º 2
0
    def __init__(self,
                 width: NumberType,
                 height: NumberType,
                 orientation: FrameOrientationType,
                 frame_id: str = '') -> None:
        super(Frame, self).__init__(widget_id=frame_id)
        assert isinstance(width, (int, float)) and width > 0
        assert isinstance(height, (int, float)) and height > 0
        assert_orientation(orientation)

        # Internals
        self._control_widget = None
        self._control_widget_last_pos = None  # This checks if menu has updated widget position
        self._height = int(height)
        self._orientation = orientation
        self._pos = {}
        self._recursive_render = 0
        self._widgets = {}
        self._width = int(width)

        # Configure widget publics
        self.first_index = -1
        self.horizontal = orientation == _locals.ORIENTATION_HORIZONTAL
        self.is_selectable = False
        self.last_index = -1

        # Stablish rect and surface
        self._rect.height = self._height
        self._rect.width = self._width
        self._surface = make_surface(width, height, alpha=True)
Ejemplo n.º 3
0
    def show_scrollbars(self, orientation: str) -> 'ScrollArea':
        """
        Hide scrollbar from given orientation.

        :param orientation: Orientation. See :py:mod:`pygame_menu.locals`
        :return: Self reference
        """
        assert_orientation(orientation)
        for sbar in self._scrollbars:
            if sbar.get_orientation() == orientation:
                sbar.show()
        return self
Ejemplo n.º 4
0
 def set_orientation(self, orientation):
     """
     Set the scroll bar orientation to vertical or horizontal.
     :param orientation: Widget orientation, could be ORIENTATION_HORIZONTAL/ORIENTATION_VERTICAL
     :type orientation: str
     :return: None
     """
     assert_orientation(orientation)
     if orientation == _locals.ORIENTATION_HORIZONTAL:
         self._orientation = 0
     elif orientation == _locals.ORIENTATION_VERTICAL:
         self._orientation = 1
     self._opp_orientation = int(not self._orientation)
     self._apply_size_changes()
Ejemplo n.º 5
0
    def set_orientation(self, orientation: str) -> None:
        """
        Set the scroll bar orientation to vertical or horizontal.

        .. note::

            See :py:mod:`pygame_menu.locals` for valid ``orientation`` values.

        :param orientation: Widget orientation
        """
        assert_orientation(orientation)
        if orientation == ORIENTATION_HORIZONTAL:
            self._orientation = 0
        elif orientation == ORIENTATION_VERTICAL:
            self._orientation = 1
        self._apply_size_changes()
Ejemplo n.º 6
0
    def set_orientation(self, orientation: ScrollBarOrientationType) -> None:
        """
        Set the scroll bar orientation to vertical or horizontal.

        .. note::

            See :py:mod:`pygame_menu.locals` for valid ``orientation`` values.

        :param orientation: Widget orientation
        :return: None
        """
        assert_orientation(orientation)
        if orientation == _locals.ORIENTATION_HORIZONTAL:
            self._orientation = 0
        elif orientation == _locals.ORIENTATION_VERTICAL:
            self._orientation = 1
        self._opp_orientation = int(not self._orientation)
        self._apply_size_changes()
Ejemplo n.º 7
0
    def show_scrollbars(self,
                        orientation: str,
                        force: bool = True) -> 'ScrollArea':
        """
        Hide scrollbar from given orientation.

        :param orientation: Orientation. See :py:mod:`pygame_menu.locals`
        :param force: Force show
        :return: Self reference
        """
        assert_orientation(orientation)
        for sbar in self._scrollbars:
            if sbar.get_orientation() == orientation:
                sbar.show(force=force)
                if not force:
                    sbar.disable_visibility_force()
        self._apply_size_changes()
        return self
Ejemplo n.º 8
0
    def get_scroll_value_percentage(self, orientation: str) -> float:
        """
        Get the scroll value in percentage; if ``0`` the scroll is at top/left, ``1`` bottom/right.

        .. note::

            If ScrollArea does not contain such orientation scroll, ``-1`` is returned.

        :param orientation: Orientation. See :py:mod:`pygame_menu.locals`
        :return: Value from ``0`` to ``1``
        """
        assert_orientation(orientation)
        for sbar in self._scrollbars:
            if not sbar.is_visible():
                continue
            if sbar.get_orientation() == orientation:
                return sbar.get_value_percentage()
        return -1
Ejemplo n.º 9
0
    def scroll_to(self, orientation: str, value: NumberType) -> 'ScrollArea':
        """
        Scroll to position in terms of the percentage.

        :param orientation: Orientation. See :py:mod:`pygame_menu.locals`
        :param value: If ``0`` scrolls to top/left, ``1`` to bottom/right
        :return: Self reference
        """
        assert_orientation(orientation)
        assert isinstance(value, NumberInstance) and 0 <= value <= 1
        for sbar in self._scrollbars:
            if not sbar.is_visible():
                continue
            if sbar.get_orientation() == orientation:
                v_min, v_max = sbar.get_minmax()
                delta = v_max - v_min
                new_value = int(min(v_min + delta * float(value), v_max))
                sbar.set_value(new_value)
                break
        return self
Ejemplo n.º 10
0
    def __init__(self,
                 width: NumberType,
                 height: NumberType,
                 orientation: str,
                 frame_id: str = '') -> None:
        super(Frame, self).__init__(widget_id=frame_id)
        assert isinstance(width, NumberInstance)
        assert isinstance(height, NumberInstance)
        assert width > 0, 'width must be greater than zero ({0} received)'.format(
            width)
        assert height > 0, 'height must be greater than zero ({0} received)'.format(
            height)
        assert_orientation(orientation)

        # Internals
        self._control_widget = None
        self._control_widget_last_pos = None  # This checks if menu has updated widget position
        self._frame_scrollarea = None
        self._has_frames = False
        self._height = int(height)
        self._orientation = orientation
        self._pack_margin_warning = True  # Set to False for hiding the pack margin warning
        self._pos = {}
        self._real_rect = pygame.Rect(0, 0, width, height)
        self._recursive_render = 0
        self._relax = False  # If True ignore sizing
        self._widgets = {}
        self._widgets_props = {}
        self._width = int(width)

        # Configure widget publics
        self.first_index = -1
        self.horizontal = orientation == _locals.ORIENTATION_HORIZONTAL
        self.is_scrollable = False
        self.is_selectable = False
        self.last_index = -1