UI: CollapsibleHeader no longer shows the open/close icon if there are no items

This commit is contained in:
Henrik Rydgård committed 2023-07-23 11:11:44 +02:00
1 parent 18ac95a107
commit aa46d3aae3
4 files changed
+20 -4

No files matched your search

+3 -1
View File
@@ -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 {
+4
View File
@@ -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 {
+8 -3
View File
@@ -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
+5
View File
@@ -324,12 +324,17 @@ private:
std::vector<AnchorTranslateTween *> 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