summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-09 11:29:59 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-09 11:29:59 +0100
commit6a3ff7efc58a619b316c2b1b731335dcdfab2e69 (patch)
treee770101061d57d160313cacae532b9baa1f9e51c
parent1f355f2a79eb8930b1e923f5bbe96982e7f0b0e7 (diff)
downloadserenity-6a3ff7efc58a619b316c2b1b731335dcdfab2e69.zip
GScrollBar: Start looking a bit more like a proper scrollbar.
And hook up FileManager's DirectoryView with its scrollbar so it actually causes the directory view to shift up and down. Very cool. :^)
-rw-r--r--FileManager/DirectoryView.cpp10
-rw-r--r--LibGUI/GScrollBar.cpp14
2 files changed, 14 insertions, 10 deletions
diff --git a/FileManager/DirectoryView.cpp b/FileManager/DirectoryView.cpp
index 53286c9455..19759154f4 100644
--- a/FileManager/DirectoryView.cpp
+++ b/FileManager/DirectoryView.cpp
@@ -17,6 +17,11 @@ DirectoryView::DirectoryView(GWidget* parent)
m_symlink_icon = GraphicsBitmap::load_from_file("/res/icons/link16.rgb", { 16, 16 });
m_scrollbar = new GScrollBar(this);
+ m_scrollbar->set_step(4);
+ m_scrollbar->set_big_step(30);
+ m_scrollbar->on_change = [this] (int) {
+ update();
+ };
}
DirectoryView::~DirectoryView()
@@ -63,7 +68,8 @@ void DirectoryView::reload()
entries.append(move(entry));
}
closedir(dirp);
- m_scrollbar->set_range(0, item_count() - 1);
+ int excess_height = max(0, (item_count() * item_height()) - height());
+ m_scrollbar->set_range(0, excess_height);
}
const GraphicsBitmap& DirectoryView::icon_for(const Entry& entry) const
@@ -107,6 +113,8 @@ void DirectoryView::paint_event(GPaintEvent&)
{
Painter painter(*this);
+ painter.translate(0, -m_scrollbar->value());
+
int horizontal_padding = 5;
int icon_size = 16;
int painted_item_index = 0;
diff --git a/LibGUI/GScrollBar.cpp b/LibGUI/GScrollBar.cpp
index 3491383a45..4f13c3c86a 100644
--- a/LibGUI/GScrollBar.cpp
+++ b/LibGUI/GScrollBar.cpp
@@ -81,20 +81,16 @@ void GScrollBar::paint_event(GPaintEvent&)
{
Painter painter(*this);
- painter.fill_rect(rect(), Color(0xc0c0c0));
+ painter.fill_rect(rect(), Color::MidGray);
painter.draw_rect(up_button_rect(), Color::DarkGray, true);
- painter.fill_rect(up_button_rect().shrunken(2, 2), Color::LightGray);
+ painter.fill_rect_with_gradient(up_button_rect().shrunken(2, 2), Color::LightGray, Color::White);
painter.draw_rect(down_button_rect(), Color::DarkGray, true);
- painter.fill_rect(down_button_rect().shrunken(2, 2), Color::LightGray);
+ painter.fill_rect_with_gradient(down_button_rect().shrunken(2, 2), Color::LightGray, Color::White);
- painter.fill_rect(pgup_rect(), Color::Magenta);
- painter.fill_rect(pgdn_rect(), Color::Yellow);
-
- painter.fill_rect(scrubber_rect(), Color::Red);
-
- dbgprintf("Paint!\n");
+ painter.draw_rect(scrubber_rect(), Color::White, true);
+ painter.fill_rect_with_gradient(scrubber_rect().shrunken(2, 2), Color::LightGray, Color::White);
}
void GScrollBar::mousedown_event(GMouseEvent& event)