From 9cfe1443266e511b0a9fe9c8514655f280cf1b63 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sun, 10 May 2020 17:48:50 -0400 Subject: [PATCH] BCardLayout: Do not recompute size limits on visible item switch. The size limits are already the minimum/maximum for all views, not just the current one, so we do not need to recompute them when the layout is invalidated due to an item switch. Fixes #14675, and other performance issues on switching tabs in layouted BTabViews, among other things. Change-Id: I55bfe4ddb8c8a79c634634cfc27113205a790c42 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2677 Reviewed-by: Andrew Lindesay --- src/kits/interface/CardLayout.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/kits/interface/CardLayout.cpp b/src/kits/interface/CardLayout.cpp index c41e2a4e62..cd8e2462c5 100644 --- a/src/kits/interface/CardLayout.cpp +++ b/src/kits/interface/CardLayout.cpp @@ -78,16 +78,20 @@ BCardLayout::SetVisibleItem(BLayoutItem* item) return; } + // Changing an item's visibility will invalidate its parent's layout (us), + // which would normally cause the min-max to be re-computed. But in this + // case, that is unnecessary, and so we can skip it. + const bool minMaxValid = fMinMaxValid; + if (fVisibleItem != NULL) fVisibleItem->SetVisible(false); fVisibleItem = item; - if (fVisibleItem != NULL) { + if (fVisibleItem != NULL) fVisibleItem->SetVisible(true); - Relayout(); - } + fMinMaxValid = minMaxValid; } @@ -274,6 +278,8 @@ BCardLayout::ItemAdded(BLayoutItem* item, int32 atIndex) void BCardLayout::ItemRemoved(BLayoutItem* item, int32 fromIndex) { + fMinMaxValid = false; + if (fVisibleItem == item) { BLayoutItem* newVisibleItem = NULL; SetVisibleItem(newVisibleItem);