diff --git a/Common/UI/UIScreen.cpp b/Common/UI/UIScreen.cpp index c56d09856a..ff30080553 100644 --- a/Common/UI/UIScreen.cpp +++ b/Common/UI/UIScreen.cpp @@ -814,7 +814,7 @@ void AbstractChoiceWithValueDisplay::GetContentDimensionsBySpec(const UIContext const std::string valueText = ValueText(); int paddingX = 12; // Assume we want at least 20% of the size for the label, at a minimum. - float availWidth = (horiz.size - paddingX * 2) * 0.8f; + float availWidth = (horiz.size - paddingX * 2) * (text_.empty() ? 1.0f : 0.8f); if (availWidth < 0) { availWidth = 65535.0f; } @@ -826,11 +826,15 @@ void AbstractChoiceWithValueDisplay::GetContentDimensionsBySpec(const UIContext valueW += paddingX; // Give the choice itself less space to grow in, so it shrinks if needed. - MeasureSpec horizLabel = horiz; - horizLabel.size -= valueW; + // MeasureSpec horizLabel = horiz; + // horizLabel.size -= valueW; Choice::GetContentDimensionsBySpec(dc, horiz, vert, w, h); w += valueW; + // Fill out anyway if there's space. + if (horiz.type == AT_MOST && w < horiz.size) { + w = horiz.size; + } h = std::max(h, valueH); } diff --git a/Common/UI/UIScreen.h b/Common/UI/UIScreen.h index 4b113d3001..d1f483f0fc 100644 --- a/Common/UI/UIScreen.h +++ b/Common/UI/UIScreen.h @@ -463,8 +463,8 @@ public: private: std::string ValueText() const override; - int *iValue_ = nullptr; std::string *sValue_ = nullptr; + int *iValue_ = nullptr; const char *category_ = nullptr; std::string (*translateCallback_)(const char *value) = nullptr; }; diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 87ae8a640a..48d6de8abf 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -414,7 +414,8 @@ void ClickableItem::GetContentDimensions(const UIContext &dc, float &w, float &h } ClickableItem::ClickableItem(LayoutParams *layoutParams) : Clickable(layoutParams) { - if (!layoutParams && autoExpand_) { + if (!layoutParams) { + // The default LayoutParams assigned by View::View defaults to WRAP_CONTENT/WRAP_CONTENT. if (layoutParams_->width == WRAP_CONTENT) layoutParams_->width = FILL_PARENT; } diff --git a/Common/UI/View.h b/Common/UI/View.h index fb26db156f..64c9cdacf8 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -692,11 +692,6 @@ public: // Draws the item background. void Draw(UIContext &dc) override; - - void SetAutoExpand(bool autoExpand) { autoExpand_ = autoExpand; } - -private: - bool autoExpand_ = true; }; // Use to trigger something or open a submenu screen. diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index 9c7960f2fe..f32bd6fd37 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -514,8 +514,9 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v float sum = 0.0f; float maxOther = 0.0f; float totalWeight = 0.0f; - float weightSum = 0.0f; - float weightZeroSum = 0.0f; + + float weightSum = 0.0f; // Total sum of weights + float weightZeroSum = 0.0f; // Sum of sizes of things with weight 0.0, a bit confusingly named int numVisible = 0; @@ -593,8 +594,11 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v for (View *view : views_) { if (view->GetVisibility() == V_GONE) continue; - const LinearLayoutParams *linLayoutParams = view->GetLayoutParams()->As(); + // FILL_PARENT is not appropriate in this direction. It gets ignored though. + // We have a bit too many of these due to the hack in the ClickableItem constructor. + // _dbg_assert_(view->GetLayoutParams()->width != UI::FILL_PARENT); + const LinearLayoutParams *linLayoutParams = view->GetLayoutParams()->As(); if (linLayoutParams && linLayoutParams->weight > 0.0f) { Margins margins = defaultMargins_; if (linLayoutParams->HasMargins()) @@ -638,8 +642,11 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v for (View *view : views_) { if (view->GetVisibility() == V_GONE) continue; - const LinearLayoutParams *linLayoutParams = view->GetLayoutParams()->As(); + // FILL_PARENT is not appropriate in this direction. It gets ignored though. + // We have a bit too many of these due to the hack in the ClickableItem constructor. + // _dbg_assert_(view->GetLayoutParams()->height != UI::FILL_PARENT); + const LinearLayoutParams *linLayoutParams = view->GetLayoutParams()->As(); if (linLayoutParams && linLayoutParams->weight > 0.0f) { Margins margins = defaultMargins_; if (linLayoutParams->HasMargins()) @@ -649,6 +656,7 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v h = MeasureSpec(AT_MOST, measuredWidth_); float unit = (allowedHeight - weightZeroSum) / weightSum; if (weightSum == 0.0f) { + // We must have gotten an inf. unit = 1.0f; } MeasureSpec v(AT_MOST, unit * linLayoutParams->weight - margins.vert()); diff --git a/UI/DisplayLayoutScreen.cpp b/UI/DisplayLayoutScreen.cpp index fd80fa8daf..cb20889c13 100644 --- a/UI/DisplayLayoutScreen.cpp +++ b/UI/DisplayLayoutScreen.cpp @@ -271,13 +271,11 @@ void DisplayLayoutScreen::CreateViews() { // Vector element pointer get invalidated on resize, cache name to have always a valid reference in the rendering thread shaderNames_[i] = i == g_Config.vPostShaderNames.size() ? "Off" : g_Config.vPostShaderNames[i]; - // TODO: I want to set UI::FILL_PARENT or an explicit width here, but breaks badly??? - LinearLayout *shaderRow = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(UI::WRAP_CONTENT, UI::WRAP_CONTENT)); + LinearLayout *shaderRow = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(UI::FILL_PARENT, UI::WRAP_CONTENT)); shaderRow->SetSpacing(4.0f); leftColumn->Add(shaderRow); postProcChoice_ = shaderRow->Add(new ChoiceWithValueDisplay(&shaderNames_[i], "", &PostShaderTranslateName, new LinearLayoutParams(1.0f))); - postProcChoice_->SetAutoExpand(false); postProcChoice_->OnClick.Add([=](EventParams &e) { auto gr = GetI18NCategory("Graphics"); auto procScreen = new PostProcScreen(gr->T("Postprocessing Shader"), i, false); @@ -305,7 +303,7 @@ void DisplayLayoutScreen::CreateViews() { } } if (hasSettings) { - auto settingsButton = shaderRow->Add(new Choice(ImageID("I_SLIDERS"))); + auto settingsButton = shaderRow->Add(new Choice(ImageID("I_SLIDERS"), new LinearLayoutParams(0.0f))); settingsButton->OnClick.Add([=](EventParams &e) { settingsVisible_[i] = !settingsVisible_[i]; RecreateViews(); @@ -315,7 +313,7 @@ void DisplayLayoutScreen::CreateViews() { } if (i > 0 && i < g_Config.vPostShaderNames.size()) { - auto upButton = shaderRow->Add(new Choice(ImageID("I_ARROW_UP"))); + auto upButton = shaderRow->Add(new Choice(ImageID("I_ARROW_UP"), new LinearLayoutParams(0.0f))); upButton->OnClick.Add([=](EventParams &e) { std::swap(g_Config.vPostShaderNames[i - 1], g_Config.vPostShaderNames[i]); RecreateViews(); @@ -323,7 +321,7 @@ void DisplayLayoutScreen::CreateViews() { }); } if (i < g_Config.vPostShaderNames.size() - 1) { - auto downButton = shaderRow->Add(new Choice(ImageID("I_ARROW_DOWN"))); + auto downButton = shaderRow->Add(new Choice(ImageID("I_ARROW_DOWN"), new LinearLayoutParams(0.0f))); downButton->OnClick.Add([=](EventParams &e) { std::swap(g_Config.vPostShaderNames[i], g_Config.vPostShaderNames[i + 1]); RecreateViews(); @@ -331,7 +329,7 @@ void DisplayLayoutScreen::CreateViews() { }); } if (i < g_Config.vPostShaderNames.size()) { - auto deleteButton = shaderRow->Add(new Choice(ImageID("I_TRASHCAN"))); + auto deleteButton = shaderRow->Add(new Choice(ImageID("I_TRASHCAN"), new LinearLayoutParams(0.0f))); deleteButton->OnClick.Add([=](EventParams &e) { g_Config.vPostShaderNames.erase(g_Config.vPostShaderNames.begin() + i); RecreateViews(); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 055d1ead17..3c5c6a1b24 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1064,7 +1064,7 @@ void TakeScreenshot() { } void RenderOverlays(UIContext *dc, void *userdata) { - // Thin bar at the top of the screen like Chrome. + // Thin bar at the top of the screen. std::vector progress = g_DownloadManager.GetCurrentProgress(); if (!progress.empty()) { static const uint32_t colors[4] = { @@ -1091,8 +1091,8 @@ void RenderOverlays(UIContext *dc, void *userdata) { } void NativeRender(GraphicsContext *graphicsContext) { - _assert_(graphicsContext != nullptr); - _assert_(screenManager != nullptr); + _dbg_assert_(graphicsContext != nullptr); + _dbg_assert_(screenManager != nullptr); g_GameManager.Update();