mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibGUI: Rename ScrollableWidget => AbstractScrollableWidget
This commit is contained in:
parent
62125796c3
commit
d47f15ab8b
26 changed files with 95 additions and 94 deletions
|
@ -1,24 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibGUI/ScrollableWidget.h>
|
||||
#include <LibGUI/AbstractScrollableWidget.h>
|
||||
#include <LibGUI/Scrollbar.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
ScrollableWidget::ScrollableWidget()
|
||||
AbstractScrollableWidget::AbstractScrollableWidget()
|
||||
{
|
||||
m_vertical_scrollbar = add<ScrollableWidgetScrollbar>(*this, Orientation::Vertical);
|
||||
m_vertical_scrollbar = add<AbstractScrollableWidgetScrollbar>(*this, Orientation::Vertical);
|
||||
m_vertical_scrollbar->set_step(4);
|
||||
m_vertical_scrollbar->on_change = [this](int) {
|
||||
did_scroll();
|
||||
update();
|
||||
};
|
||||
|
||||
m_horizontal_scrollbar = add<ScrollableWidgetScrollbar>(*this, Orientation::Horizontal);
|
||||
m_horizontal_scrollbar = add<AbstractScrollableWidgetScrollbar>(*this, Orientation::Horizontal);
|
||||
m_horizontal_scrollbar->set_step(4);
|
||||
m_horizontal_scrollbar->set_page_step(30);
|
||||
m_horizontal_scrollbar->on_change = [this](int) {
|
||||
|
@ -30,11 +30,11 @@ ScrollableWidget::ScrollableWidget()
|
|||
m_corner_widget->set_fill_with_background_color(true);
|
||||
}
|
||||
|
||||
ScrollableWidget::~ScrollableWidget()
|
||||
AbstractScrollableWidget::~AbstractScrollableWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void ScrollableWidget::handle_wheel_event(MouseEvent& event, Widget& event_source)
|
||||
void AbstractScrollableWidget::handle_wheel_event(MouseEvent& event, Widget& event_source)
|
||||
{
|
||||
if (!m_scrollbars_enabled) {
|
||||
event.ignore();
|
||||
|
@ -48,12 +48,12 @@ void ScrollableWidget::handle_wheel_event(MouseEvent& event, Widget& event_sourc
|
|||
}
|
||||
}
|
||||
|
||||
void ScrollableWidget::mousewheel_event(MouseEvent& event)
|
||||
void AbstractScrollableWidget::mousewheel_event(MouseEvent& event)
|
||||
{
|
||||
handle_wheel_event(event, *this);
|
||||
}
|
||||
|
||||
void ScrollableWidget::custom_layout()
|
||||
void AbstractScrollableWidget::custom_layout()
|
||||
{
|
||||
auto inner_rect = frame_inner_rect_for_size(size());
|
||||
int height_wanted_by_horizontal_scrollbar = m_horizontal_scrollbar->is_visible() ? m_horizontal_scrollbar->min_height() : 0;
|
||||
|
@ -78,20 +78,20 @@ void ScrollableWidget::custom_layout()
|
|||
}
|
||||
}
|
||||
|
||||
void ScrollableWidget::resize_event(ResizeEvent& event)
|
||||
void AbstractScrollableWidget::resize_event(ResizeEvent& event)
|
||||
{
|
||||
Frame::resize_event(event);
|
||||
update_scrollbar_ranges();
|
||||
}
|
||||
|
||||
Gfx::IntSize ScrollableWidget::available_size() const
|
||||
Gfx::IntSize AbstractScrollableWidget::available_size() const
|
||||
{
|
||||
unsigned available_width = max(frame_inner_rect().width() - m_size_occupied_by_fixed_elements.width() - width_occupied_by_vertical_scrollbar(), 0);
|
||||
unsigned available_height = max(frame_inner_rect().height() - m_size_occupied_by_fixed_elements.height() - height_occupied_by_horizontal_scrollbar(), 0);
|
||||
return { available_width, available_height };
|
||||
}
|
||||
|
||||
Gfx::IntSize ScrollableWidget::excess_size() const
|
||||
Gfx::IntSize AbstractScrollableWidget::excess_size() const
|
||||
{
|
||||
auto available_size = this->available_size();
|
||||
int excess_height = max(0, m_content_size.height() - available_size.height());
|
||||
|
@ -99,7 +99,7 @@ Gfx::IntSize ScrollableWidget::excess_size() const
|
|||
return { excess_width, excess_height };
|
||||
}
|
||||
|
||||
void ScrollableWidget::update_scrollbar_ranges()
|
||||
void AbstractScrollableWidget::update_scrollbar_ranges()
|
||||
{
|
||||
if (should_hide_unnecessary_scrollbars()) {
|
||||
if (excess_size().height() - height_occupied_by_horizontal_scrollbar() <= 0 && excess_size().width() - width_occupied_by_vertical_scrollbar() <= 0) {
|
||||
|
@ -126,7 +126,7 @@ void ScrollableWidget::update_scrollbar_ranges()
|
|||
m_vertical_scrollbar->set_page_step(visible_content_rect().height() - m_vertical_scrollbar->step());
|
||||
}
|
||||
|
||||
void ScrollableWidget::set_content_size(const Gfx::IntSize& size)
|
||||
void AbstractScrollableWidget::set_content_size(const Gfx::IntSize& size)
|
||||
{
|
||||
if (m_content_size == size)
|
||||
return;
|
||||
|
@ -134,7 +134,7 @@ void ScrollableWidget::set_content_size(const Gfx::IntSize& size)
|
|||
update_scrollbar_ranges();
|
||||
}
|
||||
|
||||
void ScrollableWidget::set_size_occupied_by_fixed_elements(const Gfx::IntSize& size)
|
||||
void AbstractScrollableWidget::set_size_occupied_by_fixed_elements(const Gfx::IntSize& size)
|
||||
{
|
||||
if (m_size_occupied_by_fixed_elements == size)
|
||||
return;
|
||||
|
@ -142,17 +142,17 @@ void ScrollableWidget::set_size_occupied_by_fixed_elements(const Gfx::IntSize& s
|
|||
update_scrollbar_ranges();
|
||||
}
|
||||
|
||||
int ScrollableWidget::height_occupied_by_horizontal_scrollbar() const
|
||||
int AbstractScrollableWidget::height_occupied_by_horizontal_scrollbar() const
|
||||
{
|
||||
return m_horizontal_scrollbar->is_visible() ? m_horizontal_scrollbar->height() : 0;
|
||||
}
|
||||
|
||||
int ScrollableWidget::width_occupied_by_vertical_scrollbar() const
|
||||
int AbstractScrollableWidget::width_occupied_by_vertical_scrollbar() const
|
||||
{
|
||||
return m_vertical_scrollbar->is_visible() ? m_vertical_scrollbar->width() : 0;
|
||||
}
|
||||
|
||||
Gfx::IntRect ScrollableWidget::visible_content_rect() const
|
||||
Gfx::IntRect AbstractScrollableWidget::visible_content_rect() const
|
||||
{
|
||||
Gfx::IntRect rect {
|
||||
m_horizontal_scrollbar->value(),
|
||||
|
@ -165,14 +165,14 @@ Gfx::IntRect ScrollableWidget::visible_content_rect() const
|
|||
return rect;
|
||||
}
|
||||
|
||||
void ScrollableWidget::scroll_into_view(const Gfx::IntRect& rect, Orientation orientation)
|
||||
void AbstractScrollableWidget::scroll_into_view(const Gfx::IntRect& rect, Orientation orientation)
|
||||
{
|
||||
if (orientation == Orientation::Vertical)
|
||||
return scroll_into_view(rect, false, true);
|
||||
return scroll_into_view(rect, true, false);
|
||||
}
|
||||
|
||||
void ScrollableWidget::scroll_into_view(const Gfx::IntRect& rect, bool scroll_horizontally, bool scroll_vertically)
|
||||
void AbstractScrollableWidget::scroll_into_view(const Gfx::IntRect& rect, bool scroll_horizontally, bool scroll_vertically)
|
||||
{
|
||||
auto visible_content_rect = this->visible_content_rect();
|
||||
if (visible_content_rect.contains(rect))
|
||||
|
@ -194,7 +194,7 @@ void ScrollableWidget::scroll_into_view(const Gfx::IntRect& rect, bool scroll_ho
|
|||
}
|
||||
}
|
||||
|
||||
void ScrollableWidget::set_scrollbars_enabled(bool scrollbars_enabled)
|
||||
void AbstractScrollableWidget::set_scrollbars_enabled(bool scrollbars_enabled)
|
||||
{
|
||||
if (m_scrollbars_enabled == scrollbars_enabled)
|
||||
return;
|
||||
|
@ -204,17 +204,17 @@ void ScrollableWidget::set_scrollbars_enabled(bool scrollbars_enabled)
|
|||
m_corner_widget->set_visible(m_scrollbars_enabled);
|
||||
}
|
||||
|
||||
void ScrollableWidget::scroll_to_top()
|
||||
void AbstractScrollableWidget::scroll_to_top()
|
||||
{
|
||||
scroll_into_view({}, Orientation::Vertical);
|
||||
}
|
||||
|
||||
void ScrollableWidget::scroll_to_bottom()
|
||||
void AbstractScrollableWidget::scroll_to_bottom()
|
||||
{
|
||||
scroll_into_view({ 0, content_height(), 0, 0 }, Orientation::Vertical);
|
||||
}
|
||||
|
||||
Gfx::IntRect ScrollableWidget::widget_inner_rect() const
|
||||
Gfx::IntRect AbstractScrollableWidget::widget_inner_rect() const
|
||||
{
|
||||
auto rect = frame_inner_rect();
|
||||
rect.set_width(rect.width() - width_occupied_by_vertical_scrollbar());
|
||||
|
@ -222,7 +222,7 @@ Gfx::IntRect ScrollableWidget::widget_inner_rect() const
|
|||
return rect;
|
||||
}
|
||||
|
||||
Gfx::IntPoint ScrollableWidget::to_content_position(const Gfx::IntPoint& widget_position) const
|
||||
Gfx::IntPoint AbstractScrollableWidget::to_content_position(const Gfx::IntPoint& widget_position) const
|
||||
{
|
||||
auto content_position = widget_position;
|
||||
content_position.translate_by(horizontal_scrollbar().value(), vertical_scrollbar().value());
|
||||
|
@ -230,7 +230,7 @@ Gfx::IntPoint ScrollableWidget::to_content_position(const Gfx::IntPoint& widget_
|
|||
return content_position;
|
||||
}
|
||||
|
||||
Gfx::IntPoint ScrollableWidget::to_widget_position(const Gfx::IntPoint& content_position) const
|
||||
Gfx::IntPoint AbstractScrollableWidget::to_widget_position(const Gfx::IntPoint& content_position) const
|
||||
{
|
||||
auto widget_position = content_position;
|
||||
widget_position.translate_by(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue