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

LibGUI: Improve GScrollBar button look a bit.

The arrows look better when they're sharp. :^)
This commit is contained in:
Andreas Kling 2019-02-10 11:57:19 +01:00
parent ddd580c30f
commit 8313ce57dc
3 changed files with 36 additions and 27 deletions

View file

@ -16,7 +16,7 @@ DirectoryView::DirectoryView(GWidget* parent)
m_file_icon = GraphicsBitmap::load_from_file("/res/icons/file16.rgb", { 16, 16 }); m_file_icon = GraphicsBitmap::load_from_file("/res/icons/file16.rgb", { 16, 16 });
m_symlink_icon = GraphicsBitmap::load_from_file("/res/icons/link16.rgb", { 16, 16 }); m_symlink_icon = GraphicsBitmap::load_from_file("/res/icons/link16.rgb", { 16, 16 });
m_scrollbar = new GScrollBar(this); m_scrollbar = new GScrollBar(Orientation::Vertical, this);
m_scrollbar->set_step(4); m_scrollbar->set_step(4);
m_scrollbar->set_big_step(30); m_scrollbar->set_big_step(30);
m_scrollbar->on_change = [this] (int) { m_scrollbar->on_change = [this] (int) {
@ -30,7 +30,7 @@ DirectoryView::~DirectoryView()
void DirectoryView::resize_event(GResizeEvent& event) void DirectoryView::resize_event(GResizeEvent& event)
{ {
m_scrollbar->set_relative_rect(event.size().width() - 16, 0, 16, event.size().height()); m_scrollbar->set_relative_rect(event.size().width() - m_scrollbar->preferred_size().width(), 0, m_scrollbar->preferred_size().width(), event.size().height());
} }
void DirectoryView::open(const String& path) void DirectoryView::open(const String& path)

View file

@ -4,41 +4,46 @@
#include <SharedGraphics/Painter.h> #include <SharedGraphics/Painter.h>
static const char* s_up_arrow_bitmap_data = { static const char* s_up_arrow_bitmap_data = {
" " " "
" " " # "
" ## " " ### "
" #### " " ##### "
" ###### " " ####### "
" ######## " " ### "
" ## " " ### "
" ## " " ### "
" ## " " "
" "
}; };
static const char* s_down_arrow_bitmap_data = { static const char* s_down_arrow_bitmap_data = {
" " " "
" ## " " ### "
" ## " " ### "
" ## " " ### "
" ######## " " ####### "
" ###### " " ##### "
" #### " " ### "
" ## " " # "
" " " "
" "
}; };
static CharacterBitmap* s_up_arrow_bitmap; static CharacterBitmap* s_up_arrow_bitmap;
static CharacterBitmap* s_down_arrow_bitmap; static CharacterBitmap* s_down_arrow_bitmap;
GScrollBar::GScrollBar(GWidget* parent) GScrollBar::GScrollBar(Orientation orientation, GWidget* parent)
: GWidget(parent) : GWidget(parent)
, m_orientation(orientation)
{ {
if (!s_up_arrow_bitmap) if (!s_up_arrow_bitmap)
s_up_arrow_bitmap = CharacterBitmap::create_from_ascii(s_up_arrow_bitmap_data, 10, 10).leak_ref(); s_up_arrow_bitmap = CharacterBitmap::create_from_ascii(s_up_arrow_bitmap_data, 9, 9).leak_ref();
if (!s_down_arrow_bitmap) if (!s_down_arrow_bitmap)
s_down_arrow_bitmap = CharacterBitmap::create_from_ascii(s_down_arrow_bitmap_data, 10, 10).leak_ref(); s_down_arrow_bitmap = CharacterBitmap::create_from_ascii(s_down_arrow_bitmap_data, 9, 9).leak_ref();
if (m_orientation == Orientation::Vertical) {
set_preferred_size({ 15, 0 });
} else {
set_preferred_size({ 0, 15 });
}
} }
GScrollBar::~GScrollBar() GScrollBar::~GScrollBar()

View file

@ -5,9 +5,11 @@
class GScrollBar final : public GWidget { class GScrollBar final : public GWidget {
public: public:
explicit GScrollBar(GWidget* parent); explicit GScrollBar(Orientation, GWidget* parent);
virtual ~GScrollBar() override; virtual ~GScrollBar() override;
Orientation orientation() const { return m_orientation; }
int value() const { return m_value; } int value() const { return m_value; }
int min() const { return m_min; } int min() const { return m_min; }
int max() const { return m_max; } int max() const { return m_max; }
@ -29,7 +31,7 @@ private:
virtual void mousemove_event(GMouseEvent&) override; virtual void mousemove_event(GMouseEvent&) override;
virtual const char* class_name() const override { return "GScrollBar"; } virtual const char* class_name() const override { return "GScrollBar"; }
int button_size() const { return 16; } int button_size() const { return orientation() == Orientation::Vertical ? width() : height(); }
Rect up_button_rect() const; Rect up_button_rect() const;
Rect down_button_rect() const; Rect down_button_rect() const;
Rect upper_gutter_rect() const; Rect upper_gutter_rect() const;
@ -46,4 +48,6 @@ private:
bool m_scrubbing { false }; bool m_scrubbing { false };
int m_scrub_start_value { 0 }; int m_scrub_start_value { 0 };
Point m_scrub_origin; Point m_scrub_origin;
Orientation m_orientation { Orientation::Vertical };
}; };