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

Add PAGE_UP, PAGE_DOWN, KEY_HOME, and KEY_END support in ScrollMenu #44

Closed
pkazmier opened this issue Apr 5, 2020 · 5 comments
Closed
Labels
Feature Request Add for a new feature request Good first issue Good for newcomers Help wanted Extra attention is needed Widgets Add for issues having to do with widgets
Milestone

Comments

@pkazmier
Copy link

pkazmier commented Apr 5, 2020

ScrollMenu only supports moving up and down by a single line at a time. When a scroll menu contains hundreds and hundreds of items, navigating in this manner is too slow. It would be great to add support for PAGE_UP, PAGE_DOWN, KEY_HOME, and KEY_END.

@pkazmier pkazmier added the Feature Request Add for a new feature request label Apr 5, 2020
@jwlodek
Copy link
Owner

jwlodek commented Apr 5, 2020

I think this would be worthwhile. I guess pageup, pagedown can move a set number of positions, and home/end moves to the top or bottom of the menu

@jwlodek jwlodek added Good first issue Good for newcomers Widgets Add for issues having to do with widgets labels Apr 6, 2020
@jwlodek jwlodek added this to the v0.1.1 milestone Apr 6, 2020
@pkazmier
Copy link
Author

pkazmier commented Apr 8, 2020

No time to submit a PR, but here are the implementations I used for page up and page down in my custom ScrollMenu widget:

    def page_up(self):
        shift_by = self.height - (2 * self.pady) - 3

        new_top_view = self.top_view - shift_by
        new_selected_item = self.selected_item - shift_by

        self.top_view = 0 if new_top_view < 0 else new_top_view
        self.selected_item = 0 if new_selected_item < 0 else new_selected_item

    def page_down(self):
        shift_by = self.height - (2 * self.pady) - 3
        last_item_idx = len(self.view_items) - 1

        new_top_view = self.top_view + shift_by
        new_selected_item = self.selected_item + shift_by

        self.top_view = (
            new_top_view - shift_by if new_top_view > last_item_idx else new_top_view
        )
        self.selected_item = (
            last_item_idx if new_selected_item > last_item_idx else new_selected_item
        )

@jwlodek jwlodek added the Help wanted Extra attention is needed label Apr 12, 2020
@jwlodek
Copy link
Owner

jwlodek commented Apr 18, 2020

This feature has been added to the v0.1.1-develop branch, and seems to work OK on my end. Unit tests still need to be expanded to account for this change.

@jwlodek jwlodek mentioned this issue Apr 22, 2020
3 tasks
@wdog
Copy link
Contributor

wdog commented Apr 30, 2020

I've implemented directly on the custom ScrollMenu PAGE_UP PAGE_DOWN this way

    def _handle_key_press(self, key_pressed):
        super()._handle_key_press(key_pressed)

        if key_pressed == curses.KEY_NPAGE:
            # if next jump is on the groud
            if self._selected_item + self._height - 2 < len(self._view_items):
                self._selected_item += self._height - 2
                self._top_view = self._selected_item
               
        if key_pressed == curses.KEY_PPAGE:
            self._selected_item -= self._height - 2
            self._top_view = self._selected_item
            if self._selected_item < 0:
                self._selected_item = 0

maybe helps mybe not 🎮

@jwlodek
Copy link
Owner

jwlodek commented May 24, 2020

Closing, included in new py_cui release

@jwlodek jwlodek closed this as completed May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Add for a new feature request Good first issue Good for newcomers Help wanted Extra attention is needed Widgets Add for issues having to do with widgets
Projects
None yet
Development

No branches or pull requests

3 participants