[__init__.py] Implemented the first part of show_selection for vertical scrolling
Views for all selections [with vertical scrolling] have been implemented, where enough items come after the current selection to fill all lines available for menu items. The other parts remains a ToDo for now
This commit is contained in:
parent
ecad7e2403
commit
c5b66e707b
87
__init__.py
87
__init__.py
@ -60,9 +60,18 @@ class lcdMenu:
|
||||
selection_name = self.menu_items[self.current_selection][0]
|
||||
lw = self.lcd.num_columns
|
||||
|
||||
# fill the custom character fields in the displays memory
|
||||
self.lcd.custom_char(0, bytearray([0x04,0x0A,0x11,0x00,0x00,0x00,0x00,0x00])) # arrow up
|
||||
self.lcd.custom_char(1, bytearray([0x00,0x00,0x00,0x00,0x00,0x11,0x0A,0x04])) # arrow down
|
||||
self.lcd.custom_char(2, bytearray([0x04,0x0A,0x11,0x00,0x00,0x11,0x0A,0x04])) # arrow up and down (variant 5 from above)
|
||||
self.lcd.custom_char(3, bytearray([0x11,0x0A,0x04,0x00,0x00,0x04,0x0A,0x11])) # no options (variant 3 from above)
|
||||
self.lcd.custom_char(4, bytearray([0x08,0x08,0x08,0x0F,0x08,0x08,0x08,0x08])) # line with a fork (to show the current selection - h scrolling)
|
||||
self.lcd.custom_char(5, bytearray([0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08])) # line without a fork (to show unselected items - h scrolling)
|
||||
self.lcd.custom_char(6, bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x15,0x00])) # three dots in a row
|
||||
|
||||
# now show it off!
|
||||
# Horizontal scrolling:
|
||||
if self.scroll_direction:
|
||||
if self.scroll_direction:
|
||||
self.lcd.move_to(0,0)
|
||||
if self.lcd.num_lines == 4:
|
||||
self.lcd.putstr(f"{self.fill_char*lw}{' '*lw*2}{self.fill_char*lw}") # fill the first and last line with 'fill_char's
|
||||
@ -71,8 +80,80 @@ class lcdMenu:
|
||||
self.lcd.putstr(f"<{selection_name[0:lw-2].center(lw-2)}>") # the current selected menu item's name
|
||||
# Vertical scrolling:
|
||||
else:
|
||||
pass # TODO!
|
||||
print(self.current_selection)
|
||||
lines_for_display = self.lcd.num_lines
|
||||
items_before_selection = self.current_selection # e.g. if current selection is the second -> 1; one item is before this
|
||||
items_after_selection = len(self.menu_items) - self.current_selection - 1
|
||||
self.lcd.move_to(0,0)
|
||||
if not self.hide_menu_name:
|
||||
self.lcd.putstr(f"[{self.name[0:lw-2].center(lw-2)}]") # print the menu name surrounded by sqare brackets []
|
||||
lines_for_display -= 1 # decrease the amount of lines available for displaying menu items by 1 (as it's used for the menu name)
|
||||
|
||||
# now we want to display the selections
|
||||
# where the currently selected item should be the uppermost if possible
|
||||
# only at the end of the item list, the current item has to be in a lower line...
|
||||
# ... to avoid emtpy lines at the end as this would seem unprofessional/unclean to me
|
||||
# but it adds an noticeable amount of extra work / a complex algorithm
|
||||
if items_after_selection < (lines_for_display - 1): # if there aren't enough items to fill the display after the current selection
|
||||
# maybe the following could be done with a crazy math formula - but I want to keep it simpler!
|
||||
# as there aren't enough menu items after the current selection to fill the display, we have to...
|
||||
# ... calculate where to place the current selection, how many items there are before it and how many after it
|
||||
"""
|
||||
if lines_for_display > len(self.menu_items): # if it is because of an overall small number of menu items (less than we can display)
|
||||
for i in range(len(self.menu_items)):
|
||||
if i < self.current_selection:
|
||||
self.lcd.putstr(chr(5)+" "+self.menu_items[i][0][0:lw-4])
|
||||
self.lcd.putstr(" "*(lw-4-len(self.menu_items[i][0][0:lw-4])))
|
||||
if len(self.menu_items) <= 1:
|
||||
self.lcd.putstr(" " + chr(3)) # no options icon (as there's only one menu item!)
|
||||
elif self.current_selection == 0 and not self.cycle:
|
||||
self.lcd.putstr(" "+chr(1))
|
||||
elif self.current_selection == (len(self.menu_items)-1) and not self.cycle:
|
||||
self.lcd.putstr(" "+chr(0))
|
||||
else:
|
||||
self.lcd.putstr(" "+chr(2))
|
||||
elif i == self.current_selection:
|
||||
self.lcd.putstr(chr(5)+" "+self.menu_items[i][0][0:lw-4])
|
||||
self.lcd.putstr(" "*(lw-4-len(self.menu_items[i][0][0:lw-4])))
|
||||
elif i > self.current_selection:
|
||||
|
||||
|
||||
print("Im here!")
|
||||
else: # if it is because we reached the end of a (possibly) long menu list -> we have enough items to fill all the available lines
|
||||
print("Else here!")
|
||||
"""
|
||||
print("ToDo!")
|
||||
else: # there are enough items to fill the display after the current selection
|
||||
# the first line
|
||||
self.lcd.putstr(f"{chr(4)} {selection_name[0:lw-4]}")
|
||||
self.lcd.putstr(" " * ((lw-4)-len(selection_name[0:lw-4]))) # fill the line with spaces up to 2 before the end of the line
|
||||
|
||||
if len(self.menu_items) <= 1:
|
||||
self.lcd.putstr(" " + chr(3)) # no options icon (as there's only one menu item!)
|
||||
elif lines_for_display == 1: # if there is exactly one line to display the menu entries
|
||||
if self.current_selection == 0 and not self.cycle:
|
||||
self.lcd.putstr(" "+chr(1))
|
||||
elif self.current_selection == (len(self.menu_items)-1) and not self.cycle:
|
||||
self.lcd.putstr(" "+chr(0))
|
||||
else:
|
||||
self.lcd.putstr(" "+chr(2))
|
||||
elif self.current_selection == 0 and not self.cycle: # first item selected and no cycling
|
||||
self.lcd.putstr(" ") # leave it spacy
|
||||
else:
|
||||
self.lcd.putstr(" " + chr(0))
|
||||
|
||||
# the other lines... (if existing!)
|
||||
for i in range(lines_for_display-1):
|
||||
self.lcd.putstr(f"{chr(5)} {self.menu_items[self.current_selection+i+1][0][0:lw-4]}")
|
||||
self.lcd.putstr(" " * ((lw-4)-len(self.menu_items[self.current_selection+i+1][0][0:lw-4]))) # fit the line
|
||||
# check if it's the last line being drawn...
|
||||
if (i+1) == (lines_for_display-1):
|
||||
if self.current_selection == (len(self.menu_items)-1) and not self.cycle: # last item selected and no cycling
|
||||
self.lcd.putstr(" ")
|
||||
else:
|
||||
self.lcd.putstr(" " + chr(1))
|
||||
else: # else: if it's not the last line, leave the last two columns of the line empty
|
||||
self.lcd.putstr(" ")
|
||||
|
||||
|
||||
|
||||
def previous_selection(self):
|
||||
|
Loading…
Reference in New Issue
Block a user