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 <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
299279610c
commit
3d11fed209
@@ -179,7 +179,7 @@ InstallerWindow::InstallerWindow()
|
|||||||
|
|
||||||
BSize logoSize = logoView->MinSize();
|
BSize logoSize = logoView->MinSize();
|
||||||
logoView->SetExplicitMaxSize(logoSize);
|
logoView->SetExplicitMaxSize(logoSize);
|
||||||
fStatusView->SetExplicitMinSize(BSize(fStatusView->StringWidth("W") * 30,
|
fStatusView->SetExplicitMinSize(BSize(fStatusView->StringWidth("W") * 22,
|
||||||
logoSize.height));
|
logoSize.height));
|
||||||
|
|
||||||
// Explicitly create group view to set the background white in case
|
// Explicitly create group view to set the background white in case
|
||||||
@@ -187,8 +187,8 @@ InstallerWindow::InstallerWindow()
|
|||||||
fLogoGroup = new BGroupView(B_HORIZONTAL, 10);
|
fLogoGroup = new BGroupView(B_HORIZONTAL, 10);
|
||||||
fLogoGroup->SetViewColor(255, 255, 255);
|
fLogoGroup->SetViewColor(255, 255, 255);
|
||||||
fLogoGroup->GroupLayout()->SetInsets(0, 0, 10, 0);
|
fLogoGroup->GroupLayout()->SetInsets(0, 0, 10, 0);
|
||||||
fLogoGroup->GroupLayout()->AddView(logoView);
|
fLogoGroup->AddChild(logoView);
|
||||||
fLogoGroup->GroupLayout()->AddView(fStatusView);
|
fLogoGroup->AddChild(fStatusView);
|
||||||
|
|
||||||
fDestMenu = new BPopUpMenu(B_TRANSLATE("scanning" B_UTF8_ELLIPSIS),
|
fDestMenu = new BPopUpMenu(B_TRANSLATE("scanning" B_UTF8_ELLIPSIS),
|
||||||
true, false);
|
true, false);
|
||||||
@@ -220,9 +220,8 @@ InstallerWindow::InstallerWindow()
|
|||||||
= B_TRANSLATE("Additional disk space required: 0.0 KiB");
|
= B_TRANSLATE("Additional disk space required: 0.0 KiB");
|
||||||
fSizeView = new BStringView("size_view", requiredDiskSpaceString);
|
fSizeView = new BStringView("size_view", requiredDiskSpaceString);
|
||||||
fSizeView->SetAlignment(B_ALIGN_RIGHT);
|
fSizeView->SetAlignment(B_ALIGN_RIGHT);
|
||||||
fSizeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
|
|
||||||
fSizeView->SetExplicitAlignment(
|
fSizeView->SetExplicitAlignment(
|
||||||
BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE));
|
BAlignment(B_ALIGN_RIGHT, B_ALIGN_TOP));
|
||||||
|
|
||||||
fProgressBar = new BStatusBar("progress",
|
fProgressBar = new BStatusBar("progress",
|
||||||
B_TRANSLATE("Install progress: "));
|
B_TRANSLATE("Install progress: "));
|
||||||
@@ -250,6 +249,12 @@ InstallerWindow::InstallerWindow()
|
|||||||
toolsMenu->AddItem(fMakeBootableItem);
|
toolsMenu->AddItem(fMakeBootableItem);
|
||||||
mainMenu->AddItem(toolsMenu);
|
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)
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
||||||
.Add(mainMenu)
|
.Add(mainMenu)
|
||||||
.Add(fLogoGroup)
|
.Add(fLogoGroup)
|
||||||
@@ -257,23 +262,19 @@ InstallerWindow::InstallerWindow()
|
|||||||
.AddGroup(B_VERTICAL, B_USE_ITEM_SPACING)
|
.AddGroup(B_VERTICAL, B_USE_ITEM_SPACING)
|
||||||
.SetInsets(B_USE_WINDOW_SPACING)
|
.SetInsets(B_USE_WINDOW_SPACING)
|
||||||
.AddGrid(new BGridView(B_USE_ITEM_SPACING, B_USE_ITEM_SPACING))
|
.AddGrid(new BGridView(B_USE_ITEM_SPACING, B_USE_ITEM_SPACING))
|
||||||
.Add(fSrcMenuField->CreateLabelLayoutItem(), 0, 0)
|
.AddMenuField(fSrcMenuField, 0, 0)
|
||||||
.Add(fSrcMenuField->CreateMenuBarLayoutItem(), 1, 0)
|
.AddMenuField(fDestMenuField, 0, 1)
|
||||||
.Add(fDestMenuField->CreateLabelLayoutItem(), 0, 1)
|
.AddGlue(2, 0, 1, 2)
|
||||||
.Add(fDestMenuField->CreateMenuBarLayoutItem(), 1, 1)
|
.Add(BSpaceLayoutItem::CreateVerticalStrut(5), 0, 2, 3)
|
||||||
|
|
||||||
.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)
|
|
||||||
.End()
|
.End()
|
||||||
|
.Add(packagesGroup)
|
||||||
.AddGroup(B_HORIZONTAL, B_USE_WINDOW_SPACING)
|
.AddGroup(B_HORIZONTAL, B_USE_WINDOW_SPACING)
|
||||||
.Add(fLaunchDriveSetupButton)
|
.Add(fLaunchDriveSetupButton)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.Add(fBeginButton);
|
.Add(fBeginButton)
|
||||||
|
.End()
|
||||||
|
.End()
|
||||||
|
.End();
|
||||||
|
|
||||||
// Make the optional packages and progress bar invisible on start
|
// Make the optional packages and progress bar invisible on start
|
||||||
fPackagesLayoutItem = layout_item_for(packagesScrollView);
|
fPackagesLayoutItem = layout_item_for(packagesScrollView);
|
||||||
@@ -436,6 +437,7 @@ InstallerWindow::MessageReceived(BMessage *msg)
|
|||||||
snprintf(string, sizeof(string),
|
snprintf(string, sizeof(string),
|
||||||
B_TRANSLATE("Additional disk space required: %s"), buffer);
|
B_TRANSLATE("Additional disk space required: %s"), buffer);
|
||||||
fSizeView->SetText(string);
|
fSizeView->SetText(string);
|
||||||
|
fSizeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ENCOURAGE_DRIVESETUP:
|
case ENCOURAGE_DRIVESETUP:
|
||||||
@@ -450,10 +452,6 @@ InstallerWindow::MessageReceived(BMessage *msg)
|
|||||||
}
|
}
|
||||||
case MSG_STATUS_MESSAGE:
|
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;
|
float progress;
|
||||||
if (msg->FindFloat("progress", &progress) == B_OK) {
|
if (msg->FindFloat("progress", &progress) == B_OK) {
|
||||||
const char* currentItem;
|
const char* currentItem;
|
||||||
@@ -875,7 +873,9 @@ void
|
|||||||
InstallerWindow::_SetStatusMessage(const char *text)
|
InstallerWindow::_SetStatusMessage(const char *text)
|
||||||
{
|
{
|
||||||
fStatusView->SetText(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.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <fs_attr.h>
|
#include <fs_attr.h>
|
||||||
|
#include <GroupLayout.h>
|
||||||
#include <LayoutUtils.h>
|
#include <LayoutUtils.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
#include <Messenger.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)
|
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)
|
PackageCheckBox::Draw(BRect update)
|
||||||
{
|
{
|
||||||
BCheckBox::Draw(update);
|
BCheckBox::Draw(update);
|
||||||
|
|
||||||
|
// Draw the label
|
||||||
char string[15];
|
char string[15];
|
||||||
fPackage->GetSizeAsString(string, sizeof(string));
|
fPackage->GetSizeAsString(string, sizeof(string));
|
||||||
float width = StringWidth(string);
|
float width = StringWidth(string);
|
||||||
DrawString(string, BPoint(Bounds().right - width - 8, 11));
|
BRect sizeRect = Bounds();
|
||||||
|
sizeRect.left = sizeRect.right - width;
|
||||||
const BBitmap *icon = fPackage->Icon();
|
be_control_look->DrawLabel(this, string, NULL, sizeRect, update,
|
||||||
if (icon)
|
ui_color(B_DOCUMENT_BACKGROUND_COLOR), be_control_look->Flags(this));
|
||||||
DrawBitmap(icon, BPoint(Bounds().right - 92, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -157,7 +162,6 @@ void
|
|||||||
PackageCheckBox::MouseMoved(BPoint point, uint32 transit,
|
PackageCheckBox::MouseMoved(BPoint point, uint32 transit,
|
||||||
const BMessage* dragMessage)
|
const BMessage* dragMessage)
|
||||||
{
|
{
|
||||||
printf("%s called\n", __PRETTY_FUNCTION__);
|
|
||||||
if (transit == B_ENTERED_VIEW) {
|
if (transit == B_ENTERED_VIEW) {
|
||||||
BMessage msg(MSG_STATUS_MESSAGE);
|
BMessage msg(MSG_STATUS_MESSAGE);
|
||||||
msg.AddString("status", fPackage->Description());
|
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)
|
fGroup(group)
|
||||||
{
|
{
|
||||||
SetFont(be_bold_font);
|
SetFont(be_bold_font);
|
||||||
@@ -187,17 +191,17 @@ GroupView::~GroupView()
|
|||||||
// #pragma mark -
|
// #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)
|
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);
|
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)
|
PackagesView::AddPackages(BList& packages, BMessage* msg)
|
||||||
{
|
{
|
||||||
int32 count = packages.CountItems();
|
int32 count = packages.CountItems();
|
||||||
BRect rect = Bounds();
|
|
||||||
BRect bounds = rect;
|
|
||||||
rect.left = 1;
|
|
||||||
rect.bottom = 15;
|
|
||||||
rect.top = 0;
|
|
||||||
BString lastGroup = "";
|
BString lastGroup = "";
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
void* item = packages.ItemAt(i);
|
void* item = packages.ItemAt(i);
|
||||||
Package* package = static_cast<Package*>(item);
|
Package* package = static_cast<Package*>(item);
|
||||||
if (lastGroup != BString(package->GroupName())) {
|
if (lastGroup != BString(package->GroupName())) {
|
||||||
rect.OffsetBy(0, 1);
|
|
||||||
lastGroup = package->GroupName();
|
lastGroup = package->GroupName();
|
||||||
Group* group = new Group();
|
Group* group = new Group();
|
||||||
group->SetGroupName(package->GroupName());
|
group->SetGroupName(package->GroupName());
|
||||||
GroupView *view = new GroupView(rect, group);
|
GroupView *view = new GroupView(group);
|
||||||
AddChild(view);
|
AddChild(view);
|
||||||
rect.OffsetBy(0, 17);
|
|
||||||
}
|
}
|
||||||
PackageCheckBox* checkBox = new PackageCheckBox(rect, package);
|
PackageCheckBox* checkBox = new PackageCheckBox(package);
|
||||||
checkBox->SetValue(package->OnByDefault()
|
checkBox->SetValue(package->OnByDefault()
|
||||||
? B_CONTROL_ON : B_CONTROL_OFF);
|
? B_CONTROL_ON : B_CONTROL_OFF);
|
||||||
checkBox->SetEnabled(!package->AlwaysOn());
|
checkBox->SetEnabled(!package->AlwaysOn());
|
||||||
checkBox->SetMessage(new BMessage(*msg));
|
checkBox->SetMessage(new BMessage(*msg));
|
||||||
AddChild(checkBox);
|
AddChild(checkBox);
|
||||||
rect.OffsetBy(0, 20);
|
|
||||||
}
|
}
|
||||||
ResizeTo(bounds.Width(), rect.top);
|
|
||||||
Invalidate();
|
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
|
void
|
||||||
PackagesView::Draw(BRect updateRect)
|
PackagesView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
@@ -327,25 +301,3 @@ PackagesView::Draw(BRect updateRect)
|
|||||||
Bounds(), updateRect, ViewColor(), BControlLook::B_DISABLED,
|
Bounds(), updateRect, ViewColor(), BControlLook::B_DISABLED,
|
||||||
BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE));
|
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ private:
|
|||||||
|
|
||||||
class PackageCheckBox : public BCheckBox {
|
class PackageCheckBox : public BCheckBox {
|
||||||
public:
|
public:
|
||||||
PackageCheckBox(BRect rect, Package* item);
|
PackageCheckBox(Package* item);
|
||||||
virtual ~PackageCheckBox();
|
virtual ~PackageCheckBox();
|
||||||
|
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
@@ -95,7 +95,7 @@ private:
|
|||||||
|
|
||||||
class GroupView : public BStringView {
|
class GroupView : public BStringView {
|
||||||
public:
|
public:
|
||||||
GroupView(BRect rect, Group* group);
|
GroupView(Group* group);
|
||||||
virtual ~GroupView();
|
virtual ~GroupView();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -105,7 +105,6 @@ private:
|
|||||||
|
|
||||||
class PackagesView : public BView {
|
class PackagesView : public BView {
|
||||||
public:
|
public:
|
||||||
PackagesView(BRect rect, const char* name);
|
|
||||||
PackagesView(const char* name);
|
PackagesView(const char* name);
|
||||||
virtual ~PackagesView();
|
virtual ~PackagesView();
|
||||||
|
|
||||||
@@ -115,13 +114,7 @@ public:
|
|||||||
size_t stringSize);
|
size_t stringSize);
|
||||||
void GetPackagesToInstall(BList* list, int32* size);
|
void GetPackagesToInstall(BList* list, int32* size);
|
||||||
|
|
||||||
virtual void FrameResized(float width, float height);
|
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
virtual void GetPreferredSize(float* _width, float* _height);
|
|
||||||
virtual BSize MaxSize();
|
|
||||||
|
|
||||||
private:
|
|
||||||
BList fViews;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __PACKAGEVIEWS_H__
|
#endif // __PACKAGEVIEWS_H__
|
||||||
|
|||||||
Reference in New Issue
Block a user