From 84d815768ba194a102009c9adbeb46234df598a1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 22 Jan 2016 22:38:21 -0800 Subject: [PATCH 1/5] UI: Set tags on tab views, in the typical case. --- UI/DevScreens.cpp | 2 ++ UI/GameSettingsScreen.cpp | 1 + UI/MainScreen.cpp | 2 ++ UI/SavedataScreen.cpp | 1 + UI/TouchControlLayoutScreen.cpp | 1 + 5 files changed, 7 insertions(+) diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index fc3bdd52df..3eb90f45b3 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -326,6 +326,7 @@ void SystemInfoScreen::CreateViews() { AddStandardBack(root_); TabHolder *tabHolder = new TabHolder(ORIENT_VERTICAL, 225, new AnchorLayoutParams(10, 0, 10, 0, false)); + tabHolder->SetTag("DevSystemInfo"); root_->Add(tabHolder); ViewGroup *deviceSpecsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); @@ -818,6 +819,7 @@ void ShaderListScreen::CreateViews() { root_ = layout; tabs_ = new TabHolder(ORIENT_HORIZONTAL, 40, new LinearLayoutParams(1.0)); + tabs_->SetTag("DevShaderList"); layout->Add(tabs_); layout->Add(new Button(di->T("Back")))->OnClick.Handle(this, &UIScreen::OnBack); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 9748ef499b..0802c7bca6 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -121,6 +121,7 @@ void GameSettingsScreen::CreateViews() { root_->Add(tabHolder); AddStandardBack(root_); } + tabHolder->SetTag("GameSettings"); root_->SetDefaultFocusView(tabHolder); // TODO: These currently point to global settings, not game specific ones. diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index e9a52026be..a5b6bf100a 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -709,6 +709,7 @@ void MainScreen::CreateViews() { TabHolder *leftColumn = new TabHolder(ORIENT_HORIZONTAL, 64, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); tabHolder_ = leftColumn; + tabHolder_->SetTag("MainScreenGames"); leftColumn->SetClip(true); @@ -1119,6 +1120,7 @@ void UmdReplaceScreen::CreateViews() { I18NCategory *di = GetI18NCategory("Dialog"); TabHolder *leftColumn = new TabHolder(ORIENT_HORIZONTAL, 64, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0)); + leftColumn->SetTag("UmdReplace"); leftColumn->SetClip(true); ViewGroup *rightColumn = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(270, FILL_PARENT, actionMenuMargins)); diff --git a/UI/SavedataScreen.cpp b/UI/SavedataScreen.cpp index 9f8b47a34d..ead70233e9 100644 --- a/UI/SavedataScreen.cpp +++ b/UI/SavedataScreen.cpp @@ -344,6 +344,7 @@ void SavedataScreen::CreateViews() { root_ = new LinearLayout(ORIENT_VERTICAL); TabHolder *tabs = new TabHolder(ORIENT_HORIZONTAL, 64, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f)); + tabs->SetTag("Savedata"); ScrollView *scroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); browser_ = scroll->Add(new SavedataBrowser(savedata_dir, new LayoutParams(FILL_PARENT, FILL_PARENT))); browser_->OnChoice.Handle(this, &SavedataScreen::OnSavedataButtonClick); diff --git a/UI/TouchControlLayoutScreen.cpp b/UI/TouchControlLayoutScreen.cpp index 2bb91bda92..0680dbd218 100644 --- a/UI/TouchControlLayoutScreen.cpp +++ b/UI/TouchControlLayoutScreen.cpp @@ -335,6 +335,7 @@ void TouchControlLayoutScreen::CreateViews() { root_->Add(back); TabHolder *tabHolder = new TabHolder(ORIENT_VERTICAL, leftColumnWidth, new AnchorLayoutParams(10, 0, 10, 0, false)); + tabHolder->SetTag("TouchControlLayout"); root_->Add(tabHolder); // this is more for show than anything else. It's used to provide a boundary From f6772ec526da177408eaba76eb722ede894ebcdd Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 22 Jan 2016 22:40:16 -0800 Subject: [PATCH 2/5] UI: Add a simple means of persisting data. --- ext/native/ui/ui_screen.cpp | 13 ++++++++++++- ext/native/ui/view.h | 12 ++++++++++-- ext/native/ui/viewgroup.cpp | 9 ++++++++- ext/native/ui/viewgroup.h | 1 + 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index 88ba27eca2..57af678ddd 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -1,3 +1,4 @@ +#include #include "base/display.h" #include "input/input_state.h" #include "input/keycodes.h" @@ -19,13 +20,23 @@ UIScreen::~UIScreen() { void UIScreen::DoRecreateViews() { if (recreateViews_) { + UI::PersistMap persisted; + bool persisting = root_ != nullptr; + if (persisting) { + root_->PersistData(UI::PERSIST_SAVE, persisted); + } + delete root_; - root_ = 0; + root_ = nullptr; CreateViews(); if (root_ && root_->GetDefaultFocusView()) { root_->GetDefaultFocusView()->SetFocus(); } recreateViews_ = false; + + if (persisting) { + root_->PersistData(UI::PERSIST_RESTORE, persisted); + } } } diff --git a/ext/native/ui/view.h b/ext/native/ui/view.h index 952e3d9c29..4b4cbb32d4 100644 --- a/ext/native/ui/view.h +++ b/ext/native/ui/view.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -203,9 +204,15 @@ enum FocusFlags { FF_GOTFOCUS = 2 }; -class ViewGroup; +enum PersistStatus { + PERSIST_SAVE, + PERSIST_RESTORE, +}; -void Fill(UIContext &dc, const Bounds &bounds, const Drawable &drawable); +typedef std::vector PersistBuffer; +typedef std::map PersistMap; + +class ViewGroup; struct MeasureSpec { MeasureSpec(MeasureSpecType t, float s = 0.0f) : type(t), size(s) {} @@ -339,6 +346,7 @@ public: virtual std::string Describe() const; virtual void FocusChanged(int focusFlags) {} + virtual void PersistData(PersistStatus status, PersistMap &storage) {} void Move(Bounds bounds) { bounds_ = bounds; diff --git a/ext/native/ui/viewgroup.cpp b/ext/native/ui/viewgroup.cpp index 948852bd81..a7011cd5a3 100644 --- a/ext/native/ui/viewgroup.cpp +++ b/ext/native/ui/viewgroup.cpp @@ -70,11 +70,18 @@ void ViewGroup::Clear() { lock_guard guard(modifyLock_); for (size_t i = 0; i < views_.size(); i++) { delete views_[i]; - views_[i] = 0; + views_[i] = nullptr; } views_.clear(); } +void ViewGroup::PersistData(PersistStatus status, PersistMap &storage) { + lock_guard guard(modifyLock_); + for (size_t i = 0; i < views_.size(); i++) { + views_[i]->PersistData(status, storage); + } +} + void ViewGroup::Touch(const TouchInput &input) { lock_guard guard(modifyLock_); for (auto iter = views_.begin(); iter != views_.end(); ++iter) { diff --git a/ext/native/ui/viewgroup.h b/ext/native/ui/viewgroup.h index 833c937ef4..da85e8a1e7 100644 --- a/ext/native/ui/viewgroup.h +++ b/ext/native/ui/viewgroup.h @@ -64,6 +64,7 @@ public: virtual void SetBG(const Drawable &bg) { bg_ = bg; } virtual void Clear(); + void PersistData(PersistStatus status, PersistMap &storage) override; View *GetViewByIndex(int index) { return views_[index]; } int GetNumSubviews() const { return (int)views_.size(); } void SetHasDropShadow(bool has) { hasDropShadow_ = has; } From 1c2ac798cdbc365a2a83c7410e4fcbbc338ac60a Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 22 Jan 2016 22:40:36 -0800 Subject: [PATCH 3/5] UI: Persist selected tab on resize. --- ext/native/ui/viewgroup.cpp | 22 ++++++++++++++++++++++ ext/native/ui/viewgroup.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/ext/native/ui/viewgroup.cpp b/ext/native/ui/viewgroup.cpp index a7011cd5a3..5ae3114432 100644 --- a/ext/native/ui/viewgroup.cpp +++ b/ext/native/ui/viewgroup.cpp @@ -1053,6 +1053,28 @@ EventReturn TabHolder::OnTabClick(EventParams &e) { return EVENT_DONE; } +void TabHolder::PersistData(PersistStatus status, PersistMap &storage) { + const std::string &tag = Tag(); + + if (tag.empty()) { + return; + } + + PersistBuffer &buffer = storage["TabHolder::" + tag]; + switch (status) { + case PERSIST_SAVE: + buffer.resize(1); + buffer[0] = currentTab_; + break; + + case PERSIST_RESTORE: + if (buffer.size() == 1) { + SetCurrentTab(buffer[0]); + } + break; + } +} + ChoiceStrip::ChoiceStrip(Orientation orientation, LayoutParams *layoutParams) : LinearLayout(orientation, layoutParams), selected_(0), topTabs_(false) { SetSpacing(0.0f); diff --git a/ext/native/ui/viewgroup.h b/ext/native/ui/viewgroup.h index da85e8a1e7..3b432901cf 100644 --- a/ext/native/ui/viewgroup.h +++ b/ext/native/ui/viewgroup.h @@ -323,6 +323,8 @@ public: int GetCurrentTab() const { return currentTab_; } std::string Describe() const override { return "TabHolder: " + View::Describe(); } + void PersistData(PersistStatus status, PersistMap &storage) override; + private: EventReturn OnTabClick(EventParams &e); From c0238de4eef0923042394bbc9d151c0bfce15d75 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 22 Jan 2016 22:52:13 -0800 Subject: [PATCH 4/5] UI: Add tags to all the scroll views. --- UI/ControlMappingScreen.cpp | 1 + UI/CwCheatScreen.cpp | 1 + UI/DevScreens.cpp | 7 +++++++ UI/GameSettingsScreen.cpp | 7 +++++++ UI/MainScreen.cpp | 5 +++++ UI/SavedataScreen.cpp | 2 ++ UI/Store.cpp | 2 ++ UI/TiltAnalogSettingsScreen.cpp | 1 + 8 files changed, 26 insertions(+) diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 5838faed3c..3ebe05f158 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -220,6 +220,7 @@ void ControlMappingScreen::CreateViews() { AddStandardBack(leftColumn); rightScroll_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)); + rightScroll_->SetTag("ControlMapping"); rightScroll_->SetScrollToTop(false); LinearLayout *rightColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)); rightScroll_->Add(rightColumn); diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index b2b7a6061b..82a40ef263 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -78,6 +78,7 @@ void CwCheatScreen::CreateViews() { leftColumn->Add(new PopupSliderChoice(&g_Config.iCwCheatRefreshRate, 1, 1000, cw->T("Refresh Rate"), 1, screenManager())); ScrollView *rightScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(0.5f)); + rightScroll->SetTag("CwCheats"); rightScroll->SetScrollToTop(false); LinearLayout *rightColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(200, FILL_PARENT, actionMenuMargins)); LayoutParams *layout = new LayoutParams(500, 50, LP_PLAIN); diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 3eb90f45b3..6325ba7e79 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -330,6 +330,7 @@ void SystemInfoScreen::CreateViews() { root_->Add(tabHolder); ViewGroup *deviceSpecsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + deviceSpecsScroll->SetTag("DevSystemInfoDeviceSpecs"); LinearLayout *deviceSpecs = new LinearLayout(ORIENT_VERTICAL); deviceSpecs->SetSpacing(0); deviceSpecsScroll->Add(deviceSpecs); @@ -408,6 +409,7 @@ void SystemInfoScreen::CreateViews() { #endif ViewGroup *cpuExtensionsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + cpuExtensionsScroll->SetTag("DevSystemInfoCPUExt"); LinearLayout *cpuExtensions = new LinearLayout(ORIENT_VERTICAL); cpuExtensions->SetSpacing(0); cpuExtensionsScroll->Add(cpuExtensions); @@ -422,6 +424,7 @@ void SystemInfoScreen::CreateViews() { } ViewGroup *oglExtensionsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + oglExtensionsScroll->SetTag("DevSystemInfoOGLExt"); LinearLayout *oglExtensions = new LinearLayout(ORIENT_VERTICAL); oglExtensions->SetSpacing(0); oglExtensionsScroll->Add(oglExtensions); @@ -450,6 +453,7 @@ void SystemInfoScreen::CreateViews() { // If there aren't any EGL extensions, no need to show the tab. if (exts.size() > 0) { ViewGroup *eglExtensionsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + eglExtensionsScroll->SetTag("DevSystemInfoEGLExt"); LinearLayout *eglExtensions = new LinearLayout(ORIENT_VERTICAL); eglExtensions->SetSpacing(0); eglExtensionsScroll->Add(eglExtensions); @@ -567,10 +571,12 @@ void JitCompareScreen::CreateViews() { ScrollView *midColumnScroll = root_->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(2.0f))); LinearLayout *midColumn = midColumnScroll->Add(new LinearLayout(ORIENT_VERTICAL)); + midColumn->SetTag("JitCompareLeftDisasm"); leftDisasm_ = midColumn->Add(new LinearLayout(ORIENT_VERTICAL)); leftDisasm_->SetSpacing(0.0f); ScrollView *rightColumnScroll = root_->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(2.0f))); + rightColumnScroll->SetTag("JitCompareRightDisasm"); LinearLayout *rightColumn = rightColumnScroll->Add(new LinearLayout(ORIENT_VERTICAL)); rightDisasm_ = rightColumn->Add(new LinearLayout(ORIENT_VERTICAL)); rightDisasm_->SetSpacing(0.0f); @@ -851,6 +857,7 @@ void ShaderViewScreen::CreateViews() { layout->Add(new TextView(gpu->DebugGetShaderString(id_, type_, SHADER_STRING_SHORT_DESC))); ScrollView *scroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0)); + scroll->SetTag("DevShaderView"); layout->Add(scroll); LinearLayout *lineLayout = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 0802c7bca6..f99522e3df 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -128,6 +128,7 @@ void GameSettingsScreen::CreateViews() { // Graphics ViewGroup *graphicsSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + graphicsSettingsScroll->SetTag("GameSettingsGraphics"); LinearLayout *graphicsSettings = new LinearLayout(ORIENT_VERTICAL); graphicsSettings->SetSpacing(0); graphicsSettingsScroll->Add(graphicsSettings); @@ -333,6 +334,7 @@ void GameSettingsScreen::CreateViews() { // Audio ViewGroup *audioSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + audioSettingsScroll->SetTag("GameSettingsAudio"); LinearLayout *audioSettings = new LinearLayout(ORIENT_VERTICAL); audioSettings->SetSpacing(0); audioSettingsScroll->Add(audioSettings); @@ -367,6 +369,7 @@ void GameSettingsScreen::CreateViews() { // Control ViewGroup *controlsSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + controlsSettingsScroll->SetTag("GameSettingsControls"); LinearLayout *controlsSettings = new LinearLayout(ORIENT_VERTICAL); controlsSettings->SetSpacing(0); controlsSettingsScroll->Add(controlsSettings); @@ -455,6 +458,7 @@ void GameSettingsScreen::CreateViews() { controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fAnalogLimiterDeadzone, 0.0f, 1.0f, co->T("Analog Limiter"), 0.10f, screenManager(), "/ 1.0")); ViewGroup *networkingSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + networkingSettingsScroll->SetTag("GameSettingsNetworking"); LinearLayout *networkingSettings = new LinearLayout(ORIENT_VERTICAL); networkingSettings->SetSpacing(0); networkingSettingsScroll->Add(networkingSettings); @@ -475,6 +479,7 @@ void GameSettingsScreen::CreateViews() { networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.sMACAddress, n->T("Change Mac Address"), nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeMacAddress); ViewGroup *toolsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + toolsScroll->SetTag("GameSettingsTools"); LinearLayout *tools = new LinearLayout(ORIENT_VERTICAL); tools->SetSpacing(0); toolsScroll->Add(tools); @@ -488,6 +493,7 @@ void GameSettingsScreen::CreateViews() { // System ViewGroup *systemSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); + systemSettingsScroll->SetTag("GameSettingsSystem"); LinearLayout *systemSettings = new LinearLayout(ORIENT_VERTICAL); systemSettings->SetSpacing(0); systemSettingsScroll->Add(systemSettings); @@ -1014,6 +1020,7 @@ UI::EventReturn GameSettingsScreen::OnSysInfo(UI::EventParams &e) { void DeveloperToolsScreen::CreateViews() { using namespace UI; root_ = new ScrollView(ORIENT_VERTICAL); + root_->SetTag("DevToolsSettings"); I18NCategory *di = GetI18NCategory("Dialog"); I18NCategory *dev = GetI18NCategory("Developer"); diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index a5b6bf100a..fbd646fbdc 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -715,6 +715,7 @@ void MainScreen::CreateViews() { if (g_Config.iMaxRecent > 0) { ScrollView *scrollRecentGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + scrollRecentGames->SetTag("MainScreenRecentGames"); GameBrowser *tabRecentGames = new GameBrowser( "!RECENT", false, &g_Config.bGridView1, "", "", 0, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); @@ -727,7 +728,9 @@ void MainScreen::CreateViews() { if (System_GetPermissionStatus(SYSTEM_PERMISSION_STORAGE) == PERMISSION_STATUS_GRANTED) { ScrollView *scrollAllGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + scrollAllGames->SetTag("MainScreenAllGames"); ScrollView *scrollHomebrew = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + scrollHomebrew->SetTag("MainScreenHomebrew"); GameBrowser *tabAllGames = new GameBrowser(g_Config.currentDirectory, true, &g_Config.bGridView2, mm->T("How to get games"), "http://www.ppsspp.org/getgames.html", 0, @@ -1130,6 +1133,7 @@ void UmdReplaceScreen::CreateViews() { if (g_Config.iMaxRecent > 0) { ScrollView *scrollRecentGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + scrollRecentGames->SetTag("UmdReplaceRecentGames"); GameBrowser *tabRecentGames = new GameBrowser( "!RECENT", false, &g_Config.bGridView1, "", "", 0, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); @@ -1139,6 +1143,7 @@ void UmdReplaceScreen::CreateViews() { tabRecentGames->OnHoldChoice.Handle(this, &UmdReplaceScreen::OnGameSelected); } ScrollView *scrollAllGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + scrollAllGames->SetTag("UmdReplaceAllGames"); GameBrowser *tabAllGames = new GameBrowser(g_Config.currentDirectory, true, &g_Config.bGridView2, mm->T("How to get games"), "http://www.ppsspp.org/getgames.html", 0, diff --git a/UI/SavedataScreen.cpp b/UI/SavedataScreen.cpp index ead70233e9..1aba394a9c 100644 --- a/UI/SavedataScreen.cpp +++ b/UI/SavedataScreen.cpp @@ -346,12 +346,14 @@ void SavedataScreen::CreateViews() { TabHolder *tabs = new TabHolder(ORIENT_HORIZONTAL, 64, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f)); tabs->SetTag("Savedata"); ScrollView *scroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + scroll->SetTag("SavedataBrowser"); browser_ = scroll->Add(new SavedataBrowser(savedata_dir, new LayoutParams(FILL_PARENT, FILL_PARENT))); browser_->OnChoice.Handle(this, &SavedataScreen::OnSavedataButtonClick); tabs->AddTab(sa->T("Save Data"), scroll); ScrollView *scroll2 = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); + scroll2->SetTag("SavedataStatesBrowser"); SavedataBrowser *browser2 = scroll2->Add(new SavedataBrowser(savestate_dir)); browser2->OnChoice.Handle(this, &SavedataScreen::OnSavedataButtonClick); tabs->AddTab(sa->T("Save States"), scroll2); diff --git a/UI/Store.cpp b/UI/Store.cpp index 1e36aefc56..74bc3fef56 100644 --- a/UI/Store.cpp +++ b/UI/Store.cpp @@ -400,6 +400,7 @@ void StoreScreen::CreateViews() { } else { content = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f)); ScrollView *leftScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(WRAP_CONTENT, FILL_PARENT, 0.4f)); + leftScroll->SetTag("StoreMainList"); content->Add(leftScroll); LinearLayout *scrollItemView = new LinearLayout(ORIENT_VERTICAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)); leftScroll->Add(scrollItemView); @@ -411,6 +412,7 @@ void StoreScreen::CreateViews() { // TODO: Similar apps, etc etc productPanel_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(0.5f)); + leftScroll->SetTag("StoreMainProduct"); content->Add(productPanel_); } root_->Add(content); diff --git a/UI/TiltAnalogSettingsScreen.cpp b/UI/TiltAnalogSettingsScreen.cpp index bbbee832ff..be9f7ff7bb 100644 --- a/UI/TiltAnalogSettingsScreen.cpp +++ b/UI/TiltAnalogSettingsScreen.cpp @@ -27,6 +27,7 @@ void TiltAnalogSettingsScreen::CreateViews() { I18NCategory *di = GetI18NCategory("Dialog"); root_ = new ScrollView(ORIENT_VERTICAL); + root_->SetTag("TiltAnalogSettings"); LinearLayout *settings = new LinearLayout(ORIENT_VERTICAL); From 78aae01cd4bfdfce5e3a74b34afe0f70cca36859 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 22 Jan 2016 23:02:44 -0800 Subject: [PATCH 5/5] UI: Allow scroll views to persist their position. It'll be clamped as necessary. --- ext/native/ui/viewgroup.cpp | 34 +++++++++++++++++++++++++++++++++- ext/native/ui/viewgroup.h | 4 +++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ext/native/ui/viewgroup.cpp b/ext/native/ui/viewgroup.cpp index 5ae3114432..3140141ac1 100644 --- a/ext/native/ui/viewgroup.cpp +++ b/ext/native/ui/viewgroup.cpp @@ -812,6 +812,37 @@ bool ScrollView::SubviewFocused(View *view) { return true; } +void ScrollView::PersistData(PersistStatus status, PersistMap &storage) { + ViewGroup::PersistData(status, storage); + + const std::string &tag = Tag(); + if (tag.empty()) { + return; + } + + PersistBuffer &buffer = storage["ScrollView::" + tag]; + switch (status) { + case PERSIST_SAVE: + { + buffer.resize(1); + float pos = scrollToTarget_ ? scrollTarget_ : scrollPos_; + // Hmm, ugly... better buffer? + buffer[0] = *(int *)&pos; + } + break; + + case PERSIST_RESTORE: + if (buffer.size() == 1) { + float pos = *(float *)&buffer[0]; + ClampScrollPos(pos); + scrollPos_ = pos; + scrollTarget_ = pos; + scrollToTarget_ = false; + } + break; + } +} + void ScrollView::ScrollTo(float newScrollPos) { scrollTarget_ = newScrollPos; scrollToTarget_ = true; @@ -1054,8 +1085,9 @@ EventReturn TabHolder::OnTabClick(EventParams &e) { } void TabHolder::PersistData(PersistStatus status, PersistMap &storage) { - const std::string &tag = Tag(); + ViewGroup::PersistData(status, storage); + const std::string &tag = Tag(); if (tag.empty()) { return; } diff --git a/ext/native/ui/viewgroup.h b/ext/native/ui/viewgroup.h index 3b432901cf..a178a94f55 100644 --- a/ext/native/ui/viewgroup.h +++ b/ext/native/ui/viewgroup.h @@ -245,7 +245,9 @@ public: void Update(const InputState &input_state) override; // Override so that we can scroll to the active one after moving the focus. - virtual bool SubviewFocused(View *view) override; + bool SubviewFocused(View *view) override; + + void PersistData(PersistStatus status, PersistMap &storage) override; // Quick hack to prevent scrolling to top in some lists void SetScrollToTop(bool t) { scrollToTopOnSizeChange_ = t; }