| 80 | } |
| 81 | |
| 82 | void TitlePickerOverlay::update(const InputState& input) |
| 83 | { |
| 84 | const u64 kdown = input.kDown; |
| 85 | |
| 86 | if (kdown & HidNpadButton_B) { |
| 87 | me.reset(); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | if (!mItems.empty()) { |
| 92 | if (kdown & HidNpadButton_Up) { |
| 93 | mCursor = mCursor > 0 ? mCursor - 1 : (int)mItems.size() - 1; |
| 94 | } |
| 95 | else if (kdown & HidNpadButton_Down) { |
| 96 | mCursor = mCursor < (int)mItems.size() - 1 ? mCursor + 1 : 0; |
| 97 | } |
| 98 | if (mCursor < mScroll) |
| 99 | mScroll = mCursor; |
| 100 | else if (mCursor >= mScroll + VISIBLE) |
| 101 | mScroll = mCursor - VISIBLE + 1; |
| 102 | |
| 103 | if (kdown & HidNpadButton_A) { |
| 104 | u64 id = mItems[mCursor].first; |
| 105 | // Dismiss first: mOnPick may raise its own follow-up (a keyboard), |
| 106 | // and it captures state that outlives this overlay. |
| 107 | auto pick = mOnPick; |
| 108 | me.reset(); |
| 109 | if (pick) |
| 110 | pick(id); |
| 111 | return; |
| 112 | } |
| 113 | } |
| 114 | } |