2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-03-16 18:03:31 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/Frame.h>
|
2019-03-16 18:03:31 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
namespace GUI {
|
2019-03-16 18:03:31 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
class ScrollableWidget : public Frame {
|
|
|
|
C_OBJECT(ScrollableWidget)
|
2019-03-16 18:03:31 +03:00
|
|
|
public:
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual ~ScrollableWidget() override;
|
2019-03-16 18:03:31 +03:00
|
|
|
|
2020-02-06 15:32:14 +03:00
|
|
|
Gfx::Size content_size() const { return m_content_size; }
|
2019-03-16 18:54:51 +03:00
|
|
|
int content_width() const { return m_content_size.width(); }
|
|
|
|
int content_height() const { return m_content_size.height(); }
|
|
|
|
|
2020-02-06 15:02:38 +03:00
|
|
|
Gfx::Rect visible_content_rect() const;
|
2019-03-16 18:03:31 +03:00
|
|
|
|
2020-02-06 15:02:38 +03:00
|
|
|
Gfx::Rect widget_inner_rect() const;
|
2019-03-28 18:14:26 +03:00
|
|
|
|
2020-05-04 23:33:20 +03:00
|
|
|
Gfx::Rect viewport_rect_in_content_coordinates() const
|
|
|
|
{
|
|
|
|
auto viewport_rect = visible_content_rect();
|
|
|
|
viewport_rect.set_size(widget_inner_rect().size());
|
|
|
|
return viewport_rect;
|
|
|
|
}
|
|
|
|
|
2020-02-06 13:56:38 +03:00
|
|
|
void scroll_into_view(const Gfx::Rect&, Orientation);
|
|
|
|
void scroll_into_view(const Gfx::Rect&, bool scroll_horizontally, bool scroll_vertically);
|
2019-03-16 18:03:31 +03:00
|
|
|
|
2019-03-17 01:16:37 +03:00
|
|
|
void set_scrollbars_enabled(bool);
|
|
|
|
bool is_scrollbars_enabled() const { return m_scrollbars_enabled; }
|
|
|
|
|
2020-02-06 15:32:14 +03:00
|
|
|
Gfx::Size available_size() const;
|
2019-03-23 05:53:51 +03:00
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
ScrollBar& vertical_scrollbar() { return *m_vertical_scrollbar; }
|
|
|
|
const ScrollBar& vertical_scrollbar() const { return *m_vertical_scrollbar; }
|
|
|
|
ScrollBar& horizontal_scrollbar() { return *m_horizontal_scrollbar; }
|
|
|
|
const ScrollBar& horizontal_scrollbar() const { return *m_horizontal_scrollbar; }
|
|
|
|
Widget& corner_widget() { return *m_corner_widget; }
|
|
|
|
const Widget& corner_widget() const { return *m_corner_widget; }
|
2019-03-16 18:54:51 +03:00
|
|
|
|
2019-03-19 05:09:21 +03:00
|
|
|
void scroll_to_top();
|
|
|
|
void scroll_to_bottom();
|
|
|
|
|
2019-06-22 11:39:42 +03:00
|
|
|
int width_occupied_by_vertical_scrollbar() const;
|
|
|
|
int height_occupied_by_horizontal_scrollbar() const;
|
|
|
|
|
2019-09-05 22:37:15 +03: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; }
|
|
|
|
|
2020-02-06 15:08:32 +03:00
|
|
|
Gfx::Point to_content_position(const Gfx::Point& widget_position) const;
|
|
|
|
Gfx::Point to_widget_position(const Gfx::Point& content_position) const;
|
2019-10-03 10:15:57 +03:00
|
|
|
|
2019-03-16 18:03:31 +03:00
|
|
|
protected:
|
2020-02-23 14:07:13 +03:00
|
|
|
ScrollableWidget();
|
2019-09-01 21:51:20 +03:00
|
|
|
virtual void custom_layout() override;
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual void resize_event(ResizeEvent&) override;
|
|
|
|
virtual void mousewheel_event(MouseEvent&) override;
|
2019-05-28 12:53:16 +03:00
|
|
|
virtual void did_scroll() {}
|
2020-02-06 13:56:38 +03:00
|
|
|
void set_content_size(const Gfx::Size&);
|
|
|
|
void set_size_occupied_by_fixed_elements(const Gfx::Size&);
|
2019-03-16 18:54:51 +03:00
|
|
|
|
2019-03-16 18:03:31 +03:00
|
|
|
private:
|
|
|
|
void update_scrollbar_ranges();
|
|
|
|
|
2020-02-02 17:07:41 +03:00
|
|
|
RefPtr<ScrollBar> m_vertical_scrollbar;
|
|
|
|
RefPtr<ScrollBar> m_horizontal_scrollbar;
|
|
|
|
RefPtr<Widget> m_corner_widget;
|
2020-02-06 13:56:38 +03:00
|
|
|
Gfx::Size m_content_size;
|
|
|
|
Gfx::Size m_size_occupied_by_fixed_elements;
|
2019-03-16 18:54:51 +03:00
|
|
|
bool m_scrollbars_enabled { true };
|
2019-09-05 22:37:15 +03:00
|
|
|
bool m_should_hide_unnecessary_scrollbars { false };
|
2019-03-16 18:03:31 +03:00
|
|
|
};
|
2020-02-02 17:07:41 +03:00
|
|
|
|
|
|
|
}
|