diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 9495334990..82c2497a7a 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -618,7 +618,9 @@ void CollapsibleHeader::Draw(UIContext &dc) { dc.SetFontStyle(dc.theme->uiFontSmall); dc.DrawText(text_.c_str(), bounds_.x + 4 + xoff, bounds_.centerY(), dc.theme->headerStyle.fgColor, ALIGN_LEFT | ALIGN_VCENTER); dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y2() - 2, bounds_.x2(), bounds_.y2(), dc.theme->headerStyle.fgColor); - dc.Draw()->DrawImageRotated(ImageID("I_ARROW"), bounds_.x + 20.0f, bounds_.y + 20.0f, 1.0f, *toggle_ ? -M_PI / 2 : M_PI); + if (hasSubItems_) { + dc.Draw()->DrawImageRotated(ImageID("I_ARROW"), bounds_.x + 20.0f, bounds_.y + 20.0f, 1.0f, *toggle_ ? -M_PI / 2 : M_PI); + } } void CollapsibleHeader::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const { diff --git a/Common/UI/View.h b/Common/UI/View.h index 52a7b5fe26..91dc739d5e 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -870,6 +870,10 @@ public: void Draw(UIContext &dc) override; void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override; void GetContentDimensions(const UIContext &dc, float &w, float &h) const override; + + void SetHasSubitems(bool hasSubItems) { hasSubItems_ = hasSubItems; } +private: + bool hasSubItems_ = true; }; class BitCheckBox : public CheckBox { diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index 757192fab8..e418d63008 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -1183,9 +1183,9 @@ StickyChoice *ChoiceStrip::Choice(int index) { CollapsibleSection::CollapsibleSection(const std::string &title, LayoutParams *layoutParams) : LinearLayout(ORIENT_VERTICAL, layoutParams) { SetSpacing(0.0f); - CollapsibleHeader *heading = new CollapsibleHeader(&open_, title); - views_.push_back(heading); - heading->OnClick.Add([=](UI::EventParams &) { + heading_ = new CollapsibleHeader(&open_, title); + views_.push_back(heading_); + heading_->OnClick.Add([=](UI::EventParams &) { // Change the visibility of all children except the first one. // Later maybe try something more ambitious. for (size_t i = 1; i < views_.size(); i++) { @@ -1195,4 +1195,9 @@ CollapsibleSection::CollapsibleSection(const std::string &title, LayoutParams *l }); } +void CollapsibleSection::Update() { + ViewGroup::Update(); + heading_->SetHasSubitems(views_.size() > 1); +} + } // namespace UI diff --git a/Common/UI/ViewGroup.h b/Common/UI/ViewGroup.h index 2f014ac48b..310eb20766 100644 --- a/Common/UI/ViewGroup.h +++ b/Common/UI/ViewGroup.h @@ -324,12 +324,17 @@ private: std::vector tabTweens_; }; +class CollapsibleHeader; + class CollapsibleSection : public LinearLayout { public: CollapsibleSection(const std::string &title, LayoutParams *layoutParams = nullptr); + void Update() override; + private: bool open_ = true; + CollapsibleHeader *heading_; }; } // namespace UI