@@ -79,23 +79,40 @@ bool FileBrowser::process(InputEvents* events)
79
79
80
80
int cardY = currentCard->yAbs ;
81
81
82
- if (!touchMode) {
83
- // keep the cursor on screen if using buttons
84
- if (highlighted <= 3 ) {
85
- this ->y = 0 ;
86
- updateUI |= true ;
87
- }
88
- else
89
- {
90
- if (cardY < 10 ) {
91
- this ->y += currentCard->height ;
92
- updateUI |= true ;
93
- }
94
- if (cardY > SCREEN_HEIGHT - (currentCard->height + 10 )) {
95
- this ->y -= currentCard->height ;
96
- updateUI |= true ;
97
- }
98
- }
82
+ // Below code is lifted from HBAS's AppList.cpp
83
+ // TODO: consolidate into Chesto's ListElement
84
+ if (!touchMode && this ->elements .size () > this ->highlighted && this ->highlighted >= 0 && this ->elements [this ->highlighted ])
85
+ {
86
+ // if our highlighted position is large enough, force scroll the screen so that our cursor stays on screen
87
+ Element* curTile = this ->elements [this ->highlighted ];
88
+
89
+ // the y-position of the currently highlighted tile, precisely on them screen (accounting for scroll)
90
+ // this means that if it's < 0 or > SCREEN_HEIGHT then it's not visible
91
+ int normalizedY = curTile->y + this ->y ;
92
+
93
+ // if we're FAR out of range upwards, speed up the scroll wheel (additive) to get back in range quicker
94
+ if (normalizedY < -200 )
95
+ events->wheelScroll += 0.15 ;
96
+
97
+ // far out of range, for bottom of screen
98
+ else if (normalizedY > SCREEN_HEIGHT - curTile->height + 200 )
99
+ events->wheelScroll -= 0.15 ;
100
+
101
+ // if we're slightly out of range above, recenter at the top row slowly
102
+ else if (normalizedY < -100 )
103
+ events->wheelScroll = 1 ;
104
+
105
+ // special case, scroll when we're on the bottom row of the top of the not-yet-scrolled screen
106
+ else if (this ->y == 0 && normalizedY > SCREEN_HEIGHT/2 )
107
+ events->wheelScroll -= 0.5 ;
108
+
109
+ // if we're out of range below, recenter at bottom row
110
+ else if (normalizedY > SCREEN_HEIGHT - curTile->height + 100 )
111
+ events->wheelScroll = -1 ;
112
+
113
+ // if the card is this close to the top, just set it the list offset to 0 to scroll up to the top
114
+ else if (this ->y != 0 && this ->highlighted < cardsPerRow)
115
+ events->wheelScroll = 1 ;
99
116
100
117
if (this ->elements [this ->highlighted ] && this ->elements [this ->highlighted ]->elasticCounter == NO_HIGHLIGHT)
101
118
{
@@ -255,18 +272,7 @@ void FileBrowser::listfiles()
255
272
// new folder, file, and exit buttons
256
273
Container* con = new Container (ROW_LAYOUT, 10 );
257
274
258
- auto quitaction = [mainDisplay](){
259
- #ifdef __WIIU__
260
- // will exit via procui loop in RootDisplay
261
- SYSLaunchMenu ();
262
- #else
263
- mainDisplay->exitRequested = true ;
264
- mainDisplay->isRunning = false ;
265
- #endif
266
- };
267
-
268
- con->add ((new Button (" Exit" , SELECT_BUTTON, true ))->setAction (quitaction));
269
- mainDisplay->events ->quitaction = quitaction;
275
+ con->add ((new Button (" Exit" , SELECT_BUTTON, true ))->setAction (mainDisplay->events ->quitaction ));
270
276
271
277
con->add ((new Button (" New Folder" , X_BUTTON, true ))->setAction ([this , mainDisplay](){
272
278
std::function<void (const char *)> createFunc = [this ](const char * name){
0 commit comments