mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-12 17:19:28 +01:00
UI: Give views a pointer to their parent group
Set by ViewGroup when a view is added, inserted or swapped in. Lets a view find the scroll view it's in, for example. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
729047d449
commit
5d8db2a22d
3 files changed
+13
-2
No files matched your search
@@ -471,6 +471,9 @@ public:
|
||||
const std::string &Tag() const { return tag_; }
|
||||
void SetTag(std::string_view str) { tag_ = str; }
|
||||
|
||||
// The group this view was added to, if any.
|
||||
ViewGroup *Parent() const { return parent_; }
|
||||
|
||||
// Fake RTTI
|
||||
virtual bool IsViewGroup() const { return false; }
|
||||
virtual bool ContainsSubview(const View *view) const { return false; }
|
||||
@@ -518,6 +521,9 @@ protected:
|
||||
DialogResult autoResult_ = DR_OK;
|
||||
|
||||
private:
|
||||
friend class ViewGroup; // Sets parent_.
|
||||
ViewGroup *parent_ = nullptr;
|
||||
|
||||
std::function<bool()> enabledFunc_;
|
||||
bool *enabledPtr_ = nullptr;
|
||||
bool enabled_ = true;
|
||||
|
||||
@@ -164,6 +164,7 @@ bool ViewGroup::ReplaceSubview(View *view, View *newView) {
|
||||
for (int i = 0; i < (int)views_.size(); i++) {
|
||||
if (views_[i] == view) {
|
||||
views_[i] = newView;
|
||||
SetParentOf(newView);
|
||||
delete view;
|
||||
return true;
|
||||
}
|
||||
@@ -1042,8 +1043,7 @@ CollapsibleSection::CollapsibleSection(std::string_view title, LayoutParams *lay
|
||||
open_ = &localOpen_;
|
||||
SetSpacing(0.0f);
|
||||
|
||||
header_ = new CollapsibleHeader(open_, title);
|
||||
views_.push_back(header_);
|
||||
header_ = Add(new CollapsibleHeader(open_, title));
|
||||
header_->OnClick.Add([=](UI::EventParams &) {
|
||||
// Change the visibility of all children except the first one.
|
||||
// Later maybe try something more ambitious.
|
||||
|
||||
@@ -53,11 +53,13 @@ public:
|
||||
template <class T>
|
||||
T *Add(T *view) {
|
||||
views_.push_back(view);
|
||||
SetParentOf(view);
|
||||
return view;
|
||||
}
|
||||
template <class T>
|
||||
T *Insert(int index, T *view) {
|
||||
views_.insert(views_.begin() + index, view);
|
||||
SetParentOf(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -108,6 +110,9 @@ protected:
|
||||
std::string DescribeListUnordered(std::string_view heading) const;
|
||||
std::string DescribeListOrdered(std::string_view heading) const;
|
||||
|
||||
// Anything that adds to views_ without Add or Insert must call this.
|
||||
void SetParentOf(View *view) { view->parent_ = this; }
|
||||
|
||||
std::vector<View *> views_;
|
||||
View *defaultFocusView_ = nullptr;
|
||||
Drawable bg_;
|
||||
|
||||
Reference in new issue
Block a user