Skip to content

Commit

Permalink
Add a new method to hide arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
anxuae committed Sep 17, 2022
1 parent 19eb24f commit 9bcbed6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ Several information can be retrieved from the slider:
# Set the current index.
slider.set_index(2)
# Hide left and right arrows
slider.set_arrows_visible(False)
Run examples
Expand Down
15 changes: 15 additions & 0 deletions pygame_imslider/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(self, size, stype=STYPE_SLIDE, per_page=1, per_move=0, focus=True,
self.renderer = renderer
self.background = Background(self.renderer)

self.show_arrows = True
self.arrows = (Arrow(osp.join(HERE, "left.png"), self.renderer, pygame.K_LEFT),
Arrow(osp.join(HERE, "right.png"), self.renderer, pygame.K_RIGHT))
self.pressed_repeat_time = 0.4
Expand Down Expand Up @@ -237,6 +238,17 @@ def set_size(self, width, height):
# sprites without using "dirty mechanism"
self.sprites.set_clip(self.background.rect)

def set_arrows_visible(self, show):
"""Display/hide right and left arrows.
:param show: arrows status
:type show: bool
"""
if show != self.show_arrows:
self.show_arrows = show
for arrow in self.arrows:
arrow.visible = int(show)

def draw(self, surface=None, force=False):
"""Draw the image slider.
Expand Down Expand Up @@ -341,6 +353,9 @@ def update_arrows(self):
"""Update arrows visibility. The visibility is changed only if necessary
to avoid unwelcome surface update.
"""
if not self.show_arrows:
return

if len(self.layout.slides) == 1\
or (len(self.layout.slides) <= self.per_page and self.per_move >= self.per_page):
# Only one page
Expand Down

0 comments on commit 9bcbed6

Please sign in to comment.