From 127061e76fde9a328097adb893e136d0a3dcaea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 4 Aug 2013 18:26:53 +0200 Subject: [PATCH] HaikuDepot: Scrollbars for content, document window look * All text views that potentially need scrolling are now embedded into a CustomScrollView. That one controls a vertical BScrollBar only and has B_NO_BORDER frame. Since the regular BScrollView doesn't do some adjustments in this setup, the CustomScrollView takes care of moving the BScrollBar such that the B_DOCUMENT_WINDOW_LOOK resize handle does not obscure the bottom arrow button. --- src/apps/haiku-depot/MainWindow.cpp | 4 +- src/apps/haiku-depot/PackageInfoView.cpp | 77 +++++++++++++++++++----- 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index 9431844e38a..487e6c1de38 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -30,7 +30,7 @@ MainWindow::MainWindow(BRect frame) : BWindow(frame, B_TRANSLATE_SYSTEM_NAME("HaikuDepot"), - B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) { BMenuBar* menuBar = new BMenuBar(B_TRANSLATE("Main Menu")); @@ -40,7 +40,7 @@ MainWindow::MainWindow(BRect frame) fPackageListView = new PackageListView(); fPackageInfoView = new PackageInfoView(&fPackageManager); - fSplitView = new BSplitView(B_VERTICAL, B_USE_SMALL_SPACING); + fSplitView = new BSplitView(B_VERTICAL, 5.0f); BLayoutBuilder::Group<>(this, B_VERTICAL, 0.0f) .Add(menuBar) diff --git a/src/apps/haiku-depot/PackageInfoView.cpp b/src/apps/haiku-depot/PackageInfoView.cpp index 787fc8c47eb..432f31591d4 100644 --- a/src/apps/haiku-depot/PackageInfoView.cpp +++ b/src/apps/haiku-depot/PackageInfoView.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -111,6 +112,41 @@ class BitmapView : public BView { }; +//! Layouts the scrollbar so it looks nice with no border and the document +// window look. +class CustomScrollView : public BScrollView { +public: + CustomScrollView(const char* name, BView* target) + : + BScrollView(name, target, 0, false, true, B_NO_BORDER) + { + } + + virtual void DoLayout() + { + BRect innerFrame = Bounds(); + innerFrame.right -= B_V_SCROLL_BAR_WIDTH + 1; + + BView* target = Target(); + if (target != NULL) { + Target()->MoveTo(innerFrame.left, innerFrame.top); + Target()->ResizeTo(innerFrame.Width(), innerFrame.Height()); + } + + BScrollBar* scrollBar = ScrollBar(B_VERTICAL); + if (scrollBar != NULL) { + BRect rect = innerFrame; + rect.left = rect.right + 1; + rect.right = rect.left + B_V_SCROLL_BAR_WIDTH; + rect.bottom -= B_H_SCROLL_BAR_HEIGHT; + + scrollBar->MoveTo(rect.left, rect.top); + scrollBar->ResizeTo(rect.Width(), rect.Height()); + } + } +}; + + // #pragma mark - AboutView @@ -421,19 +457,20 @@ class AboutView : public BView { AboutView() : BView("about view", 0), - fLayout(new BGroupLayout(B_HORIZONTAL)), fEmailIcon("text/x-email"), fWebsiteIcon("text/html") { SetViewColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), kContentTint)); - SetLayout(fLayout); - fDescriptionView = new BTextView("description view"); fDescriptionView->SetViewColor(ViewColor()); fDescriptionView->MakeEditable(false); - fDescriptionView->SetInsets(0.0f, be_plain_font->Size(), 0.0f, 0.0f); + const float textInset = be_plain_font->Size(); + fDescriptionView->SetInsets(textInset, textInset, textInset, 0.0f); + + BScrollView* scrollView = new CustomScrollView( + "description scroll view", fDescriptionView); BFont smallFont; GetFont(&smallFont); @@ -449,9 +486,8 @@ class AboutView : public BView { fWebsiteLinkView->SetFont(&smallFont); fWebsiteLinkView->SetHighColor(kLightBlack); - BLayoutBuilder::Group<>(fLayout) - .Add(BSpaceLayoutItem::CreateHorizontalStrut(32.0f)) - .Add(fDescriptionView, 1.0f) + BLayoutBuilder::Group<>(this, B_HORIZONTAL, 0.0f) +// .Add(BSpaceLayoutItem::CreateHorizontalStrut(32.0f)) .AddGroup(B_VERTICAL, 0.0f) .AddGlue() .AddGroup(B_HORIZONTAL) @@ -465,9 +501,13 @@ class AboutView : public BView { .End() .End() .End() + .Add(scrollView, 1.0f) + .SetExplicitMaxSize(BSize(B_SIZE_UNSET, B_SIZE_UNLIMITED)) - .SetInsets(B_USE_DEFAULT_SPACING, 0.0f, 0.0f, 0.0f) + .SetInsets(B_USE_DEFAULT_SPACING, -1.0f, -1.0f, -1.0f) ; + + scrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, -B_H_SCROLL_BAR_HEIGHT); } virtual ~AboutView() @@ -494,7 +534,6 @@ class AboutView : public BView { } private: - BGroupLayout* fLayout; BTextView* fDescriptionView; SharedBitmap fEmailIcon; @@ -525,12 +564,16 @@ class UserRatingsView : public BView { fTextView = new BTextView("ratings view"); fTextView->SetViewColor(ViewColor()); fTextView->MakeEditable(false); - fTextView->SetInsets(0.0f, be_plain_font->Size(), 0.0f, 0.0f); + const float textInset = be_plain_font->Size(); + fTextView->SetInsets(textInset, textInset, textInset, 0.0f); + + BScrollView* scrollView = new CustomScrollView( + "ratings scroll view", fTextView); BLayoutBuilder::Group<>(fLayout) .Add(BSpaceLayoutItem::CreateHorizontalStrut(32.0f)) - .Add(fTextView, 1.0f) - .SetInsets(B_USE_DEFAULT_SPACING, 0.0f, 0.0f, 0.0f) + .Add(scrollView, 1.0f) + .SetInsets(B_USE_DEFAULT_SPACING, -1.0f, -1.0f, -1.0f) ; } @@ -594,12 +637,16 @@ class ChangelogView : public BView { fTextView = new BTextView("changelog view"); fTextView->SetViewColor(ViewColor()); fTextView->MakeEditable(false); - fTextView->SetInsets(0.0f, be_plain_font->Size(), 0.0f, 0.0f); + const float textInset = be_plain_font->Size(); + fTextView->SetInsets(textInset, textInset, textInset, 0.0f); + + BScrollView* scrollView = new CustomScrollView( + "changelog scroll view", fTextView); BLayoutBuilder::Group<>(fLayout) .Add(BSpaceLayoutItem::CreateHorizontalStrut(32.0f)) - .Add(fTextView, 1.0f) - .SetInsets(B_USE_DEFAULT_SPACING, 0.0f, 0.0f, 0.0f) + .Add(scrollView, 1.0f) + .SetInsets(B_USE_DEFAULT_SPACING, -1.0f, -1.0f, -1.0f) ; }