fix: small QoL: return to the last selected menu location (#1629)

## Summary

* **What is the goal of this PR?** Small UX improvement to the Home
screen by preserving the last selected cursor position when returning to
it.

It supersedes #985 and #1103, which are both significantly outdated and
hundreds of commits behind master.

---

### AI Usage

Did you use AI tools to help write this code? _**< YES >**_
This commit is contained in:
Uri Tauber
2026-05-19 08:41:39 -05:00
committed by GitHub
parent dac7fef49d
commit 08461c08e7
7 changed files with 77 additions and 29 deletions
+30 -2
View File
@@ -28,6 +28,33 @@ class HomeActivity final : public Activity {
int coverRectW = 0;
int coverRectH = 0;
std::vector<RecentBook> recentBooks;
const HomeMenuItem initialMenuItem;
// Convert HomeMenuItem to menu index (used in onEnter)
static int menuItemToIndex(HomeMenuItem item, bool hasOpdsUrl) {
int i = 0;
if (item == HomeMenuItem::FILE_BROWSER) return i;
++i;
if (item == HomeMenuItem::RECENTS) return i;
++i;
if (item == HomeMenuItem::OPDS_BROWSER) return hasOpdsUrl ? i : 0;
if (hasOpdsUrl) ++i;
if (item == HomeMenuItem::FILE_TRANSFER) return i;
++i;
if (item == HomeMenuItem::SETTINGS_MENU) return i;
return 0;
}
// Convert menu index to HomeMenuItem (used in loop)
static HomeMenuItem indexToMenuItem(int idx, bool hasOpdsUrl) {
int i = 0;
if (idx == i++) return HomeMenuItem::FILE_BROWSER;
if (idx == i++) return HomeMenuItem::RECENTS;
if (hasOpdsUrl && idx == i++) return HomeMenuItem::OPDS_BROWSER;
if (idx == i++) return HomeMenuItem::FILE_TRANSFER;
if (idx == i) return HomeMenuItem::SETTINGS_MENU;
return HomeMenuItem::NONE;
}
void onSelectBook(const std::string& path);
void onFileBrowserOpen();
void onRecentsOpen();
@@ -43,8 +70,9 @@ class HomeActivity final : public Activity {
void loadRecentCovers(int coverHeight);
public:
explicit HomeActivity(GfxRenderer& renderer, MappedInputManager& mappedInput)
: Activity("Home", renderer, mappedInput) {}
explicit HomeActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
HomeMenuItem initialMenuItemValue = HomeMenuItem::NONE)
: Activity("Home", renderer, mappedInput), initialMenuItem(initialMenuItemValue) {}
void onEnter() override;
void onExit() override;
void loop() override;