From 146a80c1cf6dca883d28aa1693078d700104ee57 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 16 Jul 2018 22:50:18 -0400 Subject: [PATCH] HaikuDepot: Refactor & fix layout initialization in RatingItemView. BLayoutBuilder is designed for single-shot use; i.e., a "one-liner" of .AddLayout(), .Add(), and .End()s and no variable storage. This is basically the only coherent way to use the class, as otherwise it becomes unclear what state it's even in, and in the case of functions like these with multiple branches for different options, that is doubly true. It seems that in certain cases, the final SetInsets() after the End() was winding up one before the "beginning" of the builder and thus attempting to set the insets of NULL. Rather than analyze the function to determine under what control-flow this occured (since it only happened for some packages, and not others), I've opted here for the more systemic solution to remove usage of BLayoutBuilder entirely, and just create straight BLayouts. Fixes #14214. --- src/apps/haikudepot/ui/PackageInfoView.cpp | 30 ++++++++++------------ 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/apps/haikudepot/ui/PackageInfoView.cpp b/src/apps/haikudepot/ui/PackageInfoView.cpp index 59c54020ab..b390109fa8 100644 --- a/src/apps/haikudepot/ui/PackageInfoView.cpp +++ b/src/apps/haikudepot/ui/PackageInfoView.cpp @@ -874,25 +874,24 @@ public: { SetViewUIColor(B_PANEL_BACKGROUND_COLOR, kContentTint); - BLayoutBuilder::Group > verticalGroup = - BLayoutBuilder::Group<>(this) - .AddGroup(B_VERTICAL, 0.0f); + BGroupLayout* verticalGroup = new BGroupLayout(B_VERTICAL, 0.0f); + GroupLayout()->AddItem(verticalGroup); { BStringView* userNicknameView = new BStringView("user-nickname", rating.User().NickName()); userNicknameView->SetFont(be_bold_font); - verticalGroup.Add(userNicknameView); + verticalGroup->AddView(userNicknameView); } - BLayoutBuilder::Group > > ratingGroup = - verticalGroup.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING); + BGroupLayout* ratingGroup = + new BGroupLayout(B_HORIZONTAL, B_USE_DEFAULT_SPACING); + verticalGroup->AddItem(ratingGroup); if (rating.Rating() >= 0) { RatingView* ratingView = new RatingView("package rating view"); ratingView->SetRating(rating.Rating()); - ratingGroup.Add(ratingView); + ratingGroup->AddView(ratingView); } { @@ -913,11 +912,10 @@ public: ratingContextDescription); BFont versionFont(be_plain_font); ratingContextView->SetFont(&versionFont); - ratingGroup.Add(ratingContextView); + ratingGroup->AddView(ratingContextView); } - ratingGroup.AddGlue(); - ratingGroup.End(); + ratingGroup->AddItem(BSpaceLayoutItem::CreateGlue()); if (rating.Comment() > 0) { TextView* textView = new TextView("rating-text"); @@ -925,14 +923,12 @@ public: paragraphStyle.SetJustify(true); textView->SetParagraphStyle(paragraphStyle); textView->SetText(rating.Comment()); - verticalGroup.AddStrut(8.0f); - verticalGroup.Add(textView); - verticalGroup.AddStrut(8.0f); + verticalGroup->AddItem(BSpaceLayoutItem::CreateVerticalStrut(8.0f)); + verticalGroup->AddView(textView); + verticalGroup->AddItem(BSpaceLayoutItem::CreateVerticalStrut(8.0f)); } - verticalGroup - .End() - .SetInsets(B_USE_DEFAULT_SPACING); + verticalGroup->SetInsets(B_USE_DEFAULT_SPACING); SetFlags(Flags() | B_WILL_DRAW); }