diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-28 16:14:26 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-28 16:14:26 +0100 |
commit | 1fc03a7644290da0f15e73181547d90232f1cce5 (patch) | |
tree | dc7401c9b74b6fbe9aa9afccd928defcb0900976 /LibGUI/GScrollableWidget.cpp | |
parent | cb296ffede47d04c80870d1ccbba41efc03e0a8d (diff) | |
download | serenity-1fc03a7644290da0f15e73181547d90232f1cce5.zip |
LibGUI: Make GScrollableWidget a GFrame and fix up GTextEditor for it.
Diffstat (limited to 'LibGUI/GScrollableWidget.cpp')
-rw-r--r-- | LibGUI/GScrollableWidget.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/LibGUI/GScrollableWidget.cpp b/LibGUI/GScrollableWidget.cpp index d0ec6a12cc..44d47b5bf9 100644 --- a/LibGUI/GScrollableWidget.cpp +++ b/LibGUI/GScrollableWidget.cpp @@ -2,7 +2,7 @@ #include <LibGUI/GScrollBar.h> GScrollableWidget::GScrollableWidget(GWidget* parent) - : GWidget(parent) + : GFrame(parent) { m_vertical_scrollbar = new GScrollBar(Orientation::Vertical, this); m_vertical_scrollbar->set_step(4); @@ -27,25 +27,26 @@ GScrollableWidget::~GScrollableWidget() void GScrollableWidget::resize_event(GResizeEvent& event) { + auto inner_rect = frame_inner_rect_for_size(event.size()); update_scrollbar_ranges(); int height_wanted_by_horizontal_scrollbar = m_horizontal_scrollbar->is_visible() ? m_horizontal_scrollbar->height() : 0; int width_wanted_by_vertical_scrollbar = m_vertical_scrollbar->is_visible() ? m_vertical_scrollbar->width() : 0; - m_vertical_scrollbar->set_relative_rect(event.size().width() - m_vertical_scrollbar->preferred_size().width(), 0, m_vertical_scrollbar->preferred_size().width(), event.size().height() - height_wanted_by_horizontal_scrollbar); - m_horizontal_scrollbar->set_relative_rect(0, event.size().height() - m_horizontal_scrollbar->preferred_size().height(), event.size().width() - m_vertical_scrollbar->preferred_size().width(), width_wanted_by_vertical_scrollbar); + m_vertical_scrollbar->set_relative_rect(inner_rect.right() + 1 - m_vertical_scrollbar->preferred_size().width(), inner_rect.top(), m_vertical_scrollbar->preferred_size().width(), inner_rect.height() - height_wanted_by_horizontal_scrollbar); + m_horizontal_scrollbar->set_relative_rect(inner_rect.left(), inner_rect.bottom() + 1 - m_horizontal_scrollbar->preferred_size().height(), inner_rect.width() - m_vertical_scrollbar->preferred_size().width(), width_wanted_by_vertical_scrollbar); m_corner_widget->set_visible(m_vertical_scrollbar->is_visible() && m_horizontal_scrollbar->is_visible()); if (m_corner_widget->is_visible()) { - Rect corner_rect { m_horizontal_scrollbar->rect().right() + 1, m_vertical_scrollbar->rect().bottom() + 1, height_occupied_by_horizontal_scrollbar(), width_occupied_by_vertical_scrollbar() }; + Rect corner_rect { m_horizontal_scrollbar->rect().right() + 2, m_vertical_scrollbar->rect().bottom() + 2, width_occupied_by_vertical_scrollbar(), height_occupied_by_horizontal_scrollbar() }; m_corner_widget->set_relative_rect(corner_rect); } } Size GScrollableWidget::available_size() const { - int available_width = width() - m_size_occupied_by_fixed_elements.width() - width_occupied_by_vertical_scrollbar(); - int available_height = height() - m_size_occupied_by_fixed_elements.height() - height_occupied_by_horizontal_scrollbar(); + int available_width = frame_inner_rect().width() - m_size_occupied_by_fixed_elements.width() - width_occupied_by_vertical_scrollbar(); + int available_height = frame_inner_rect().height() - m_size_occupied_by_fixed_elements.height() - height_occupied_by_horizontal_scrollbar(); return { available_width, available_height }; } @@ -93,8 +94,8 @@ Rect GScrollableWidget::visible_content_rect() const return { m_horizontal_scrollbar->value(), m_vertical_scrollbar->value(), - width() - width_occupied_by_vertical_scrollbar() - m_size_occupied_by_fixed_elements.width(), - height() - height_occupied_by_horizontal_scrollbar() - m_size_occupied_by_fixed_elements.height() + frame_inner_rect().width() - width_occupied_by_vertical_scrollbar() - m_size_occupied_by_fixed_elements.width(), + frame_inner_rect().height() - height_occupied_by_horizontal_scrollbar() - m_size_occupied_by_fixed_elements.height() }; } @@ -144,3 +145,11 @@ void GScrollableWidget::scroll_to_bottom() { scroll_into_view({ 0, content_height(), 1, 1 }, Orientation::Vertical); } + +Rect GScrollableWidget::widget_inner_rect() const +{ + auto rect = frame_inner_rect(); + rect.set_width(rect.width() - width_occupied_by_vertical_scrollbar()); + rect.set_height(rect.height() - height_occupied_by_horizontal_scrollbar()); + return rect; +} |