summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorFrHun <28605587+frhun@users.noreply.github.com>2022-07-04 05:39:24 +0200
committerAndreas Kling <kling@serenityos.org>2022-07-04 11:15:40 +0200
commitccdccadc2416a2eba322bf0a352a0c8686713ca0 (patch)
treecb41b51936513231eb7af4b17b7d6da675ded2cf /Userland
parent309874b4fb4c34bc894531337289a6a4755dfa98 (diff)
downloadserenity-ccdccadc2416a2eba322bf0a352a0c8686713ca0.zip
LibGUI: Implement calculated min/preferred sizes for TabWidget
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/TabWidget.cpp29
-rw-r--r--Userland/Libraries/LibGUI/TabWidget.h3
2 files changed, 32 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/TabWidget.cpp b/Userland/Libraries/LibGUI/TabWidget.cpp
index 36e78712f7..03833486b2 100644
--- a/Userland/Libraries/LibGUI/TabWidget.cpp
+++ b/Userland/Libraries/LibGUI/TabWidget.cpp
@@ -7,6 +7,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/GenericShorthands.h>
#include <AK/JsonValue.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Painter.h>
@@ -690,6 +691,34 @@ void TabWidget::set_container_margins(GUI::Margins const& margins)
update();
}
+Optional<UISize> TabWidget::calculated_min_size() const
+{
+ if (!m_active_widget)
+ return {};
+ auto content_min_size = m_active_widget->effective_min_size();
+ UIDimension width = MUST(content_min_size.width().shrink_value()), height = MUST(content_min_size.height().shrink_value());
+ width.add_if_int(container_margins().vertical_total()
+ + (first_is_one_of(m_tab_position, TabPosition::Left, TabPosition::Right) ? bar_rect().width() : 0));
+ height.add_if_int(container_margins().vertical_total()
+ + (first_is_one_of(m_tab_position, TabPosition::Top, TabPosition::Bottom) ? bar_rect().height() : 0));
+
+ return UISize { width, height };
+}
+
+Optional<UISize> TabWidget::calculated_preferred_size() const
+{
+ if (!m_active_widget)
+ return {};
+ auto content_preferred_size = m_active_widget->effective_preferred_size();
+ UIDimension width = MUST(content_preferred_size.width().shrink_value()), height = MUST(content_preferred_size.height().shrink_value());
+ width.add_if_int(container_margins().vertical_total()
+ + (first_is_one_of(m_tab_position, TabPosition::Left, TabPosition::Right) ? bar_rect().width() : 0));
+ height.add_if_int(
+ container_margins().vertical_total()
+ + (first_is_one_of(m_tab_position, TabPosition::Top, TabPosition::Bottom) ? bar_rect().height() : 0));
+ return UISize { width, height };
+}
+
void TabWidget::drag_tab(size_t index)
{
m_dragging_active_tab = m_reorder_allowed;
diff --git a/Userland/Libraries/LibGUI/TabWidget.h b/Userland/Libraries/LibGUI/TabWidget.h
index e98961eaae..de1621415f 100644
--- a/Userland/Libraries/LibGUI/TabWidget.h
+++ b/Userland/Libraries/LibGUI/TabWidget.h
@@ -47,6 +47,9 @@ public:
GUI::Margins const& container_margins() const { return m_container_margins; }
void set_container_margins(GUI::Margins const&);
+ Optional<UISize> calculated_min_size() const override;
+ Optional<UISize> calculated_preferred_size() const override;
+
ErrorOr<void> try_add_widget(Widget&);
void add_widget(Widget&);