From 6202e46e2ca4335deb33cdbdb8db146ca2e55bad Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 28 Feb 2021 15:04:00 -0800 Subject: [PATCH] UI: Wrap long info items. Avoid overlapping the label. --- Common/Math/geom2d.h | 3 +++ Common/UI/View.cpp | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Common/Math/geom2d.h b/Common/Math/geom2d.h index 1d375fc1d6..1d0afa1c2b 100644 --- a/Common/Math/geom2d.h +++ b/Common/Math/geom2d.h @@ -66,6 +66,9 @@ struct Bounds { Bounds Expand(float amount) const { return Bounds(x - amount, y - amount, w + amount * 2, h + amount * 2); } + Bounds Expand(float xAmount, float yAmount) const { + return Bounds(x - xAmount, y - yAmount, w + xAmount * 2, h + yAmount * 2); + } Bounds Offset(float xAmount, float yAmount) const { return Bounds(x + xAmount, y + yAmount, w, h); } diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 89c1da4dfb..dbb206185d 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -546,11 +546,16 @@ void InfoItem::Draw(UIContext &dc) { dc.FillRect(style.background, bounds_); int paddingX = 12; + Bounds padBounds = bounds_.Expand(-paddingX, 0); + + float leftWidth, leftHeight; + dc.MeasureTextRect(dc.theme->uiFont, 1.0f, 1.0f, text_.c_str(), (int)text_.size(), padBounds, &leftWidth, &leftHeight, ALIGN_VCENTER); dc.SetFontStyle(dc.theme->uiFont); - dc.DrawText(text_.c_str(), bounds_.x + paddingX, bounds_.centerY(), style.fgColor, ALIGN_VCENTER); - dc.DrawText(rightText_.c_str(), bounds_.x2() - paddingX, bounds_.centerY(), style.fgColor, ALIGN_VCENTER | ALIGN_RIGHT); -// dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y + 2, dc.theme->itemDownStyle.bgColor); + dc.DrawTextRect(text_.c_str(), padBounds, style.fgColor, ALIGN_VCENTER); + + Bounds rightBounds(padBounds.x + leftWidth, padBounds.y, padBounds.w - leftWidth, padBounds.h); + dc.DrawTextRect(rightText_.c_str(), rightBounds, style.fgColor, ALIGN_VCENTER | ALIGN_RIGHT | FLAG_WRAP_TEXT); } std::string InfoItem::DescribeText() const {