Debugger: fix width of alert for short messages

Don't force a larger min size if the message is short enough.

To do this:
- Get the TextRect without word wrapping
- If that is small enough, nothing to do
- If that is too wide, set a minimal size that will be used for the word wrapping so the alert
  doesn't get too large and also doesn't get too narrow

Fixes #18404

Change-Id: Iee2704377180510edf7bdf930583b8a7cc47ef2e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6461
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
PulkoMandy 2023-05-20 14:15:06 +02:00 committed by waddlesplash
parent ef240bfffa
commit 6a06a56256

View File

@ -58,11 +58,15 @@ AlertWithCheckbox::AlertWithCheckbox(const char* title, const char* messageText,
message->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor); message->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor);
message->MakeEditable(false); message->MakeEditable(false);
message->MakeSelectable(false); message->MakeSelectable(false);
message->SetWordWrap(true);
message->SetText(messageText); message->SetText(messageText);
BRect textRect = message->TextRect();
textRect.PrintToStream();
message->SetWordWrap(true);
message->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNSET)); message->SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNSET));
float width = message->StringWidth("W") * 40; float width = message->StringWidth("W") * 40;
message->SetExplicitMinSize(BSize(width, B_SIZE_UNSET)); if (width < textRect.Width()) {
message->SetExplicitMinSize(BSize(width, B_SIZE_UNSET));
}
fDontAskAgain = new BCheckBox("checkbox", fDontAskAgain = new BCheckBox("checkbox",
checkboxLabel, NULL); checkboxLabel, NULL);