def __init__(self, relative_rect: pygame.Rect, starting_layer_height: int, manager: IUIManagerInterface, *, element_id: str = 'panel', margins: Dict[str, int] = None, container: Union[IContainerLikeInterface, None] = None, parent_element: UIElement = None, object_id: Union[str, None] = None, anchors: Dict[str, str] = None): super().__init__(relative_rect, manager, container, starting_height=starting_layer_height, layer_thickness=1, anchors=anchors) self._create_valid_ids(container=container, parent_element=parent_element, object_id=object_id, element_id=element_id) self.background_colour = None self.border_colour = None self.background_image = None self.border_width = 1 self.shadow_width = 2 self.shape_corner_radius = 0 self.shape = 'rectangle' self.rebuild_from_changed_theme_data() if margins is None: self.container_margins = { 'left': self.shadow_width + self.border_width, 'right': self.shadow_width + self.border_width, 'top': self.shadow_width + self.border_width, 'bottom': self.shadow_width + self.border_width } else: self.container_margins = margins container_rect = pygame.Rect( self.relative_rect.left + self.container_margins['left'], self.relative_rect.top + self.container_margins['top'], self.relative_rect.width - (self.container_margins['left'] + self.container_margins['right']), self.relative_rect.height - (self.container_margins['top'] + self.container_margins['bottom'])) self.panel_container = UIContainer( container_rect, manager, starting_height=starting_layer_height, container=container, parent_element=self, object_id='#panel_container', anchors=anchors)
def rebuild(self): """ A complete rebuild of the drawable shape used by this element. """ theming_parameters = {'normal_bg': self.background_colour, 'normal_border': self.border_colour, 'normal_image': self.background_image, 'border_width': self.border_width, 'shadow_width': self.shadow_width, 'shape_corner_radius': self.shape_corner_radius} if self.shape == 'rectangle': self.drawable_shape = RectDrawableShape(self.rect, theming_parameters, ['normal'], self.ui_manager) elif self.shape == 'rounded_rectangle': self.drawable_shape = RoundedRectangleShape(self.rect, theming_parameters, ['normal'], self.ui_manager) self.on_fresh_drawable_shape_ready() if self.list_and_scroll_bar_container is None: self.list_and_scroll_bar_container = UIContainer( pygame.Rect(self.relative_rect.left + self.shadow_width + self.border_width, self.relative_rect.top + self.shadow_width + self.border_width, self.relative_rect.width - (2 * self.shadow_width) - (2 * self.border_width), self.relative_rect.height - (2 * self.shadow_width) - (2 * self.border_width)), manager=self.ui_manager, starting_height=self.starting_height, container=self.ui_container, parent_element=self._parent_element, object_id='#selection_list_container', anchors=self.anchors, visible=self.visible ) self.join_focus_sets(self.list_and_scroll_bar_container) else: self.list_and_scroll_bar_container.set_dimensions((self.relative_rect.width - (2 * self.shadow_width) - (2 * self.border_width), self.relative_rect.height - (2 * self.shadow_width) - (2 * self.border_width))) self.list_and_scroll_bar_container.set_relative_position((self.relative_rect.left + self.shadow_width + self.border_width, self.relative_rect.top + self.shadow_width + self.border_width)) self.set_item_list(self._raw_item_list)
def __init__(self, relative_rect: pygame.Rect, manager: IUIManagerInterface, name: str, channel_index: int, value_range: Tuple[int, int], initial_value: int, container: Union[IContainerLikeInterface, None] = None, parent_element: UIElement = None, object_id: Union[ObjectID, str, None] = None, anchors: Dict[str, str] = None, visible: int = 1): super().__init__(relative_rect, manager, container, starting_height=1, layer_thickness=1, anchors=anchors, visible=visible) self._create_valid_ids(container=container, parent_element=parent_element, object_id=object_id, element_id='colour_channel_editor') self.range = value_range self.current_value = initial_value self.channel_index = channel_index self.set_image(self.ui_manager.get_universal_empty_surface()) self.element_container = UIContainer(relative_rect, self.ui_manager, container=self.ui_container, parent_element=self, anchors=anchors, visible=self.visible) default_sizes = { 'space_between': 3, 'label_width': 17, 'entry_width': 43, 'line_height': 29, 'slider_height': 21, 'slider_vert_space': 4 } self.label = UILabel(pygame.Rect(0, 0, -1, default_sizes['line_height']), text=name, manager=self.ui_manager, container=self.element_container, parent_element=self, anchors={ 'left': 'left', 'right': 'left', 'top': 'top', 'bottom': 'bottom' }) self.entry = UITextEntryLine(pygame.Rect(-default_sizes['entry_width'], 0, default_sizes['entry_width'], default_sizes['line_height']), manager=self.ui_manager, container=self.element_container, parent_element=self, anchors={ 'left': 'right', 'right': 'right', 'top': 'top', 'bottom': 'bottom' }) slider_width = (self.entry.rect.left - self.label.rect.right) - ( 2 * default_sizes['space_between']) self.slider = UIHorizontalSlider(pygame.Rect( (self.label.get_abs_rect().width + default_sizes['space_between']), default_sizes['slider_vert_space'], slider_width, default_sizes['slider_height']), start_value=initial_value, value_range=value_range, manager=self.ui_manager, container=self.element_container, parent_element=self, anchors={ 'left': 'left', 'right': 'right', 'top': 'top', 'bottom': 'bottom' }) self.entry.set_allowed_characters('numbers') self.entry.set_text(str(initial_value)) self.entry.set_text_length_limit(3)
def rebuild(self): """ Rebuild anything that might need rebuilding. """ border_and_shadow = self.border_width + self.shadow_width self.background_rect = pygame.Rect((border_and_shadow + self.relative_rect.x, border_and_shadow + self.relative_rect.y), (self.relative_rect.width - (2 * border_and_shadow), self.relative_rect.height - (2 * border_and_shadow))) theming_parameters = {'normal_bg': self.background_colour, 'normal_border': self.border_colour, 'border_width': self.border_width, 'shadow_width': self.shadow_width, 'shape_corner_radius': self.shape_corner_radius} if self.shape_type == 'rectangle': self.drawable_shape = RectDrawableShape(self.rect, theming_parameters, ['normal'], self.ui_manager) elif self.shape_type == 'rounded_rectangle': self.drawable_shape = RoundedRectangleShape(self.rect, theming_parameters, ['normal'], self.ui_manager) self.set_image(self.drawable_shape.get_surface('normal')) if self.button_container is None: self.button_container = UIContainer(self.background_rect, manager=self.ui_manager, container=self.ui_container, anchors=self.anchors, object_id='#horiz_scrollbar_buttons_container') else: self.button_container.set_dimensions(self.background_rect.size) self.button_container.set_relative_position(self.background_rect.topleft) # Things below here depend on theme data so need to be updated on a rebuild if self.arrow_buttons_enabled: self.arrow_button_width = self.default_button_width if self.left_button is None: self.left_button = UIButton(pygame.Rect((0, 0), (self.arrow_button_width, self.background_rect.height)), '◀', self.ui_manager, container=self.button_container, starting_height=1, parent_element=self, object_id='#left_button', anchors={'left': 'left', 'right': 'left', 'top': 'top', 'bottom': 'bottom'} ) if self.right_button is None: self.right_button = UIButton(pygame.Rect((-self.arrow_button_width, 0), (self.arrow_button_width, self.background_rect.height)), '▶', self.ui_manager, container=self.button_container, starting_height=1, parent_element=self, object_id='#right_button', anchors={'left': 'right', 'right': 'right', 'top': 'top', 'bottom': 'bottom'}) else: self.arrow_button_width = 0 if self.left_button is not None: self.left_button.kill() self.left_button = None if self.right_button is not None: self.right_button.kill() self.right_button = None self.scrollable_width = (self.background_rect.width - self.sliding_button_width - (2 * self.arrow_button_width)) self.right_limit_position = self.scrollable_width self.scroll_position = self.scrollable_width / 2 if self.sliding_button is not None: sliding_x_pos = int((self.background_rect.width / 2) - (self.sliding_button_width / 2)) self.sliding_button.set_relative_position((sliding_x_pos, 0)) self.sliding_button.set_dimensions((self.sliding_button_width, self.background_rect.height)) self.sliding_button.set_hold_range((self.background_rect.width, 100)) self.set_current_value(self.current_value)
def rebuild(self): """ Rebuilds the window when the theme has changed. """ if self._window_root_container is None: self._window_root_container = UIContainer(pygame.Rect(self.relative_rect.x + self.shadow_width, self.relative_rect.y + self.shadow_width, self.relative_rect.width - (2 * self.shadow_width), self.relative_rect.height - (2 * self.shadow_width)), manager=self.ui_manager, starting_height=1, is_window_root_container=True, container=None, parent_element=self, object_id="#window_root_container") if self.window_element_container is None: window_container_rect = pygame.Rect(self.border_width, self.title_bar_height, (self._window_root_container.relative_rect.width - (2 * self.border_width)), (self._window_root_container.relative_rect.height - self.title_bar_height - self.border_width)) self.window_element_container = UIContainer(window_container_rect, self.ui_manager, starting_height=0, container=self._window_root_container, parent_element=self, object_id="#window_element_container", anchors={'top': 'top', 'bottom': 'bottom', 'left': 'left', 'right': 'right'}) theming_parameters = {'normal_bg': self.background_colour, 'normal_border': self.border_colour, 'border_width': self.border_width, 'shadow_width': self.shadow_width, 'shape_corner_radius': self.shape_corner_radius} if self.shape_type == 'rectangle': self.drawable_shape = RectDrawableShape(self.rect, theming_parameters, ['normal'], self.ui_manager) elif self.shape_type == 'rounded_rectangle': self.drawable_shape = RoundedRectangleShape(self.rect, theming_parameters, ['normal'], self.ui_manager) self.set_image(self.drawable_shape.get_surface('normal')) self.set_dimensions(self.relative_rect.size) if self.window_element_container is not None: element_container_width = (self._window_root_container.relative_rect.width - (2 * self.border_width)) element_container_height = (self._window_root_container.relative_rect.height - self.title_bar_height) self.window_element_container.set_dimensions((element_container_width, element_container_height)) self.window_element_container.set_relative_position((self.border_width, self.title_bar_height)) if self.enable_title_bar: if self.title_bar is not None: self.title_bar.set_dimensions((self._window_root_container.relative_rect.width - self.title_bar_button_width, self.title_bar_height)) else: title_bar_width = (self._window_root_container.relative_rect.width - self.title_bar_button_width) self.title_bar = UIButton(relative_rect=pygame.Rect(0, 0, title_bar_width, self.title_bar_height), text=self.window_display_title, manager=self.ui_manager, container=self._window_root_container, parent_element=self, object_id='#title_bar', anchors={'top': 'top', 'bottom': 'top', 'left': 'left', 'right': 'right'} ) self.title_bar.set_hold_range((100, 100)) if self.enable_close_button: if self.close_window_button is not None: close_button_pos = (-self.title_bar_button_width, 0) self.close_window_button.set_dimensions((self.title_bar_button_width, self.title_bar_height)) self.close_window_button.set_relative_position(close_button_pos) else: close_rect = pygame.Rect((-self.title_bar_button_width, 0), (self.title_bar_button_width, self.title_bar_height)) self.close_window_button = UIButton(relative_rect=close_rect, text='╳', manager=self.ui_manager, container=self._window_root_container, parent_element=self, object_id='#close_button', anchors={'top': 'top', 'bottom': 'top', 'left': 'right', 'right': 'right'} ) else: if self.close_window_button is not None: self.close_window_button.kill() self.close_window_button = None else: if self.title_bar is not None: self.title_bar.kill() self.title_bar = None if self.close_window_button is not None: self.close_window_button.kill() self.close_window_button = None
def __init__(self, relative_rect: pygame.Rect, manager: IUIManagerInterface, *, starting_height: int = 1, container: Union[IContainerLikeInterface, None] = None, parent_element: Union[UIElement, None] = None, object_id: Union[ObjectID, str, None] = None, anchors: Union[Dict[str, str], None] = None, visible: int = 1): super().__init__(relative_rect, manager, container, starting_height=starting_height, layer_thickness=2, anchors=anchors, visible=visible) self._create_valid_ids(container=container, parent_element=parent_element, object_id=object_id, element_id='scrolling_container') # self.parent_element = parent_element self.scroll_bar_width = 0 self.scroll_bar_height = 0 self.need_to_sort_out_scrollbars = False self.vert_scroll_bar = None # type: Union[UIVerticalScrollBar, None] self.horiz_scroll_bar = None # type: Union[UIHorizontalScrollBar, None] self.set_image(self.ui_manager.get_universal_empty_surface()) # this contains the scroll bars and the 'view' container self._root_container = UIContainer(relative_rect=relative_rect, manager=manager, starting_height=starting_height, container=container, parent_element=parent_element, object_id=ObjectID(object_id='#root_container', class_id=None), anchors=anchors, visible=self.visible) # This container is the view on to the scrollable container it's size is determined by # the size of the root container and whether there are any scroll bars or not. view_rect = pygame.Rect(0, 0, relative_rect.width, relative_rect.height) self._view_container = UIContainer(relative_rect=view_rect, manager=manager, starting_height=0, container=self._root_container, parent_element=parent_element, object_id=ObjectID(object_id='#view_container', class_id=None), anchors={'left': 'left', 'right': 'right', 'top': 'top', 'bottom': 'bottom'}) # This container is what we actually put other stuff in. # It is aligned to the top left corner but that isn't that important for a container that # can be much larger than it's view scrollable_rect = pygame.Rect(0, 0, relative_rect.width, relative_rect.height) self.scrollable_container = UIContainer(relative_rect=scrollable_rect, manager=manager, starting_height=0, container=self._view_container, parent_element=parent_element, object_id=ObjectID( object_id='#scrollable_container', class_id=None), anchors={'left': 'left', 'right': 'left', 'top': 'top', 'bottom': 'top'}) self.scrolling_height = 0 self.scrolling_width = 0 self.scrolling_bottom = 0 self.scrolling_right = 0 self._calculate_scrolling_dimensions()
def set_item_list(self, new_item_list: Union[List[str], List[Tuple[str, str]]]): """ Set a new string list (or tuple of strings & ids list) as the item list for this selection list. This will change what is displayed in the list. Tuples should be arranged like so: (list_text, object_ID) - list_text: displayed in the UI - object_ID: used for theming and events :param new_item_list: The new list to switch to. Can be a list of strings or tuples. """ self._raw_item_list = new_item_list self.item_list = [] # type: List[Dict] for new_item in new_item_list: if isinstance(new_item, str): new_item_list_item = { 'text': new_item, 'button_element': None, 'selected': False, 'object_id': '#item_list_item' } elif isinstance(new_item, tuple): new_item_list_item = { 'text': new_item[0], 'button_element': None, 'selected': False, 'object_id': new_item[1] } else: raise ValueError('Invalid item list') self.item_list.append(new_item_list_item) self.total_height_of_list = self.list_item_height * len(self.item_list) self.lowest_list_pos = ( self.total_height_of_list - self.list_and_scroll_bar_container.relative_rect.height) inner_visible_area_height = self.list_and_scroll_bar_container.relative_rect.height if self.total_height_of_list > inner_visible_area_height: # we need a scroll bar self.current_scroll_bar_width = self.scroll_bar_width percentage_visible = inner_visible_area_height / max( self.total_height_of_list, 1) if self.scroll_bar is not None: self.scroll_bar.reset_scroll_position() self.scroll_bar.set_visible_percentage(percentage_visible) self.scroll_bar.start_percentage = 0 else: self.scroll_bar = UIVerticalScrollBar( pygame.Rect(-self.scroll_bar_width, 0, self.scroll_bar_width, inner_visible_area_height), visible_percentage=percentage_visible, manager=self.ui_manager, parent_element=self, container=self.list_and_scroll_bar_container, anchors={ 'left': 'right', 'right': 'right', 'top': 'top', 'bottom': 'bottom' }) self.join_focus_sets(self.scroll_bar) else: if self.scroll_bar is not None: self.scroll_bar.kill() self.scroll_bar = None self.current_scroll_bar_width = 0 # create button list container if self.item_list_container is not None: self.item_list_container.clear() if (self.item_list_container.relative_rect.width != (self.list_and_scroll_bar_container.relative_rect.width - self.current_scroll_bar_width)): container_dimensions = ( self.list_and_scroll_bar_container.relative_rect.width - self.current_scroll_bar_width, self.list_and_scroll_bar_container.relative_rect.height) self.item_list_container.set_dimensions(container_dimensions) else: self.item_list_container = UIContainer( pygame.Rect( 0, 0, self.list_and_scroll_bar_container.relative_rect.width - self.current_scroll_bar_width, self.list_and_scroll_bar_container.relative_rect.height), manager=self.ui_manager, starting_height=0, parent_element=self, container=self.list_and_scroll_bar_container, object_id='#item_list_container', anchors={ 'left': 'left', 'right': 'right', 'top': 'top', 'bottom': 'bottom' }) self.join_focus_sets(self.item_list_container) item_y_height = 0 for item in self.item_list: if item_y_height <= self.item_list_container.relative_rect.height: button_rect = pygame.Rect( 0, item_y_height, self.item_list_container.relative_rect.width, self.list_item_height) item['button_element'] = UIButton( relative_rect=button_rect, text=item['text'], manager=self.ui_manager, parent_element=self, container=self.item_list_container, object_id=ObjectID(object_id=item['object_id'], class_id='@selection_list_item'), allow_double_clicks=self.allow_double_clicks, anchors={ 'left': 'left', 'right': 'right', 'top': 'top', 'bottom': 'top' }) self.join_focus_sets(item['button_element']) item_y_height += self.list_item_height else: break
def rebuild(self): """ Rebuild anything that might need rebuilding. """ border_and_shadow = self.border_width + self.shadow_width self.background_rect = pygame.Rect( (border_and_shadow + self.relative_rect.x, border_and_shadow + self.relative_rect.y), (self.relative_rect.width - (2 * border_and_shadow), self.relative_rect.height - (2 * border_and_shadow))) theming_parameters = { 'normal_bg': self.background_colour, 'normal_border': self.border_colour, 'disabled_bg': self.disabled_background_colour, 'disabled_border': self.disabled_border_colour, 'border_width': self.border_width, 'shadow_width': self.shadow_width, 'shape_corner_radius': self.shape_corner_radius } if self.shape == 'rectangle': self.drawable_shape = RectDrawableShape(self.rect, theming_parameters, ['normal', 'disabled'], self.ui_manager) elif self.shape == 'rounded_rectangle': self.drawable_shape = RoundedRectangleShape( self.rect, theming_parameters, ['normal', 'disabled'], self.ui_manager) self.set_image(self.drawable_shape.get_fresh_surface()) if self.button_container is None: self.button_container = UIContainer( self.background_rect, manager=self.ui_manager, container=self.ui_container, anchors=self.anchors, object_id='#vert_scrollbar_buttons_container', visible=self.visible) self.join_focus_sets(self.button_container) else: self.button_container.set_dimensions(self.background_rect.size) self.button_container.set_relative_position( self.background_rect.topleft) if self.enable_arrow_buttons: self.arrow_button_height = self.button_height if self.top_button is None: self.top_button = UIButton(pygame.Rect( (0, 0), (self.background_rect.width, self.arrow_button_height)), '▲', self.ui_manager, container=self.button_container, starting_height=1, parent_element=self, object_id=ObjectID( "#top_button", "@arrow_button"), anchors={ 'left': 'left', 'right': 'right', 'top': 'top', 'bottom': 'top' }) self.join_focus_sets(self.top_button) if self.bottom_button is None: self.bottom_button = UIButton(pygame.Rect( (0, -self.arrow_button_height), (self.background_rect.width, self.arrow_button_height)), '▼', self.ui_manager, container=self.button_container, starting_height=1, parent_element=self, object_id=ObjectID( "#bottom_button", "@arrow_button"), anchors={ 'left': 'left', 'right': 'right', 'top': 'bottom', 'bottom': 'bottom' }) self.join_focus_sets(self.bottom_button) else: self.arrow_button_height = 0 if self.top_button is not None: self.top_button.kill() self.top_button = None if self.bottom_button is not None: self.bottom_button.kill() self.bottom_button = None self.scrollable_height = self.background_rect.height - ( 2 * self.arrow_button_height) self.bottom_limit = self.scrollable_height scroll_bar_height = max( 5, int(self.scrollable_height * self.visible_percentage)) self.scroll_position = min(max(self.scroll_position, self.top_limit), self.bottom_limit - scroll_bar_height) x_pos = 0 y_pos = (self.scroll_position + self.arrow_button_height) self.sliding_rect_position = pygame.math.Vector2(x_pos, y_pos) if self.sliding_button is not None: self.sliding_button.set_relative_position( self.sliding_rect_position) self.sliding_button.set_dimensions( (self.background_rect.width, scroll_bar_height)) self.sliding_button.set_hold_range( (100, self.background_rect.height))
def rebuild(self): """ Rebuild anything that might need rebuilding. """ border_and_shadow = self.border_width + self.shadow_width self.background_rect = pygame.Rect( (border_and_shadow + self.relative_rect.x, border_and_shadow + self.relative_rect.y), (self.relative_rect.width - (2 * border_and_shadow), self.relative_rect.height - (2 * border_and_shadow))) theming_parameters = { 'normal_bg': self.background_colour, 'normal_border': self.border_colour, 'border_width': self.border_width, 'shadow_width': self.shadow_width, 'shape_corner_radius': self.shape_corner_radius } if self.shape == 'rectangle': self.drawable_shape = RectDrawableShape(self.rect, theming_parameters, ['normal'], self.ui_manager) elif self.shape == 'rounded_rectangle': self.drawable_shape = RoundedRectangleShape( self.rect, theming_parameters, ['normal'], self.ui_manager) self.set_image(self.drawable_shape.get_surface('normal')) if self.button_container is None: self.button_container = UIContainer( self.background_rect, manager=self.ui_manager, container=self.ui_container, anchors=self.anchors, object_id='#horiz_scrollbar_buttons_container') else: self.button_container.set_dimensions(self.background_rect.size) self.button_container.set_relative_position( self.background_rect.topleft) if self.enable_arrow_buttons: self.arrow_button_width = self.button_width if self.left_button is None: self.left_button = UIButton(pygame.Rect( (0, 0), (self.arrow_button_width, self.background_rect.height)), '◀', self.ui_manager, container=self.button_container, starting_height=1, parent_element=self, object_id="#left_button", anchors={ 'left': 'left', 'right': 'left', 'top': 'top', 'bottom': 'bottom' }) if self.right_button is None: self.right_button = UIButton(pygame.Rect( (-self.arrow_button_width, 0), (self.arrow_button_width, self.background_rect.height)), '▶', self.ui_manager, container=self.button_container, starting_height=1, parent_element=self, object_id="#right_button", anchors={ 'left': 'right', 'right': 'right', 'top': 'top', 'bottom': 'bottom' }) else: self.arrow_button_width = 0 if self.left_button is not None: self.left_button.kill() self.left_button = None if self.right_button is not None: self.right_button.kill() self.right_button = None self.scrollable_width = self.background_rect.width - ( 2 * self.arrow_button_width) self.right_limit = self.scrollable_width scroll_bar_width = max( 5, int(self.scrollable_width * self.visible_percentage)) self.scroll_position = min(max(self.scroll_position, self.left_limit), self.right_limit - scroll_bar_width) x_pos = (self.scroll_position + self.arrow_button_width) y_pos = 0 self.sliding_rect_position = pygame.math.Vector2(x_pos, y_pos) if self.sliding_button is not None: self.sliding_button.set_relative_position( self.sliding_rect_position) self.sliding_button.set_dimensions( (scroll_bar_width, self.background_rect.height)) self.sliding_button.set_hold_range( (self.background_rect.width, 100))
def __init__(self, rect: pygame.Rect, manager, container: Union[IContainerLikeInterface, None] = None, parent: Union[UIElement, None] = None, object_id: Union[str, None] = None, anchors: Union[Dict[str, str], None] = None, menu_bar_data: Dict[str, Dict[str, Union[Dict, str]]] = MENU_BAR_DATA_DICT): super().__init__(rect, manager, container, starting_height=1, layer_thickness=1, anchors=anchors) self._create_valid_ids(container, parent, object_id, 'menu_bar') self.menu_data = menu_bar_data self.bg_color = None self.border_color = None self.shape_type = 'rectangle' self.rgb_tuple = None # type: Union[Tuple[int, int, int], None] self.open_menu = None self._selected_menu = None self._close_opened_menu = False self.rebuild_from_changed_theme_data() self.container_rect = pygame.Rect( self.relative_rect.left + (self.shadow_width + self.border_width), self.relative_rect.top + (self.shadow_width + self.border_width), self.relative_rect.width - 2 * (self.shadow_width + self.border_width), self.relative_rect.height - 2 * (self.shadow_width + self.border_width)) self.menu_bar_container = UIContainer(self.container_rect, manager, starting_height=1, parent_element=self, object_id='#menu_bar_container') # menü butonları için for loop current_y_pos = 0 for menu_key, menu_item in self.menu_data.items(): if menu_key == '#icon': icon_surf = pygame.image.load( os.path.join('litevision', 'res', 'image_examples', 'icon.png')).convert_alpha() self.icon = UIImage( pygame.Rect( (0 + GUI_OFFSET_VALUE + ((48 - 32) // 2), current_y_pos + GUI_OFFSET_VALUE), (32, 32)), icon_surf, self.ui_manager, self.menu_bar_container, self, menu_key) current_y_pos += (48 + GUI_OFFSET_VALUE) continue elif menu_key == '#empty_1' or menu_key == '#empty_2': empty_surf = pygame.Surface((48, 48), pygame.SRCALPHA, masks=pygame.Color('#2F4F4F')) UIImage( pygame.Rect((0 + GUI_OFFSET_VALUE, current_y_pos), (48, 48)), empty_surf, self.ui_manager, self.menu_bar_container, self, menu_key) current_y_pos += (48 + GUI_OFFSET_VALUE) continue elif menu_key == '#start_pause': sp_surf = pygame.Surface((48, 48), pygame.SRCALPHA, masks=pygame.Color('#2F4F4F')) sp_icon = pygame.image.load( os.path.join('litevision', 'res', 'image_examples', 'start_icon', 'start.png')).convert_alpha() sp_surf.blit(sp_icon, (0, 0)) self.start_button = UIImage( pygame.Rect((0 + GUI_OFFSET_VALUE, current_y_pos), (48, 48)), sp_surf, self.ui_manager, self.menu_bar_container, self, '#start_pause') current_y_pos += (48 + GUI_OFFSET_VALUE) continue elif menu_key == '#rgb_button': rgb_surf = pygame.Surface((48, 48), pygame.SRCALPHA, masks=pygame.Color('#2F4F4F')) rgb_icon = pygame.image.load( os.path.join('litevision', 'res', 'image_examples', 'rgb.png')).convert_alpha() rgb_surf.blit(rgb_icon, (0, 0)) self.rgb_button = UIImage( pygame.Rect((0 + GUI_OFFSET_VALUE, current_y_pos), (48, 48)), rgb_surf, self.ui_manager, self.menu_bar_container, self, '#rgb_button') current_y_pos += (48 + GUI_OFFSET_VALUE) continue UIButton(pygame.Rect((0 + GUI_OFFSET_VALUE, current_y_pos), (48, 48)), menu_item['display_name'], self.ui_manager, self.menu_bar_container, object_id=menu_key, parent_element=self) current_y_pos += (48 + GUI_OFFSET_VALUE)