LibGUI: GTabWidget should not set children to have negative size

This could happen if a child was added to a GTabWidget before the
GTabWidget had its first layout.

Also add an assertion to catch this in GWidget::set_relative_rect()
since it was not immediately obvious what was happening.
This commit is contained in:
Andreas Kling 2019-10-23 19:51:09 +02:00
parent 93dff5df34
commit b916e34fed
Notes: sideshowbarker 2024-07-19 11:34:14 +09:00
2 changed files with 10 additions and 3 deletions

View file

@ -45,13 +45,18 @@ void GTabWidget::resize_event(GResizeEvent& event)
Rect GTabWidget::child_rect_for_size(const Size& size) const
{
Rect rect;
switch (m_tab_position) {
case TabPosition::Top:
return { { container_padding(), bar_height() + container_padding() }, { size.width() - container_padding() * 2, size.height() - bar_height() - container_padding() * 2 } };
rect = { { container_padding(), bar_height() + container_padding() }, { size.width() - container_padding() * 2, size.height() - bar_height() - container_padding() * 2 } };
break;
case TabPosition::Bottom:
return { { container_padding(), container_padding() }, { size.width() - container_padding() * 2, size.height() - bar_height() - container_padding() * 2 } };
rect = { { container_padding(), container_padding() }, { size.width() - container_padding() * 2, size.height() - bar_height() - container_padding() * 2 } };
break;
}
ASSERT_NOT_REACHED();
if (rect.is_empty())
return {};
return rect;
}
void GTabWidget::child_event(CChildEvent& event)

View file

@ -44,6 +44,8 @@ void GWidget::child_event(CChildEvent& event)
void GWidget::set_relative_rect(const Rect& rect)
{
ASSERT(rect.width() >= 0 && rect.height() >= 0);
if (rect == m_relative_rect)
return;