コード例 #1
0
    def add_element(self, element: IUIElementInterface):
        """
        Add a UIElement to the container. The UI's relative_rect parameter will be relative to
        this container.

        :param element: A UIElement to add to this container.

        """
        element.change_layer(self._layer + element.get_starting_height())
        self.elements.append(element)
        self.calc_add_element_changes_thickness(element)
コード例 #2
0
ファイル: ui_container.py プロジェクト: trungtran8522/suraimu
    def calc_add_element_changes_thickness(self, element: IUIElementInterface):
        """
        This function checks if a single added element will increase the containers thickness
        and if so updates containers recursively.

        :param element: the element to check.
        """
        if (element.get_top_layer() > self.max_element_top_layer
                and element not in self.ui_manager.get_window_stack().get_stack()
                and (not isinstance(element, UIContainer) or not element.is_window_root_container)):

            self.max_element_top_layer = element.get_top_layer()
            self.layer_thickness = self.max_element_top_layer - self._layer
            if self.ui_container is not None and self.ui_container != self:
                self.ui_container.calc_add_element_changes_thickness(self)
コード例 #3
0
    def remove_element(self, element: IUIElementInterface):
        """
        Remove a UIElement from this container.

        :param element: A UIElement to remove from this container.

        """
        if element in self.elements:
            self.elements.remove(element)
        if element.get_top_layer() == self.max_element_top_layer:
            self.recalculate_container_layer_thickness()
コード例 #4
0
ファイル: ui_manager.py プロジェクト: pepe1977/pygame_gui
    def set_focus_element(self, ui_element: IUIElementInterface):
        """
        Set an element as the focused element.

        If the element is a scroll bar we also keep track of that.

        :param ui_element: The element to focus on.
        """
        if ui_element is self.focused_element:
            return
        if self.focused_element is not None:
            self.focused_element.unfocus()
            self.focused_element = None

        if self.focused_element is None:
            self.focused_element = ui_element
            if ui_element is not None:
                self.focused_element.focus()

                if 'vertical_scroll_bar' in ui_element.get_element_ids():
                    self.last_focused_vertical_scrollbar = ui_element
                if 'horizontal_scroll_bar' in ui_element.get_element_ids():
                    self.last_focused_horizontal_scrollbar = ui_element