Skip to content

Commit bbae137

Browse files
committed
minor change
1 parent 0634dfd commit bbae137

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

adafruit_displayio_layout/widgets/switch_round.py

+22-17
Original file line numberDiff line numberDiff line change
@@ -755,23 +755,28 @@ def _animate_switch(self):
755755
# switch is going from on->off or off->on
756756

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

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

0 commit comments

Comments
 (0)