mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
UI: Have scroll views directly remember their pos.
Kinda like checkboxes, cleaner this way.
This commit is contained in:
parent
4d5a63a74e
commit
fc78b408b2
4 changed files with 14 additions and 16 deletions
|
@ -1017,17 +1017,13 @@ void ScrollView::PersistData(PersistStatus status, std::string anonId, PersistMa
|
||||||
void ScrollView::SetVisibility(Visibility visibility) {
|
void ScrollView::SetVisibility(Visibility visibility) {
|
||||||
ViewGroup::SetVisibility(visibility);
|
ViewGroup::SetVisibility(visibility);
|
||||||
|
|
||||||
if (visibility == V_GONE && !rememberPosition_) {
|
if (visibility == V_GONE && !rememberPos_) {
|
||||||
// Since this is no longer shown, forget the scroll position.
|
// Since this is no longer shown, forget the scroll position.
|
||||||
// For example, this happens when switching tabs.
|
// For example, this happens when switching tabs.
|
||||||
ScrollTo(0.0f);
|
ScrollTo(0.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float ScrollView::GetScrollPosition() {
|
|
||||||
return scrollPos_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScrollView::ScrollTo(float newScrollPos) {
|
void ScrollView::ScrollTo(float newScrollPos) {
|
||||||
scrollTarget_ = newScrollPos;
|
scrollTarget_ = newScrollPos;
|
||||||
scrollToTarget_ = true;
|
scrollToTarget_ = true;
|
||||||
|
@ -1141,6 +1137,8 @@ void ScrollView::Update() {
|
||||||
|
|
||||||
if (oldPos != scrollPos_)
|
if (oldPos != scrollPos_)
|
||||||
orientation_ == ORIENT_HORIZONTAL ? lastScrollPosX = scrollPos_ : lastScrollPosY = scrollPos_;
|
orientation_ == ORIENT_HORIZONTAL ? lastScrollPosX = scrollPos_ : lastScrollPosY = scrollPos_;
|
||||||
|
if (rememberPos_)
|
||||||
|
*rememberPos_ = scrollPos_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) {
|
void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) {
|
||||||
|
|
|
@ -262,8 +262,8 @@ public:
|
||||||
// A scrollview usually contains just a single child - a linear layout or similar.
|
// A scrollview usually contains just a single child - a linear layout or similar.
|
||||||
class ScrollView : public ViewGroup {
|
class ScrollView : public ViewGroup {
|
||||||
public:
|
public:
|
||||||
ScrollView(Orientation orientation, LayoutParams *layoutParams = 0, bool rememberPosition = false)
|
ScrollView(Orientation orientation, LayoutParams *layoutParams = 0)
|
||||||
: ViewGroup(layoutParams), orientation_(orientation), rememberPosition_(rememberPosition) {}
|
: ViewGroup(layoutParams), orientation_(orientation) {}
|
||||||
~ScrollView();
|
~ScrollView();
|
||||||
|
|
||||||
void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override;
|
void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override;
|
||||||
|
@ -277,10 +277,14 @@ public:
|
||||||
void ScrollTo(float newScrollPos);
|
void ScrollTo(float newScrollPos);
|
||||||
void ScrollToBottom();
|
void ScrollToBottom();
|
||||||
void ScrollRelative(float distance);
|
void ScrollRelative(float distance);
|
||||||
float GetScrollPosition();
|
|
||||||
bool CanScroll() const;
|
bool CanScroll() const;
|
||||||
void Update() override;
|
void Update() override;
|
||||||
|
|
||||||
|
void RememberPosition(float *pos) {
|
||||||
|
rememberPos_ = pos;
|
||||||
|
ScrollTo(*pos);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the last moved scroll view position
|
// Get the last moved scroll view position
|
||||||
static void GetLastScrollPosition(float &x, float &y);
|
static void GetLastScrollPosition(float &x, float &y);
|
||||||
|
|
||||||
|
@ -309,7 +313,7 @@ private:
|
||||||
float pull_ = 0.0f;
|
float pull_ = 0.0f;
|
||||||
float lastViewSize_ = 0.0f;
|
float lastViewSize_ = 0.0f;
|
||||||
bool scrollToTopOnSizeChange_ = false;
|
bool scrollToTopOnSizeChange_ = false;
|
||||||
bool rememberPosition_;
|
float *rememberPos_ = nullptr;
|
||||||
|
|
||||||
static float lastScrollPosX;
|
static float lastScrollPosX;
|
||||||
static float lastScrollPosY;
|
static float lastScrollPosY;
|
||||||
|
|
|
@ -97,7 +97,7 @@ void CwCheatScreen::CreateViews() {
|
||||||
rightScroll_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 0.5f));
|
rightScroll_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 0.5f));
|
||||||
rightScroll_->SetTag("CwCheats");
|
rightScroll_->SetTag("CwCheats");
|
||||||
rightScroll_->SetScrollToTop(false);
|
rightScroll_->SetScrollToTop(false);
|
||||||
rightScroll_->ScrollTo(g_Config.fCwCheatScrollPosition);
|
rightScroll_->RememberPosition(&g_Config.fCwCheatScrollPosition);
|
||||||
LinearLayout *rightColumn = new LinearLayoutList(ORIENT_VERTICAL, new LinearLayoutParams(200, FILL_PARENT, actionMenuMargins));
|
LinearLayout *rightColumn = new LinearLayoutList(ORIENT_VERTICAL, new LinearLayoutParams(200, FILL_PARENT, actionMenuMargins));
|
||||||
rightScroll_->Add(rightColumn);
|
rightScroll_->Add(rightColumn);
|
||||||
|
|
||||||
|
@ -140,7 +140,6 @@ void CwCheatScreen::onFinish(DialogResult result) {
|
||||||
if (MIPSComp::jit) {
|
if (MIPSComp::jit) {
|
||||||
MIPSComp::jit->ClearCache();
|
MIPSComp::jit->ClearCache();
|
||||||
}
|
}
|
||||||
g_Config.fCwCheatScrollPosition = rightScroll_->GetScrollPosition();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UI::EventReturn CwCheatScreen::OnEnableAll(UI::EventParams ¶ms) {
|
UI::EventReturn CwCheatScreen::OnEnableAll(UI::EventParams ¶ms) {
|
||||||
|
|
|
@ -1007,7 +1007,7 @@ void MainScreen::CreateViews() {
|
||||||
|
|
||||||
Button *focusButton = nullptr;
|
Button *focusButton = nullptr;
|
||||||
if (hasStorageAccess) {
|
if (hasStorageAccess) {
|
||||||
scrollAllGames_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT), true);
|
scrollAllGames_ = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
|
||||||
scrollAllGames_->SetTag("MainScreenAllGames");
|
scrollAllGames_->SetTag("MainScreenAllGames");
|
||||||
ScrollView *scrollHomebrew = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
|
ScrollView *scrollHomebrew = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
|
||||||
scrollHomebrew->SetTag("MainScreenHomebrew");
|
scrollHomebrew->SetTag("MainScreenHomebrew");
|
||||||
|
@ -1026,7 +1026,7 @@ void MainScreen::CreateViews() {
|
||||||
|
|
||||||
tabHolder_->AddTab(mm->T("Games"), scrollAllGames_);
|
tabHolder_->AddTab(mm->T("Games"), scrollAllGames_);
|
||||||
tabHolder_->AddTab(mm->T("Homebrew & Demos"), scrollHomebrew);
|
tabHolder_->AddTab(mm->T("Homebrew & Demos"), scrollHomebrew);
|
||||||
scrollAllGames_->ScrollTo(g_Config.fGameListScrollPosition);
|
scrollAllGames_->RememberPosition(&g_Config.fGameListScrollPosition);
|
||||||
|
|
||||||
tabAllGames->OnChoice.Handle(this, &MainScreen::OnGameSelectedInstant);
|
tabAllGames->OnChoice.Handle(this, &MainScreen::OnGameSelectedInstant);
|
||||||
tabHomebrew->OnChoice.Handle(this, &MainScreen::OnGameSelectedInstant);
|
tabHomebrew->OnChoice.Handle(this, &MainScreen::OnGameSelectedInstant);
|
||||||
|
@ -1248,9 +1248,6 @@ void MainScreen::update() {
|
||||||
RecreateViews();
|
RecreateViews();
|
||||||
lastVertical_ = vertical;
|
lastVertical_ = vertical;
|
||||||
}
|
}
|
||||||
if (scrollAllGames_) {
|
|
||||||
g_Config.fGameListScrollPosition = scrollAllGames_->GetScrollPosition();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainScreen::UseVerticalLayout() const {
|
bool MainScreen::UseVerticalLayout() const {
|
||||||
|
|
Loading…
Add table
Reference in a new issue