From 863bef5f647b14ef26665e0fc012003224445216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 17 Feb 2025 11:25:23 -0600 Subject: [PATCH] Give all views a `bool popupStyle_`, so they know the context. --- Common/UI/UIScreen.cpp | 6 +++++- Common/UI/View.h | 9 +++++++-- Common/UI/ViewGroup.cpp | 7 +++++++ Common/UI/ViewGroup.h | 2 ++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Common/UI/UIScreen.cpp b/Common/UI/UIScreen.cpp index 9412008276..ee5a5c1b76 100644 --- a/Common/UI/UIScreen.cpp +++ b/Common/UI/UIScreen.cpp @@ -430,11 +430,15 @@ void PopupScreen::CreateViews() { box_->SetSpacing(0.0f); if (HasTitleBar()) { - View* title = new PopupHeader(title_); + View *title = new PopupHeader(title_); box_->Add(title); } CreatePopupContents(box_); + root_->Recurse([](View *view) { + view->SetPopupStyle(true); + }); + root_->SetDefaultFocusView(box_); if (ShowButtons() && !button1_.empty()) { // And the two buttons at the bottom. diff --git a/Common/UI/View.h b/Common/UI/View.h index 4ede036922..01c648cec1 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -429,6 +429,8 @@ public: virtual bool CanBeFocused() const { return true; } virtual bool SubviewFocused(View *view) { return false; } + void SetPopupStyle(bool popupStyle) { popupStyle_ = popupStyle; } + bool HasFocus() const { return GetFocusedView() == this; } @@ -480,6 +482,8 @@ public: return t; } + virtual void Recurse(void (*func)(View *view)) {} + protected: // Inputs to layout std::unique_ptr layoutParams_; @@ -496,6 +500,9 @@ protected: std::vector tweens_; + // Whether to use popup colors for styling. + bool popupStyle_ = false; + private: std::function enabledFunc_; bool *enabledPtr_ = nullptr; @@ -851,11 +858,9 @@ public: std::string DescribeText() const override; void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override; void SetLarge(bool large) { large_ = large; } - void SetPopupStyle(bool popupStyle) { popupStyle_ = popupStyle; } private: std::string text_; bool large_ = false; - bool popupStyle_ = false; }; class PopupHeader : public Item { diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index a544952929..f55b07ab5a 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -48,6 +48,13 @@ ViewGroup::~ViewGroup() { Clear(); } +void ViewGroup::Recurse(void (*func)(View *view)) { + for (View *view : views_) { + func(view); + view->Recurse(func); + } +} + void ViewGroup::RemoveSubview(View *subView) { // loop counter needed, so can't convert loop. for (size_t i = 0; i < views_.size(); i++) { diff --git a/Common/UI/ViewGroup.h b/Common/UI/ViewGroup.h index 6a3ef5a222..1cfbddb01b 100644 --- a/Common/UI/ViewGroup.h +++ b/Common/UI/ViewGroup.h @@ -82,6 +82,8 @@ public: std::string DescribeLog() const override { return "ViewGroup: " + View::DescribeLog(); } std::string DescribeText() const override; + void Recurse(void (*func)(View *view)) override; + protected: std::string DescribeListUnordered(std::string_view heading) const; std::string DescribeListOrdered(std::string_view heading) const;