hrev53865 adds 1 changeset to branch 'master'
old head: 299279610c0354caf0cdf83dc0760b5c53e4dc01
new head: 3d11fed20977284b0769147024dc7a48aa98e7fd
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=3d11fed20977+%5E299279610c03
----------------------------------------------------------------------------
3d11fed20977: Installer: fix drawing of optional packages view
Rework the layout of the installer window, do not try to put everything
in a single grid but instead use a mix of grid and groups as
appropriate, which keeps things simpler.
Make the width of the window more font sensitive.
Have the package view properly resize with the window, and the items in
it still draw properly (checkbox and name on the left, size on the
right)
The menu fields for source and destination don't need to extend to the
whole window width, so allow them to be smaller.
Fixes #5785
Change-Id: If0683f610b9e7f3629d51d25c1d8e8b00c101156
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2185
Reviewed-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
[ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev53865
Commit: 3d11fed20977284b0769147024dc7a48aa98e7fd
URL: https://git.haiku-os.org/haiku/commit/?id=3d11fed20977
Author: Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date: Mon Feb 3 15:53:46 2020 UTC
Committer: Adrien Destugues <pulkomandy@xxxxxxxxx>
Commit-Date: Mon Feb 10 09:49:51 2020 UTC
Ticket: https://dev.haiku-os.org/ticket/5785
----------------------------------------------------------------------------
3 files changed, 58 insertions(+), 113 deletions(-)
src/apps/installer/InstallerWindow.cpp | 46 ++++++------
src/apps/installer/PackageViews.cpp | 114 +++++++++--------------------
src/apps/installer/PackageViews.h | 11 +--
----------------------------------------------------------------------------
diff --git a/src/apps/installer/InstallerWindow.cpp
b/src/apps/installer/InstallerWindow.cpp
index ed8d9fdde9..897f4d7f58 100644
--- a/src/apps/installer/InstallerWindow.cpp
+++ b/src/apps/installer/InstallerWindow.cpp
@@ -179,7 +179,7 @@ InstallerWindow::InstallerWindow()
BSize logoSize = logoView->MinSize();
logoView->SetExplicitMaxSize(logoSize);
- fStatusView->SetExplicitMinSize(BSize(fStatusView->StringWidth("W") *
30,
+ fStatusView->SetExplicitMinSize(BSize(fStatusView->StringWidth("W") *
22,
logoSize.height));
// Explicitly create group view to set the background white in case
@@ -187,8 +187,8 @@ InstallerWindow::InstallerWindow()
fLogoGroup = new BGroupView(B_HORIZONTAL, 10);
fLogoGroup->SetViewColor(255, 255, 255);
fLogoGroup->GroupLayout()->SetInsets(0, 0, 10, 0);
- fLogoGroup->GroupLayout()->AddView(logoView);
- fLogoGroup->GroupLayout()->AddView(fStatusView);
+ fLogoGroup->AddChild(logoView);
+ fLogoGroup->AddChild(fStatusView);
fDestMenu = new BPopUpMenu(B_TRANSLATE("scanning" B_UTF8_ELLIPSIS),
true, false);
@@ -220,9 +220,8 @@ InstallerWindow::InstallerWindow()
= B_TRANSLATE("Additional disk space required: 0.0 KiB");
fSizeView = new BStringView("size_view", requiredDiskSpaceString);
fSizeView->SetAlignment(B_ALIGN_RIGHT);
- fSizeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
B_SIZE_UNLIMITED));
fSizeView->SetExplicitAlignment(
- BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE));
+ BAlignment(B_ALIGN_RIGHT, B_ALIGN_TOP));
fProgressBar = new BStatusBar("progress",
B_TRANSLATE("Install progress: "));
@@ -250,6 +249,12 @@ InstallerWindow::InstallerWindow()
toolsMenu->AddItem(fMakeBootableItem);
mainMenu->AddItem(toolsMenu);
+ BGroupView* packagesGroup = new BGroupView(B_VERTICAL,
B_USE_ITEM_SPACING);
+ packagesGroup->AddChild(fPackagesSwitch);
+ packagesGroup->AddChild(packagesScrollView);
+ packagesGroup->AddChild(fProgressBar);
+ packagesGroup->AddChild(fSizeView);
+
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
.Add(mainMenu)
.Add(fLogoGroup)
@@ -257,23 +262,19 @@ InstallerWindow::InstallerWindow()
.AddGroup(B_VERTICAL, B_USE_ITEM_SPACING)
.SetInsets(B_USE_WINDOW_SPACING)
.AddGrid(new BGridView(B_USE_ITEM_SPACING,
B_USE_ITEM_SPACING))
- .Add(fSrcMenuField->CreateLabelLayoutItem(), 0,
0)
- .Add(fSrcMenuField->CreateMenuBarLayoutItem(),
1, 0)
- .Add(fDestMenuField->CreateLabelLayoutItem(),
0, 1)
- .Add(fDestMenuField->CreateMenuBarLayoutItem(),
1, 1)
-
- .Add(BSpaceLayoutItem::CreateVerticalStrut(5),
0, 2, 2)
-
- .Add(fPackagesSwitch, 0, 3, 2)
- .Add(packagesScrollView, 0, 4, 2)
- .Add(fProgressBar, 0, 5, 2)
- .Add(fSizeView, 0, 6, 2)
+ .AddMenuField(fSrcMenuField, 0, 0)
+ .AddMenuField(fDestMenuField, 0, 1)
+ .AddGlue(2, 0, 1, 2)
+ .Add(BSpaceLayoutItem::CreateVerticalStrut(5),
0, 2, 3)
.End()
-
+ .Add(packagesGroup)
.AddGroup(B_HORIZONTAL, B_USE_WINDOW_SPACING)
.Add(fLaunchDriveSetupButton)
.AddGlue()
- .Add(fBeginButton);
+ .Add(fBeginButton)
+ .End()
+ .End()
+ .End();
// Make the optional packages and progress bar invisible on start
fPackagesLayoutItem = layout_item_for(packagesScrollView);
@@ -436,6 +437,7 @@ InstallerWindow::MessageReceived(BMessage *msg)
snprintf(string, sizeof(string),
B_TRANSLATE("Additional disk space required:
%s"), buffer);
fSizeView->SetText(string);
+ fSizeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
B_SIZE_UNSET));
break;
}
case ENCOURAGE_DRIVESETUP:
@@ -450,10 +452,6 @@ InstallerWindow::MessageReceived(BMessage *msg)
}
case MSG_STATUS_MESSAGE:
{
-// TODO: Was this supposed to prevent status messages still arriving
-// after the copy engine was shut down?
-// if (fInstallStatus != kInstalling)
-// break;
float progress;
if (msg->FindFloat("progress", &progress) == B_OK) {
const char* currentItem;
@@ -875,7 +873,9 @@ void
InstallerWindow::_SetStatusMessage(const char *text)
{
fStatusView->SetText(text);
- fLogoGroup->GroupLayout()->InvalidateLayout();
+ fStatusView->InvalidateLayout();
+ // In case the status message makes the text view higher than
the
+ // logo, then we need to resize te whole window to fit it.
}
diff --git a/src/apps/installer/PackageViews.cpp
b/src/apps/installer/PackageViews.cpp
index 3987afd4f4..0aa0679133 100644
--- a/src/apps/installer/PackageViews.cpp
+++ b/src/apps/installer/PackageViews.cpp
@@ -13,6 +13,7 @@
#include <Directory.h>
#include <Entry.h>
#include <fs_attr.h>
+#include <GroupLayout.h>
#include <LayoutUtils.h>
#include <Locale.h>
#include <Messenger.h>
@@ -124,11 +125,14 @@ Group::~Group()
}
-PackageCheckBox::PackageCheckBox(BRect rect, Package *item)
+PackageCheckBox::PackageCheckBox(Package *item)
:
- BCheckBox(rect.OffsetBySelf(7, 0), "pack_cb", item->Name(), NULL),
+ BCheckBox("pack_cb", item->Name(), NULL),
fPackage(item)
{
+ SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
+ SetFlags(Flags() | B_FULL_UPDATE_ON_RESIZE);
+ SetIcon(fPackage->Icon());
}
@@ -142,14 +146,15 @@ void
PackageCheckBox::Draw(BRect update)
{
BCheckBox::Draw(update);
+
+ // Draw the label
char string[15];
fPackage->GetSizeAsString(string, sizeof(string));
float width = StringWidth(string);
- DrawString(string, BPoint(Bounds().right - width - 8, 11));
-
- const BBitmap *icon = fPackage->Icon();
- if (icon)
- DrawBitmap(icon, BPoint(Bounds().right - 92, 0));
+ BRect sizeRect = Bounds();
+ sizeRect.left = sizeRect.right - width;
+ be_control_look->DrawLabel(this, string, NULL, sizeRect, update,
+ ui_color(B_DOCUMENT_BACKGROUND_COLOR),
be_control_look->Flags(this));
}
@@ -157,7 +162,6 @@ void
PackageCheckBox::MouseMoved(BPoint point, uint32 transit,
const BMessage* dragMessage)
{
- printf("%s called\n", __PRETTY_FUNCTION__);
if (transit == B_ENTERED_VIEW) {
BMessage msg(MSG_STATUS_MESSAGE);
msg.AddString("status", fPackage->Description());
@@ -169,9 +173,9 @@ PackageCheckBox::MouseMoved(BPoint point, uint32 transit,
}
-GroupView::GroupView(BRect rect, Group *group)
+GroupView::GroupView(Group *group)
:
- BStringView(rect, "group", group->GroupName()),
+ BStringView("group", group->GroupName()),
fGroup(group)
{
SetFont(be_bold_font);
@@ -187,17 +191,17 @@ GroupView::~GroupView()
// #pragma mark -
-PackagesView::PackagesView(BRect rect, const char* name)
- :
- BView(rect, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS)
-{
-}
-
-
PackagesView::PackagesView(const char* name)
:
- BView(name, B_WILL_DRAW | B_FRAME_EVENTS)
+ BView(name, B_WILL_DRAW)
{
+ BGroupLayout* layout = new BGroupLayout(B_VERTICAL);
+ layout->SetSpacing(0);
+ layout->SetInsets(B_USE_SMALL_SPACING, 0);
+ SetLayout(layout);
+
+ SetViewUIColor(B_DOCUMENT_BACKGROUND_COLOR);
+ SetExplicitMinSize(BSize(B_SIZE_UNSET, 80));
}
@@ -219,6 +223,10 @@ PackagesView::Clean()
}
}
ScrollTo(0, 0);
+
+ BView* parent = Parent();
+ BRect r = parent->Bounds();
+ parent->FrameResized(r.Width(), r.Height());
}
@@ -226,34 +234,30 @@ void
PackagesView::AddPackages(BList& packages, BMessage* msg)
{
int32 count = packages.CountItems();
- BRect rect = Bounds();
- BRect bounds = rect;
- rect.left = 1;
- rect.bottom = 15;
- rect.top = 0;
BString lastGroup = "";
for (int32 i = 0; i < count; i++) {
void* item = packages.ItemAt(i);
Package* package = static_cast<Package*>(item);
if (lastGroup != BString(package->GroupName())) {
- rect.OffsetBy(0, 1);
lastGroup = package->GroupName();
Group* group = new Group();
group->SetGroupName(package->GroupName());
- GroupView *view = new GroupView(rect, group);
+ GroupView *view = new GroupView(group);
AddChild(view);
- rect.OffsetBy(0, 17);
}
- PackageCheckBox* checkBox = new PackageCheckBox(rect, package);
+ PackageCheckBox* checkBox = new PackageCheckBox(package);
checkBox->SetValue(package->OnByDefault()
? B_CONTROL_ON : B_CONTROL_OFF);
checkBox->SetEnabled(!package->AlwaysOn());
checkBox->SetMessage(new BMessage(*msg));
AddChild(checkBox);
- rect.OffsetBy(0, 20);
}
- ResizeTo(bounds.Width(), rect.top);
Invalidate();
+
+ // Force scrollbars to update
+ BView* parent = Parent();
+ BRect r = parent->Bounds();
+ parent->FrameResized(r.Width(), r.Height());
}
@@ -286,36 +290,6 @@ PackagesView::GetPackagesToInstall(BList* list, int32*
size)
}
-void
-PackagesView::FrameResized(float width, float height)
-{
- if (CountChildren() == 0)
- Invalidate();
-
- BScrollBar* scrollBar = ScrollBar(B_VERTICAL);
- if (scrollBar == NULL)
- return;
-
- float virtualHeight = 0.0;
-
- int32 count = CountChildren();
- if (count > 0) {
- BView* child = ChildAt(count - 1);
- virtualHeight = child->Frame().bottom;
- }
-
- if (height > virtualHeight) {
- scrollBar->SetRange(0.0f, 0.0f);
- scrollBar->SetValue(0.0f);
- } else {
- scrollBar->SetRange(0.0f, virtualHeight - height);
- scrollBar->SetProportion(height / virtualHeight);
- }
-
- scrollBar->SetSteps(15, height);
-}
-
-
void
PackagesView::Draw(BRect updateRect)
{
@@ -327,25 +301,3 @@ PackagesView::Draw(BRect updateRect)
Bounds(), updateRect, ViewColor(), BControlLook::B_DISABLED,
BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
}
-
-
-void
-PackagesView::GetPreferredSize(float* _width, float* _height)
-{
- // TODO: Something more nice as default? I need to see how this looks
- // when there are actually any packages...
- if (_width != NULL)
- *_width = 400.0;
-
- if (_height != NULL)
- *_height = 80.0;
-}
-
-
-BSize
-PackagesView::MaxSize()
-{
- return BLayoutUtils::ComposeSize(ExplicitMaxSize(),
- BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
-}
-
diff --git a/src/apps/installer/PackageViews.h
b/src/apps/installer/PackageViews.h
index d676b6b91d..240dff9e40 100644
--- a/src/apps/installer/PackageViews.h
+++ b/src/apps/installer/PackageViews.h
@@ -79,7 +79,7 @@ private:
class PackageCheckBox : public BCheckBox {
public:
-
PackageCheckBox(BRect rect, Package* item);
+
PackageCheckBox(Package* item);
virtual ~PackageCheckBox();
virtual void Draw(BRect updateRect);
@@ -95,7 +95,7 @@ private:
class GroupView : public BStringView {
public:
- GroupView(BRect
rect, Group* group);
+
GroupView(Group* group);
virtual ~GroupView();
private:
@@ -105,7 +105,6 @@ private:
class PackagesView : public BView {
public:
-
PackagesView(BRect rect, const char* name);
PackagesView(const char* name);
virtual ~PackagesView();
@@ -115,13 +114,7 @@ public:
size_t
stringSize);
void
GetPackagesToInstall(BList* list, int32* size);
- virtual void FrameResized(float width, float
height);
virtual void Draw(BRect updateRect);
- virtual void GetPreferredSize(float* _width,
float* _height);
- virtual BSize MaxSize();
-
-private:
- BList fViews;
};
#endif // __PACKAGEVIEWS_H__