2019-03-16 16:03:31 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-03-28 16:14:26 +01:00
|
|
|
#include <LibGUI/GFrame.h>
|
2019-03-16 16:03:31 +01:00
|
|
|
|
|
|
|
class GScrollBar;
|
|
|
|
|
2019-03-28 16:14:26 +01:00
|
|
|
class GScrollableWidget : public GFrame {
|
2019-07-25 19:49:28 +02:00
|
|
|
C_OBJECT(GScrollableWidget)
|
2019-03-16 16:03:31 +01:00
|
|
|
public:
|
|
|
|
virtual ~GScrollableWidget() override;
|
|
|
|
|
|
|
|
Size content_size() const { return m_content_size; }
|
2019-03-16 16:54:51 +01:00
|
|
|
int content_width() const { return m_content_size.width(); }
|
|
|
|
int content_height() const { return m_content_size.height(); }
|
|
|
|
|
2019-03-16 16:03:31 +01:00
|
|
|
Rect visible_content_rect() const;
|
|
|
|
|
2019-03-28 16:14:26 +01:00
|
|
|
Rect widget_inner_rect() const;
|
|
|
|
|
2019-03-16 16:03:31 +01:00
|
|
|
void scroll_into_view(const Rect&, Orientation);
|
2019-03-16 16:54:51 +01:00
|
|
|
void scroll_into_view(const Rect&, bool scroll_horizontally, bool scroll_vertically);
|
2019-03-16 16:03:31 +01:00
|
|
|
|
2019-03-16 23:16:37 +01:00
|
|
|
void set_scrollbars_enabled(bool);
|
|
|
|
bool is_scrollbars_enabled() const { return m_scrollbars_enabled; }
|
|
|
|
|
2019-03-23 03:53:51 +01:00
|
|
|
Size available_size() const;
|
|
|
|
|
2019-03-16 16:03:31 +01:00
|
|
|
GScrollBar& vertical_scrollbar() { return *m_vertical_scrollbar; }
|
|
|
|
const GScrollBar& vertical_scrollbar() const { return *m_vertical_scrollbar; }
|
|
|
|
GScrollBar& horizontal_scrollbar() { return *m_horizontal_scrollbar; }
|
|
|
|
const GScrollBar& horizontal_scrollbar() const { return *m_horizontal_scrollbar; }
|
2019-03-16 16:54:51 +01:00
|
|
|
GWidget& corner_widget() { return *m_corner_widget; }
|
|
|
|
const GWidget& corner_widget() const { return *m_corner_widget; }
|
|
|
|
|
2019-03-19 03:09:21 +01:00
|
|
|
void scroll_to_top();
|
|
|
|
void scroll_to_bottom();
|
|
|
|
|
2019-06-22 10:39:42 +02:00
|
|
|
int width_occupied_by_vertical_scrollbar() const;
|
|
|
|
int height_occupied_by_horizontal_scrollbar() const;
|
|
|
|
|
2019-09-05 21:37:15 +02:00
|
|
|
void set_should_hide_unnecessary_scrollbars(bool b) { m_should_hide_unnecessary_scrollbars = b; }
|
|
|
|
bool should_hide_unnecessary_scrollbars() const { return m_should_hide_unnecessary_scrollbars; }
|
|
|
|
|
2019-10-03 09:15:57 +02:00
|
|
|
Point to_content_position(const Point& widget_position) const;
|
2019-10-09 21:16:49 +02:00
|
|
|
Point to_widget_position(const Point& content_position) const;
|
2019-10-03 09:15:57 +02:00
|
|
|
|
2019-03-16 16:03:31 +01:00
|
|
|
protected:
|
|
|
|
explicit GScrollableWidget(GWidget* parent);
|
2019-09-01 20:51:20 +02:00
|
|
|
virtual void custom_layout() override;
|
2019-03-16 16:03:31 +01:00
|
|
|
virtual void resize_event(GResizeEvent&) override;
|
2019-05-13 19:52:57 +02:00
|
|
|
virtual void mousewheel_event(GMouseEvent&) override;
|
2019-05-28 11:53:16 +02:00
|
|
|
virtual void did_scroll() {}
|
2019-03-16 16:03:31 +01:00
|
|
|
void set_content_size(const Size&);
|
|
|
|
void set_size_occupied_by_fixed_elements(const Size&);
|
2019-03-16 16:54:51 +01:00
|
|
|
|
2019-03-16 16:03:31 +01:00
|
|
|
private:
|
|
|
|
void update_scrollbar_ranges();
|
|
|
|
|
2019-09-22 00:31:54 +02:00
|
|
|
RefPtr<GScrollBar> m_vertical_scrollbar;
|
|
|
|
RefPtr<GScrollBar> m_horizontal_scrollbar;
|
|
|
|
RefPtr<GWidget> m_corner_widget;
|
2019-03-16 16:03:31 +01:00
|
|
|
Size m_content_size;
|
|
|
|
Size m_size_occupied_by_fixed_elements;
|
2019-03-16 16:54:51 +01:00
|
|
|
bool m_scrollbars_enabled { true };
|
2019-09-05 21:37:15 +02:00
|
|
|
bool m_should_hide_unnecessary_scrollbars { false };
|
2019-03-16 16:03:31 +01:00
|
|
|
};
|