Give all views a bool popupStyle_, so they know the context.

This commit is contained in:
Henrik Rydgård 2025-02-17 11:25:23 -06:00
parent 4ff642ccc8
commit 863bef5f64
4 changed files with 21 additions and 3 deletions

View file

@ -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.

View file

@ -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> layoutParams_;
@ -496,6 +500,9 @@ protected:
std::vector<Tween *> tweens_;
// Whether to use popup colors for styling.
bool popupStyle_ = false;
private:
std::function<bool()> 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 {

View file

@ -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++) {

View file

@ -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;