Skip to content

Commit

Permalink
fix scrolling_container scrollbar dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
MyreMylar committed Apr 14, 2024
1 parent 3c29557 commit c1e3e57
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pygame_gui/elements/ui_scrolling_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self,
# scroll bars so that it resizes automatically as the scroll bars are added and "removed".

# this contains the scroll bars and the 'view' container
self._root_container = UIContainer(relative_rect=relative_rect,
self._root_container = UIContainer(relative_rect=self.relative_rect,
manager=manager,
starting_height=starting_height,
container=container,
Expand All @@ -106,7 +106,7 @@ def __init__(self,
self.vert_scroll_bar = None
if self.allow_scroll_y:

scroll_bar_rect = pygame.Rect(-20, 0, 20, relative_rect.height)
scroll_bar_rect = pygame.Rect(-20, 0, 20, self.relative_rect.height)
self.vert_scroll_bar = UIVerticalScrollBar(relative_rect=scroll_bar_rect,
visible_percentage=1.0,
manager=self.ui_manager,
Expand All @@ -117,15 +117,15 @@ def __init__(self,
'top': 'top',
'bottom': 'bottom'})

self.vert_scroll_bar.set_dimensions((0, relative_rect.height)) # TODO: Remove these when anchoring is fixed
self.vert_scroll_bar.set_dimensions((0, self.relative_rect.height)) # TODO: Remove these when anchoring is fixed
self.vert_scroll_bar.set_relative_position((0, 0)) # Without this, they look off-centered
self.join_focus_sets(self.vert_scroll_bar)

view_container_anchors['right_target'] = self.vert_scroll_bar

self.horiz_scroll_bar = None
if self.allow_scroll_x:
scroll_bar_rect = pygame.Rect(0, -20, relative_rect.width, 20)
scroll_bar_rect = pygame.Rect(0, -20, self.relative_rect.width, 20)
self.horiz_scroll_bar = UIHorizontalScrollBar(relative_rect=scroll_bar_rect,
visible_percentage=1.0,
manager=self.ui_manager,
Expand All @@ -136,15 +136,15 @@ def __init__(self,
'top': 'bottom',
'bottom': 'bottom'})

self.horiz_scroll_bar.set_dimensions((relative_rect.width, 0))
self.horiz_scroll_bar.set_dimensions((self.relative_rect.width, 0))
self.horiz_scroll_bar.set_relative_position((0, 0))
self.join_focus_sets(self.horiz_scroll_bar)

view_container_anchors['bottom_target'] = self.horiz_scroll_bar

# 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)
view_rect = pygame.Rect(0, 0, self.relative_rect.width, self.relative_rect.height)
self._view_container = UIContainer(relative_rect=view_rect,
manager=manager,
starting_height=1,
Expand All @@ -158,7 +158,7 @@ def __init__(self,
# 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)
scrollable_rect = pygame.Rect(0, 0, self.relative_rect.width, self.relative_rect.height)
scrollable_anchors = {'left': 'left',
'right': 'left',
'top': 'top',
Expand Down Expand Up @@ -415,9 +415,7 @@ def _sort_out_element_container_scroll_bars(self):
self.vert_scroll_bar.set_visible_percentage(vis_percent)
self.vert_scroll_bar.set_relative_position((-self.scroll_bar_width, 0))

# This is important as horiz scroll bar's dimensions are evaluated after. If horizontal scrollbar is not
# needed, then scroll bar height is 0.
height = self._view_container.rect.height - self.scroll_bar_height
height = self._view_container.rect.height
self.vert_scroll_bar.set_dimensions((self.scroll_bar_width,
height))
else:
Expand Down

0 comments on commit c1e3e57

Please sign in to comment.