From 99b4affab6fbabb0917abd76cb9a08b55a128e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 30 Jul 2015 18:27:13 +0200 Subject: [PATCH] Added BWindow::ResizeToPreferred(). * B_AUTO_UPDATE_SIZE_LIMITS only really makes sense for resizable windows, and it only sets the minimum/maximum window size. * ResizeToPreferred() resizes the window to its preferred size, and also supports height-for-width layouts. --- headers/os/interface/Window.h | 1 + src/kits/interface/Window.cpp | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/headers/os/interface/Window.h b/headers/os/interface/Window.h index b4df13e925..dbf0431516 100644 --- a/headers/os/interface/Window.h +++ b/headers/os/interface/Window.h @@ -165,6 +165,7 @@ public: void MoveTo(float x, float y); void ResizeBy(float dx, float dy); void ResizeTo(float width, float height); + void ResizeToPreferred(); void CenterIn(const BRect& rect); void CenterOnScreen(); diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index bcd07de4fb..141e4891bc 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -2521,7 +2521,26 @@ BWindow::ResizeTo(float width, float height) } -// Center the window in the passed in rect. +void +BWindow::ResizeToPreferred() +{ + Layout(false); + + float width = fTopView->PreferredSize().width; + width = std::min(width, fTopView->MaxSize().width); + width = std::max(width, fTopView->MinSize().width); + + float height = fTopView->PreferredSize().height; + height = std::min(width, fTopView->MaxSize().height); + height = std::max(width, fTopView->MinSize().height); + + if (GetLayout()->HasHeightForWidth()) + GetLayout()->GetHeightForWidth(width, NULL, NULL, &height); + + ResizeTo(width, height); +} + + void BWindow::CenterIn(const BRect& rect) { @@ -2534,7 +2553,6 @@ BWindow::CenterIn(const BRect& rect) } -// Centers the window on the screen the window is currently on. void BWindow::CenterOnScreen() {