1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 07:07:34 +00:00

LibGUI: Implement calculated min/preferred sizes for TabWidget

This commit is contained in:
FrHun 2022-07-04 05:39:24 +02:00 committed by Andreas Kling
parent 309874b4fb
commit ccdccadc24
2 changed files with 32 additions and 0 deletions

View file

@ -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;