Skip to content

Commit 323bf5d

Browse files
authored
Merge pull request #76 from The-Debarghya/bug-75-zerodivisionerror
handle ZeroDivisionError
2 parents aa66d0f + f2b1656 commit 323bf5d

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

adafruit_displayio_layout/widgets/switch_round.py

+24-15
Original file line numberDiff line numberDiff line change
@@ -754,21 +754,30 @@ def _animate_switch(self):
754754
# Determines the direction of movement, depending upon if the
755755
# switch is going from on->off or off->on
756756

757-
# constrain the elapsed time
758-
elapsed_time = time.monotonic() - start_time
759-
if elapsed_time > self._animation_time:
760-
elapsed_time = self._animation_time
761-
762-
if self._value:
763-
position = (
764-
1 - (elapsed_time) / self._animation_time
765-
) # fraction from 0 to 1
766-
else:
767-
position = (elapsed_time) / self._animation_time # fraction from 0 to 1
768-
769-
# Update the moving elements based on the current position
770-
# apply the "easing" function to the requested position to adjust motion
771-
self._draw_position(easing(position)) # update the switch position
757+
if self._animation_time == 0:
758+
if not self._value:
759+
position = 1
760+
self._draw_position(1)
761+
else:
762+
position = 0
763+
self._draw_position(0)
764+
else: # animate over time
765+
# constrain the elapsed time
766+
elapsed_time = time.monotonic() - start_time
767+
if elapsed_time > self._animation_time:
768+
elapsed_time = self._animation_time
769+
770+
if self._value:
771+
position = (
772+
1 - (elapsed_time) / self._animation_time
773+
) # fraction from 0 to 1
774+
else:
775+
# fraction from 0 to 1
776+
position = (elapsed_time) / self._animation_time
777+
778+
# Update the moving elements based on the current position
779+
# apply the "easing" function to the requested position to adjust motion
780+
self._draw_position(easing(position)) # update the switch position
772781

773782
# update the switch value once the motion is complete
774783
if (position >= 1) and not self._value:

0 commit comments

Comments
 (0)