UI: Allow scroll views to persist their position.

It'll be clamped as necessary.
This commit is contained in:
Unknown W. Brackets committed 2016-01-22 23:02:44 -08:00
1 parent c0238de4ee
commit 78aae01cd4
2 files changed
+36 -2

No files matched your search

+33 -1
View File
@@ -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;
}
+3 -1
View File
@@ -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; }