From b6462b19a90c2bb9571ce799bb5accfddb7869b2 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 11 Jan 2021 13:58:20 +0000 Subject: [PATCH] When flow layout hasn't been visible, be conservative with its size * Because the flow layout adjusts to its available size, we instead set it to minimum size until it's first laid out. Otherwise it can get unreasonably sized. --- qrenderdoc/3rdparty/flowlayout/FlowLayout.cpp | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/qrenderdoc/3rdparty/flowlayout/FlowLayout.cpp b/qrenderdoc/3rdparty/flowlayout/FlowLayout.cpp index cd11ce9b3..619dd0965 100644 --- a/qrenderdoc/3rdparty/flowlayout/FlowLayout.cpp +++ b/qrenderdoc/3rdparty/flowlayout/FlowLayout.cpp @@ -125,6 +125,8 @@ bool FlowLayout::hasHeightForWidth() const int FlowLayout::heightForWidth(int width) const { + if(m_prevRect.isEmpty()) + return minimumSize().height(); int height = doLayout(QRect(0, 0, width, 0), true); return height; } @@ -144,6 +146,8 @@ void FlowLayout::setGeometry(const QRect &rect) QSize FlowLayout::sizeHint() const { + if(m_prevRect.isEmpty()) + return minimumSize(); QSize size = geometry().size(); size.setHeight(doLayout(geometry().adjusted(0, 0, -10, 0), true)); return size; @@ -158,14 +162,17 @@ QSize FlowLayout::minimumSize() const size += QSize(2*margin(), 2*margin()); - // we use the previous height as a hint for the minimum size otherwise we'll never request - // enough height for multiple rows - size.setHeight(qMax(size.height(), heightForWidth(m_prevRect.width()))); + if(!m_prevRect.isEmpty()) + { + // we use the previous height as a hint for the minimum size otherwise we'll never request + // enough height for multiple rows + size.setHeight(qMax(size.height(), heightForWidth(m_prevRect.width()))); - // we use the previous width as a minimum, otherwise if we have a long item which expands - // up to a large width in our minimum, other layouts might starve us of enough height - // because it will assume we are sized to the minimum. - size.setWidth(qMin(size.width(), m_prevRect.width())); + // we use the previous width as a minimum, otherwise if we have a long item which expands + // up to a large width in our minimum, other layouts might starve us of enough height + // because it will assume we are sized to the minimum. + size.setWidth(qMin(size.width(), m_prevRect.width())); + } return size; }