From bfc849dbc4ae57690f9c44bd6a37d838a6447fa0 Mon Sep 17 00:00:00 2001 From: hi80482 <66435094+hi80482@users.noreply.github.com> Date: Wed, 29 Jul 2020 21:48:11 +0800 Subject: [PATCH] add loop scroll --- sys.py/UI/Emulator/rom_list_page.py | 34 +++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/sys.py/UI/Emulator/rom_list_page.py b/sys.py/UI/Emulator/rom_list_page.py index 31d596d..5d9b75f 100644 --- a/sys.py/UI/Emulator/rom_list_page.py +++ b/sys.py/UI/Emulator/rom_list_page.py @@ -115,6 +115,8 @@ class RomListPage(Page): _RomSoConfirmDownloadPage = None _Backspace = False + + _ItemsPerPage = 6 def __init__(self): Page.__init__(self) @@ -294,7 +296,8 @@ class RomListPage(Page): self._RomSoConfirmDownloadPage = rom_so_confirm_page def ScrollUp(self): - if len(self._MyList) == 0: + # if len(self._MyList) == 0: + if len(self._MyList) <= 1: return tmp = self._PsIndex @@ -302,7 +305,7 @@ class RomListPage(Page): if self._PsIndex < 0: # self._PsIndex = 0 - self._PsIndex = len(self._MyList) -1 # to end + self._PsIndex = len(self._MyList) - 1 # to end # dy = tmp - self._PsIndex dy = abs(tmp - self._PsIndex) @@ -313,15 +316,21 @@ class RomListPage(Page): self._Scrolled += dy # loop scroll, to end - # dy - 5: 6 items on screen, 6 - 1 = 5 if self._PsIndex == len(self._MyList) - 1: + # check items per page + if len(self._MyList) < self._ItemsPerPage: + self._ItemsPerPage = len(self._MyList) + self._ItemsPerPage -= 1 # not include current item for i in range(0, len(self._MyList)): - self._MyList[i]._PosY -= self._MyList[i]._Height * (dy - 5) + self._MyList[i]._PosY -= self._MyList[i]._Height * (dy - self._ItemsPerPage) self._Scrolled -= dy + self._ItemsPerPage = 6 # reset to 6 def ScrollDown(self): - if len(self._MyList) == 0: + # if len(self._MyList) == 0: + if len(self._MyList) <= 1: return + tmp = self._PsIndex self._PsIndex +=self._ScrollStep @@ -338,12 +347,16 @@ class RomListPage(Page): self._Scrolled -= dy # loop scroll, to first - # dy - 5: 6 items on screen, 6 - 1 = 5 if self._PsIndex == 0: + # check items per page + if len(self._MyList) < self._ItemsPerPage: + self._ItemsPerPage = len(self._MyList) + self._ItemsPerPage -= 1 # not include current item for i in range(0, len(self._MyList)): - self._MyList[i]._PosY += self._MyList[i]._Height * (dy - 5) + self._MyList[i]._PosY += self._MyList[i]._Height * (dy - self._ItemsPerPage) self._Scrolled += dy - + self._ItemsPerPage = 6 # reset to 6 + def SyncScroll(self): ## if self._Scrolled == 0: @@ -452,7 +465,10 @@ class RomListPage(Page): cur_time = time.time() if cur_time - self._Screen._LastKeyDown > 0.3: - self._ScrollStep = 1 + self._ScrollStep = 1 + + if len(self._MyList) < self._ItemsPerPage: + self._ScrollStep = 1 def KeyDown(self,event):