1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 03:58:12 +00:00

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. :^)
This commit is contained in:
Andreas Kling 2019-02-09 11:29:59 +01:00
parent 1f355f2a79
commit 6a3ff7efc5
2 changed files with 14 additions and 10 deletions

View file

@ -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;