From a3e22cdaa790630f5a82a086c25cfc5e843e260c Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 8 Sep 2018 19:49:03 -0400 Subject: [PATCH] Installer: Rework status message view sizing logic. * Make the status message view have a minimum height of the logo view's height. * Properly add the views to the BGroupView layout. * Instead of trying to set the explicit minimum size from the status view information, just invalidate the GroupLayout. This seems to fix a number of bugs relating to text overflowing the view, while it doesn't fix others (e.g. orphan words on their own lines are still not drawn in some cases, which appears to be a BTextView bug.) * Use BString::SetToFormat instead of snprintf in some places. As far as I can make out, fixes #13608. --- src/apps/installer/InstallerWindow.cpp | 35 +++++++++++--------------- src/apps/installer/InstallerWindow.h | 2 ++ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/apps/installer/InstallerWindow.cpp b/src/apps/installer/InstallerWindow.cpp index eb36bf3cce..603d7963bd 100644 --- a/src/apps/installer/InstallerWindow.cpp +++ b/src/apps/installer/InstallerWindow.cpp @@ -181,14 +181,14 @@ InstallerWindow::InstallerWindow() BSize logoSize = logoView->MinSize(); logoView->SetExplicitMaxSize(logoSize); fStatusView->SetExplicitMinSize(BSize(logoSize.width * 0.8, - B_SIZE_UNSET)); + logoSize.height)); // Explicitly create group view to set the background white in case // height resizing is needed for the status view - BGroupView* logoGroup = new BGroupView(B_HORIZONTAL, 0); - logoGroup->SetViewColor(255, 255, 255); - logoGroup->AddChild(logoView); - logoGroup->AddChild(fStatusView); + fLogoGroup = new BGroupView(B_HORIZONTAL, 0); + fLogoGroup->SetViewColor(255, 255, 255); + fLogoGroup->GroupLayout()->AddView(logoView); + fLogoGroup->GroupLayout()->AddView(fStatusView); fDestMenu = new BPopUpMenu(B_TRANSLATE("scanning" B_UTF8_ELLIPSIS), true, false); @@ -252,7 +252,7 @@ InstallerWindow::InstallerWindow() BLayoutBuilder::Group<>(this, B_VERTICAL, 0) .Add(mainMenu) - .Add(logoGroup) + .Add(fLogoGroup) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) .AddGroup(B_VERTICAL, B_USE_ITEM_SPACING) .SetInsets(B_USE_WINDOW_SPACING) @@ -496,10 +496,10 @@ InstallerWindow::MessageReceived(BMessage *msg) PartitionMenuItem* dstItem = (PartitionMenuItem*)fDestMenu->FindMarked(); - char status[1024]; + BString status; if (be_roster->IsRunning(kDeskbarSignature)) { fBeginButton->SetLabel(B_TRANSLATE("Quit")); - snprintf(status, sizeof(status), B_TRANSLATE("Installation " + status.SetToFormat(B_TRANSLATE("Installation " "completed. Boot sector has been written to '%s'. Press " "Quit to leave the Installer or choose a new target " "volume to perform another installation."), @@ -507,7 +507,7 @@ InstallerWindow::MessageReceived(BMessage *msg) "Unknown partition name")); } else { fBeginButton->SetLabel(B_TRANSLATE("Restart")); - snprintf(status, sizeof(status), B_TRANSLATE("Installation " + status.SetToFormat(B_TRANSLATE("Installation " "completed. Boot sector has been written to '%s'. Press " "Restart to restart the computer or choose a new target " "volume to perform another installation."), @@ -515,7 +515,7 @@ InstallerWindow::MessageReceived(BMessage *msg) "Unknown partition name")); } - _SetStatusMessage(status); + _SetStatusMessage(status.String()); fInstallStatus = kFinished; _DisableInterface(false); fProgressLayoutItem->SetVisible(false); @@ -787,10 +787,10 @@ InstallerWindow::_UpdateControls() fDestMenuField->MenuItem()->SetLabel(label.String()); if (srcItem != NULL && dstItem != NULL) { - char message[255]; - sprintf(message, B_TRANSLATE("Press the Begin button to install from " - "'%1s' onto '%2s'."), srcItem->Name(), dstItem->Name()); - _SetStatusMessage(message); + BString message; + message.SetToFormat(B_TRANSLATE("Press the Begin button to install " + "from '%1s' onto '%2s'."), srcItem->Name(), dstItem->Name()); + _SetStatusMessage(message.String()); } else if (srcItem != NULL) { _SetStatusMessage(B_TRANSLATE("Choose the disk you want to install " "onto from the pop-up menu. Then click \"Begin\".")); @@ -872,12 +872,7 @@ void InstallerWindow::_SetStatusMessage(const char *text) { fStatusView->SetText(text); - - // Make the status view taller if needed - BSize size = fStatusView->ExplicitMinSize(); - float heightNeeded = fStatusView->TextHeight(0, fStatusView->CountLines()) + 15.0; - if (heightNeeded > size.height) - fStatusView->SetExplicitMinSize(BSize(size.width, heightNeeded)); + fLogoGroup->GroupLayout()->InvalidateLayout(); } diff --git a/src/apps/installer/InstallerWindow.h b/src/apps/installer/InstallerWindow.h index d6be378153..d5caf46f7a 100644 --- a/src/apps/installer/InstallerWindow.h +++ b/src/apps/installer/InstallerWindow.h @@ -18,6 +18,7 @@ using namespace BPrivate; class BButton; class BLayoutItem; +class BGroupView; class BMenu; class BMenuField; class BMenuItem; @@ -60,6 +61,7 @@ private: static int _ComparePackages(const void* firstArg, const void* secondArg); + BGroupView* fLogoGroup; BTextView* fStatusView; BMenu* fSrcMenu; BMenu* fDestMenu;