mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-19 01:10:39 +02:00
UI: Add a simple means of persisting data.
This commit is contained in:
1 parent
84d815768b
commit
f6772ec526
4 files changed
+31
-4
No files matched your search
@@ -1,3 +1,4 @@
|
||||
#include <map>
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-2
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
@@ -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<int> PersistBuffer;
|
||||
typedef std::map<std::string, UI::PersistBuffer> 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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in new issue
Block a user