summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorKarol Kosek <krkk@serenityos.org>2022-05-10 00:11:52 +0200
committerAndreas Kling <kling@serenityos.org>2022-05-11 20:24:38 +0200
commitea99589d042af8f3ac3c1dace8213b683cd447ac (patch)
treef2c4c9701bc047e49f8cda389ccb20e7886453a2 /Userland
parent84b98da2594aa32ed37a7d33f8fbb2e28cbf9e15 (diff)
downloadserenity-ea99589d042af8f3ac3c1dace8213b683cd447ac.zip
LibGUI: Take only valid sizes when calculating BoxLayout preferred size
We ran a min() function to clamp child widgets to their maximum size, but if it wasn't set, it got -1 and made the widget able to shrink completely.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/BoxLayout.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGUI/BoxLayout.cpp b/Userland/Libraries/LibGUI/BoxLayout.cpp
index d483fcf965..6a6ea8dccf 100644
--- a/Userland/Libraries/LibGUI/BoxLayout.cpp
+++ b/Userland/Libraries/LibGUI/BoxLayout.cpp
@@ -39,15 +39,17 @@ int BoxLayout::preferred_primary_size() const
for (auto& entry : m_entries) {
if (!entry.widget || !entry.widget->is_visible())
continue;
- int min_size = entry.widget->min_size().primary_size_for_orientation(orientation());
- int max_size = entry.widget->max_size().primary_size_for_orientation(orientation());
int preferred_primary_size = -1;
if (entry.widget->is_shrink_to_fit() && entry.widget->layout()) {
preferred_primary_size = entry.widget->layout()->preferred_size().primary_size_for_orientation(orientation());
}
int item_size = max(0, preferred_primary_size);
- item_size = max(min_size, item_size);
- item_size = min(max_size, item_size);
+ int min_size = entry.widget->min_size().primary_size_for_orientation(orientation());
+ if (min_size != -1)
+ item_size = max(min_size, item_size);
+ int max_size = entry.widget->max_size().primary_size_for_orientation(orientation());
+ if (max_size != -1)
+ item_size = min(max_size, item_size);
size += item_size + spacing();
}
if (size > 0)