LibGUI: Minor cleanup in GScrollBar.

This commit is contained in:
Andreas Kling 2019-02-10 08:23:03 +01:00
parent 546946775b
commit 29f2a22d34
Notes: sideshowbarker 2024-07-19 15:48:28 +09:00
2 changed files with 37 additions and 36 deletions

View file

@ -98,8 +98,10 @@ Rect DirectoryView::row_rect(int item_index) const
void DirectoryView::mousedown_event(GMouseEvent& event)
{
for (int i = 0; i < item_count(); ++i) {
if (row_rect(i).contains(event.position())) {
if (event.button() == GMouseButton::Left) {
for (int i = 0; i < item_count(); ++i) {
if (!row_rect(i).contains(event.position()))
continue;
auto& entry = this->entry(i);
if (entry.is_directory()) {
FileSystemPath new_path(String::format("%s/%s", m_path.characters(), entry.name.characters()));

View file

@ -3,9 +3,42 @@
#include <SharedGraphics/GraphicsBitmap.h>
#include <SharedGraphics/Painter.h>
static const char* s_up_arrow_bitmap_data = {
" "
" "
" ## "
" #### "
" ###### "
" ######## "
" ## "
" ## "
" ## "
" "
};
static const char* s_down_arrow_bitmap_data = {
" "
" ## "
" ## "
" ## "
" ######## "
" ###### "
" #### "
" ## "
" "
" "
};
static CharacterBitmap* s_up_arrow_bitmap;
static CharacterBitmap* s_down_arrow_bitmap;
GScrollBar::GScrollBar(GWidget* parent)
: GWidget(parent)
{
if (!s_up_arrow_bitmap)
s_up_arrow_bitmap = CharacterBitmap::create_from_ascii(s_up_arrow_bitmap_data, 10, 10).leak_ref();
if (!s_down_arrow_bitmap)
s_down_arrow_bitmap = CharacterBitmap::create_from_ascii(s_down_arrow_bitmap_data, 10, 10).leak_ref();
}
GScrollBar::~GScrollBar()
@ -88,42 +121,8 @@ Rect GScrollBar::scrubber_rect() const
return { 0, (int)y, button_size(), button_size() };
}
static const char* s_up_arrow_bitmap_data = {
" "
" "
" ## "
" #### "
" ###### "
" ######## "
" ## "
" ## "
" ## "
" "
};
static const char* s_down_arrow_bitmap_data = {
" "
" ## "
" ## "
" ## "
" ######## "
" ###### "
" #### "
" ## "
" "
" "
};
static CharacterBitmap* s_up_arrow_bitmap;
static CharacterBitmap* s_down_arrow_bitmap;
void GScrollBar::paint_event(GPaintEvent&)
{
if (!s_up_arrow_bitmap)
s_up_arrow_bitmap = CharacterBitmap::create_from_ascii(s_up_arrow_bitmap_data, 10, 10).leak_ref();
if (!s_down_arrow_bitmap)
s_down_arrow_bitmap = CharacterBitmap::create_from_ascii(s_down_arrow_bitmap_data, 10, 10).leak_ref();
Painter painter(*this);
painter.fill_rect(rect(), Color(164, 164, 164));