From 08b7d646e81e4dfde132ba8ac09307b99759851a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 4 Oct 2021 20:28:49 +0200 Subject: [PATCH] Show text on the Browse button --- Common/UI/View.cpp | 22 +++++++++++++++------- UI/MainScreen.cpp | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index da693298e4..ad3f3be361 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -431,10 +431,15 @@ void Choice::Click() { } void Choice::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const { + float totalW = 0.0f; + float totalH = 0.0f; if (image_.isValid()) { dc.Draw()->GetAtlas()->measureImage(image_, &w, &h); - } else { - const int paddingX = 12; + totalW = w; + totalH = h; + } + if (!text_.empty()) { + const int paddingX = 12 + (image_.isValid() ? 6 : 0); float availWidth = horiz.size - paddingX * 2 - textPadding_.horiz(); if (availWidth < 0.0f) { // Let it have as much space as it needs. @@ -444,10 +449,13 @@ void Choice::GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, availWidth = layoutParams_->width; float scale = CalculateTextScale(dc, availWidth); Bounds availBounds(0, 0, availWidth, vert.size); - dc.MeasureTextRect(dc.theme->uiFont, scale, scale, text_.c_str(), (int)text_.size(), availBounds, &w, &h, FLAG_WRAP_TEXT); + float textW = 0.0f, textH = 0.0f; + dc.MeasureTextRect(dc.theme->uiFont, scale, scale, text_.c_str(), (int)text_.size(), availBounds, &textW, &textH, FLAG_WRAP_TEXT); + totalH = std::max(totalH, textH); + totalW += textW; } - w += 24; - h += 16; + w = totalW + 24; + h = totalH + 16; h = std::max(h, ITEM_HEIGHT); } @@ -498,8 +506,8 @@ void Choice::Draw(UIContext &dc) { if (image_.isValid()) { const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(image_); - paddingX += image->w + 12; - availWidth -= image->w + 12; + paddingX += image->w + 6; + availWidth -= image->w + 6; // TODO: Use scale rotation and flip here as well (DrawImageRotated is always ALIGN_CENTER for now) dc.Draw()->DrawImage(image_, bounds_.x + 6, bounds_.centerY(), 1.0f, 0xFFFFFFFF, ALIGN_LEFT | ALIGN_VCENTER); } diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index d049ce9b7a..4e86ac1abb 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -680,7 +680,7 @@ void GameBrowser::Refresh() { topBar->Add(new Choice(ImageID("I_SDCARD"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::StorageClick); } if (System_GetPropertyBool(SYSPROP_HAS_FOLDER_BROWSER)) { - topBar->Add(new Choice(ImageID("I_FOLDER_OPEN"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick); + topBar->Add(new Choice(mm->T("Browse"), ImageID("I_FOLDER_OPEN"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::BrowseClick); } } else { topBar->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 64.0f, 1.0f)));