From 4c3bb93dc33eba75cae7e7d79e12c3408a20a3ca Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 25 Aug 2026 21:09:02 +0300 Subject: [PATCH] fix Panel::cropToContent --- src/graphics/ui/elements/Panel.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/graphics/ui/elements/Panel.cpp b/src/graphics/ui/elements/Panel.cpp index 26401ee10..8f023fbd6 100644 --- a/src/graphics/ui/elements/Panel.cpp +++ b/src/graphics/ui/elements/Panel.cpp @@ -39,15 +39,24 @@ glm::vec2 Panel::getContentSize() const { } void Panel::cropToContent() { + int maxInt = std::numeric_limits::max(); + bool isHorizontal = orientation == Orientation::HORIZONTAL; + + int minLengthX = isHorizontal ? minLength : 0; + int maxLengthX = isHorizontal ? maxLength : maxInt; + + int minLengthY = isHorizontal ? 0 : minLength; + int maxLengthY = isHorizontal ? maxInt : maxLength; + if (maxLength > 0.0f) { setSize(glm::vec2( - glm::max(minLength, glm::min(maxLength, actualLengthX)), - glm::max(minLength, glm::min(maxLength, actualLengthY)) + glm::max(minLengthX, glm::min(maxLengthX, actualLengthX)), + glm::max(minLengthY, glm::min(maxLengthY, actualLengthY)) )); } else { setSize(glm::vec2( - glm::max(minLength, actualLengthX), - glm::max(minLength, actualLengthY) + glm::max(minLengthX, actualLengthX), + glm::max(minLengthY, actualLengthY) )); } }