Fix scroll acceleration wrap-around

This commit is contained in:
Willy-JL
2023-06-29 03:39:09 +02:00
parent 788b395be2
commit 0c3a8a3ca1
3 changed files with 48 additions and 2 deletions

View File

@@ -148,7 +148,7 @@ typedef struct {
bool hide_ext;
size_t scroll_counter;
uint32_t button_held_for_ticks;
int32_t button_held_for_ticks;
} FileBrowserModel;
static const Icon* BrowserItemIcons[] = {
@@ -670,11 +670,20 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
} else {
scroll_speed = model->button_held_for_ticks > 9 ? 5 : 3;
}
} else if(model->button_held_for_ticks < 0) {
scroll_speed = 0;
}
if(event->key == InputKeyUp) {
if(model->item_idx < scroll_speed) {
scroll_speed = model->item_idx;
if(scroll_speed == 0) {
if(model->button_held_for_ticks > 0) {
model->button_held_for_ticks = -1;
} else {
scroll_speed = 1;
}
}
}
model->item_idx =
@@ -690,11 +699,21 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
}
model->scroll_counter = 0;
if(model->button_held_for_ticks < -1) {
model->button_held_for_ticks = 0;
}
model->button_held_for_ticks += 1;
} else if(event->key == InputKeyDown) {
int32_t count = model->item_cnt;
if(model->item_idx + scroll_speed >= count) {
scroll_speed = count - model->item_idx - 1;
if(scroll_speed == 0) {
if(model->button_held_for_ticks > 0) {
model->button_held_for_ticks = -1;
} else {
scroll_speed = 1;
}
}
}
model->item_idx = (model->item_idx + scroll_speed) % model->item_cnt;
@@ -709,6 +728,9 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
}
model->scroll_counter = 0;
if(model->button_held_for_ticks < -1) {
model->button_held_for_ticks = 0;
}
model->button_held_for_ticks += 1;
}
},