Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update launcher.py for infinite scrolling #23

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

jsh97
Copy link
Contributor

@jsh97 jsh97 commented May 19, 2023

changed the logic, so that you start again on the top page if you scroll further down on the last page.

changed the logic, so that you start again on the top page if you scroll further down on the last page.
@Gadgetoid
Copy link
Member

You should be able to use:

  if pin == badger2040.BUTTON_UP:
        state["page"] = (state["page"] - 1) % MAX_PAGE
        render()
    if pin == badger2040.BUTTON_DOWN:
        state["page"] = (state["page"] + 1) % MAX_PAGE
        render()

Which will keep state["page"] between 0 and MAX_PAGE, since:

>>> math.fmod(-1, 2)
-1.0
>>> -1 % 2
1

(because Python is weird, yay)

Your approach works because Python's list support negative indices and ranges:

>>> list("abcdef")[-1]
f

But having -1 in the saved launcher state would be a little weird!

@Gadgetoid Gadgetoid merged commit e40a941 into pimoroni:main Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants