Пример #1
0
    def hovered_element(self, new_hover: UIElement):
        if self._hovered_element is not None:
            self._hovered_element.on_unhover()
            self._hovered_element = None

        if new_hover is not None:
            new_hover.on_hover()

        self._hovered_element = new_hover
Пример #2
0
    def focused_element(self, new_focus: UIElement):
        if self._focused_element is not None:
            self._focused_element.on_unfocus()
            self._focused_element = None

        if new_focus is not None:
            new_focus.on_focus()

        self._focused_element = new_focus
Пример #3
0
    def update(self, element: UIElement, space=0, **kwargs):
        cx, cy = self.cursor

        if self._vertical:
            # add offset
            cy -= space
            # position element
            element.center_x = cx
            element.center_y = cy - space - element.height // 2
            # update cursor
            self.cursor = cx, cy - space - element.height
        else:
            # add offset
            cx += space
            # position element
            element.center_x = cx + space + element.width // 2
            element.center_y = cy
            # update cursor
            self.cursor = cx + space + element.width, cy
    def add_ui_element(self, ui_element: UIElement):
        """
        Adds a :py:class:`arcade.gui.UIElement` to the :py:class:`arcade.gui.UIManager`.
        :py:attr:`arcade.gui.UIElement.id` has to be unique.

        The :py:class:`arcade.gui.UIElement` will be drawn by the :py:class:`arcade.gui.UIManager`.
        :param UIElement ui_element: element to add.
        """
        if not hasattr(ui_element, 'id'):
            raise UIException('UIElement seems not to be properly setup, please check if you'
                              ' overwrite the constructor and forgot "super().__init__(**kwargs)"')

        ui_element.render()
        self._ui_elements.append(ui_element)
        ui_element.mng = self

        # Add elements with id to lookup
        if ui_element.id is not None:
            if ui_element.id in self._id_cache:
                raise UIException(f'duplicate id "{ui_element.id}"')

            self._id_cache[ui_element.id] = ui_element
Пример #5
0
    def add_ui_element(self, ui_element: UIElement):
        if not hasattr(ui_element, 'id'):
            raise UIException(
                'UIElement seems not to be properly setup, please check if you'
                ' overwrite the constructor and forgot "super().__init__(**kwargs)"'
            )

        self._ui_elements.append(ui_element)
        ui_element.mng = self

        # Add elements with id to lookup
        if ui_element.id is not None:
            if ui_element.id in self._id_cache:
                raise UIException(f'duplicate id "{ui_element.id}"')

            self._id_cache[ui_element.id] = ui_element