mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-02 18:53:58 +01:00
UI: Allow scroll views to persist their position.
It'll be clamped as necessary.
This commit is contained in:
1 parent
c0238de4ee
commit
78aae01cd4
2 files changed
+36
-2
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in new issue
Block a user