diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 6a12441740..da693298e4 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -608,6 +608,38 @@ std::string ItemHeader::DescribeText() const { return ReplaceAll(u->T("%1 heading"), "%1", text_); } +void BorderView::Draw(UIContext &dc) { + Color color = 0xFFFFFFFF; + if (style_ == BorderStyle::HEADER_FG) + color = dc.theme->headerStyle.fgColor; + else if (style_ == BorderStyle::ITEM_DOWN_BG) + color = dc.theme->itemDownStyle.background.color; + + if (borderFlags_ & BORDER_TOP) + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y + size_, color); + if (borderFlags_ & BORDER_LEFT) + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x + size_, bounds_.y2(), color); + if (borderFlags_ & BORDER_BOTTOM) + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y2() - size_, bounds_.x2(), bounds_.y2(), color); + if (borderFlags_ & BORDER_RIGHT) + dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x2() - size_, bounds_.y, bounds_.x2(), bounds_.y2(), color); +} + +void BorderView::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const { + Bounds bounds(0, 0, layoutParams_->width, layoutParams_->height); + if (bounds.w < 0) { + // If there's no size, let's grow as big as we want. + bounds.w = horiz.size == 0 ? MAX_ITEM_SIZE : horiz.size; + } + if (bounds.h < 0) { + bounds.h = vert.size == 0 ? MAX_ITEM_SIZE : vert.size; + } + ApplyBoundsBySpec(bounds, horiz, vert); + // If we have vertical borders, grow to width so they're spaced apart. + w = (borderFlags_ & BORDER_VERT) != 0 ? bounds.w : 0; + h = (borderFlags_ & BORDER_HORIZ) != 0 ? bounds.h : 0; +} + void PopupHeader::Draw(UIContext &dc) { const float paddingHorizontal = 12; const float availableWidth = bounds_.w - paddingHorizontal * 2; diff --git a/Common/UI/View.h b/Common/UI/View.h index 2b56716028..6a554b5b78 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -162,6 +162,24 @@ enum Gravity { G_VERTMASK = 3 << 2, }; +enum Borders { + BORDER_NONE = 0, + + BORDER_TOP = 0x0001, + BORDER_LEFT = 0x0002, + BORDER_BOTTOM = 0x0004, + BORDER_RIGHT = 0x0008, + + BORDER_HORIZ = BORDER_LEFT | BORDER_RIGHT, + BORDER_VERT = BORDER_TOP | BORDER_BOTTOM, + BORDER_ALL = BORDER_TOP | BORDER_LEFT | BORDER_BOTTOM | BORDER_RIGHT, +}; + +enum class BorderStyle { + HEADER_FG, + ITEM_DOWN_BG, +}; + typedef float Size; // can also be WRAP_CONTENT or FILL_PARENT. enum Orientation { @@ -867,6 +885,21 @@ public: std::string DescribeText() const override { return ""; } private: + float size_ = 0.0f; +}; + +class BorderView : public InertView { +public: + BorderView(Borders borderFlags, BorderStyle style, float size = 2.0f, LayoutParams *layoutParams = nullptr) + : InertView(layoutParams), borderFlags_(borderFlags), style_(style), size_(size) { + } + void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override; + void Draw(UIContext &dc) override; + std::string DescribeText() const override { return ""; } + +private: + Borders borderFlags_; + BorderStyle style_; float size_; }; diff --git a/UI/TouchControlLayoutScreen.cpp b/UI/TouchControlLayoutScreen.cpp index 1c9bb0931c..c4ad2f96f3 100644 --- a/UI/TouchControlLayoutScreen.cpp +++ b/UI/TouchControlLayoutScreen.cpp @@ -640,6 +640,7 @@ void TouchControlLayoutScreen::CreateViews() { leftColumn->Add(new Choice(di->T("Reset")))->OnClick.Handle(this, &TouchControlLayoutScreen::OnReset); leftColumn->Add(new Choice(di->T("Back")))->OnClick.Handle(this, &UIScreen::OnBack); - root_->Add(new ItemHeader("", new AnchorLayoutParams(leftColumnWidth + 10, bounds.h*(1.0-layoutAreaScale)-40, NONE, NONE, false))); - layoutView_ = root_->Add(new ControlLayoutView(new AnchorLayoutParams(leftColumnWidth + 10, bounds.h*(1.0-layoutAreaScale), 0.0f, 0.0f, false))); + root_->Add(new BorderView(BORDER_BOTTOM, BorderStyle::ITEM_DOWN_BG, 4.0f, new AnchorLayoutParams(leftColumnWidth + 10, bounds.h * (1.0f - layoutAreaScale), 0.0f, NONE, false))); + root_->Add(new BorderView(BORDER_RIGHT, BorderStyle::ITEM_DOWN_BG, 4.0f, new AnchorLayoutParams(leftColumnWidth + 10, 0.0f, NONE, 0.0f, false))); + layoutView_ = root_->Add(new ControlLayoutView(new AnchorLayoutParams(leftColumnWidth + 10, bounds.h * (1.0 - layoutAreaScale), 0.0f, 0.0f, false))); }