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

Grid menu #123

Merged
merged 50 commits into from Dec 23, 2018
Merged

Grid menu #123

merged 50 commits into from Dec 23, 2018

Conversation

derivmug
Copy link
Collaborator

This branch adds a 3x3 grid menu.

Copy link
Member

@CRImier CRImier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good, but would be better off based on BaseListBackgroundableUIElement (less code duplication and more features).

ui/grid_menu.py Outdated
new_x = self.selected_option['x'] + x_mod
new_y = self.selected_option['y'] + y_mod

if new_x >= 1 and new_x <= 3:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 is a magic number in this and next rows, care to replace with a const?

Suggested change
if new_x >= 1 and new_x <= 3:
if new_x >= 1 and new_x <= self.GRID_WIDTH:
if new_y >= 1 and new_y <= self.GRID_HEIGHT:

ui/grid_menu.py Outdated
def refresh(self):
self.draw_menu()

def _move_cursor(self, x_mod, y_mod):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lacks navigation when pressing RIGHT on the last column (or LEFT on first). Feel free to borrow the code from the calendar =)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or, if based on BaseListBackgroundableUIElement, its nav functions will work (but move_up/down will need to be defined as move_left/right and proper move_up/down will need to be added)

ui/grid_menu.py Outdated

class GridMenu(BaseUIElement):

GRID_WIDTH = 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be able to define it as an init() argument? seems like a good base UI element that we could later move, say, DatePicker to, I will think about it more.

ui/grid_menu.py Outdated
from base_ui import BaseUIElement
from canvas import Canvas

class GridMenu(BaseUIElement):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider defining your own validate_contents(self, contents). If someone passes contents that isn't a widthxheight array of entries, I imagine it can break in subtle ways - better warn the developer about it first =D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or, if you base it off BaseListBackgroundableUIElement, its validate_contents will be more than suitable

@CRImier
Copy link
Member

CRImier commented Oct 22, 2018

<CRImier> derivmug: what do you think about moving GridMenu to BaseListBackgroundableUIElement?
<derivmug[m]> Ok, what would I need to change/add
<CRImier> well, it's a ListUIElement
<CRImier> it has menu navigation primitives already in
[...]
<CRImier> as well as useful stuff for working with "contents"
<CRImier> come to think of it, we don't really need to pass a X*Y grid as "contents"
<CRImier> merely rendering it all as a list (and overriding move_up/down/left/right ofc)
<CRImier> should do
<CRImier> like you have with calendar, for example
<CRImier> actually
<CRImier> don't really need to redefine move_up/down/left/right?
<CRImier> oh wait, you do
<CRImier> move_left/right would work as move_up/down currently do
<CRImier> in list UI elements
<CRImier> and move_up/down would skip to next/previous row

@codecov
Copy link

codecov bot commented Oct 22, 2018

Codecov Report

Merging #123 into devel will increase coverage by 0.07%.
The diff coverage is 34.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##            devel     #123      +/-   ##
==========================================
+ Coverage   40.56%   40.64%   +0.07%     
==========================================
  Files         248      251       +3     
  Lines       19950    20276     +326     
==========================================
+ Hits         8093     8241     +148     
- Misses      11857    12035     +178
Impacted Files Coverage Δ
apps/hardware_apps/zp_test/key_test.py 0% <ø> (ø)
emulator.py 3.84% <0%> (-0.03%) ⬇️
apps/hardware_apps/zp_test/main.py 0% <0%> (ø)
ui/canvas.py 86.54% <100%> (+0.08%) ⬆️
ui/__init__.py 100% <100%> (ø) ⬆️
ui/tests/test_base_list_ui.py 75% <100%> (+2.5%) ⬆️
ui/base_list_ui.py 82.1% <100%> (+5.41%) ⬆️
apps/example_apps/sandbox/main.py 40.9% <16.66%> (-22.73%) ⬇️
ui/tests/test_grid_menu.py 32.19% <32.19%> (ø)
apps/example_apps/grid_menu_test/main.py 60% <60%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bac028e...c4021ba. Read the comment docs.

@CRImier
Copy link
Member

CRImier commented Nov 27, 2018

Hi! Thank you for the work, currently building the main menu from it. Some feedback:

  • We do already have plenty of pointer handling code. So, redefining pointer to pretty much be x_index doesn't make a lot of sense and will introduce differences from code that we already have that relies on pointer to be an index in contents, and isn't even necessary.
  • There's some code and variables in the GridMenu that actually ought to be in GridView because it's only relevant when we display the menu. I.e. we only actually care about y_index when we draw the menu on the screen.

Working further - got an idea in my head of how it all could work, hope you like how it turns out =)

@CRImier
Copy link
Member

CRImier commented Nov 27, 2018

Also, do check how other UI elements work, it doesn't make sense to break conventions - i.e. making contents into a keyword argument when Menu, a parent UI element, has it as the first positional argument.

…own, making sure they don't refresh more than once per call
…a view mixin. WIP - out-of-screen entry navigation doesn't yet work properly, might need to adjust first_displayed_entry better.
…emoving it out of pyavrdude because can't test it yet
@CRImier CRImier merged commit c4021ba into devel Dec 23, 2018
@CRImier CRImier deleted the grid-menu branch December 23, 2018 15:25
@CRImier
Copy link
Member

CRImier commented Dec 23, 2018

@derivmug thank you!

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.

None yet

2 participants