summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGUI/ScrollableWidget.cpp37
-rw-r--r--Userland/Libraries/LibGUI/ScrollableWidget.h1
2 files changed, 23 insertions, 15 deletions
diff --git a/Userland/Libraries/LibGUI/ScrollableWidget.cpp b/Userland/Libraries/LibGUI/ScrollableWidget.cpp
index ea04ada81f..f2b4cb571f 100644
--- a/Userland/Libraries/LibGUI/ScrollableWidget.cpp
+++ b/Userland/Libraries/LibGUI/ScrollableWidget.cpp
@@ -106,31 +106,38 @@ Gfx::IntSize ScrollableWidget::available_size() const
return { available_width, available_height };
}
-void ScrollableWidget::update_scrollbar_ranges()
+Gfx::IntSize ScrollableWidget::excess_size() const
{
auto available_size = this->available_size();
-
int excess_height = max(0, m_content_size.height() - available_size.height());
int excess_width = max(0, m_content_size.width() - available_size.width());
+ return { excess_width, excess_height };
+}
- auto vertical_initial_visibility = m_vertical_scrollbar->is_visible();
- auto horizontal_initial_visibility = m_horizontal_scrollbar->is_visible();
-
+void ScrollableWidget::update_scrollbar_ranges()
+{
if (should_hide_unnecessary_scrollbars()) {
- m_vertical_scrollbar->set_visible(excess_height > 0);
- m_horizontal_scrollbar->set_visible(excess_width > 0);
- }
-
- if (m_vertical_scrollbar->is_visible() != vertical_initial_visibility || m_horizontal_scrollbar->is_visible() != horizontal_initial_visibility) {
- available_size = this->available_size();
- excess_height = max(0, m_content_size.height() - available_size.height());
- excess_width = max(0, m_content_size.width() - available_size.width());
+ if (excess_size().height() - height_occupied_by_horizontal_scrollbar() <= 0 && excess_size().width() - width_occupied_by_vertical_scrollbar() <= 0) {
+ m_horizontal_scrollbar->set_visible(false);
+ m_vertical_scrollbar->set_visible(false);
+ } else {
+ auto vertical_initial_visibility = m_vertical_scrollbar->is_visible();
+ auto horizontal_initial_visibility = m_horizontal_scrollbar->is_visible();
+
+ m_vertical_scrollbar->set_visible(excess_size().height() > 0);
+ m_horizontal_scrollbar->set_visible(excess_size().width() > 0);
+
+ if (m_vertical_scrollbar->is_visible() != vertical_initial_visibility)
+ m_horizontal_scrollbar->set_visible(excess_size().width() > 0);
+ if (m_horizontal_scrollbar->is_visible() != horizontal_initial_visibility)
+ m_vertical_scrollbar->set_visible(excess_size().height() > 0);
+ }
}
- m_horizontal_scrollbar->set_range(0, excess_width);
+ m_horizontal_scrollbar->set_range(0, excess_size().width());
m_horizontal_scrollbar->set_page_step(visible_content_rect().width() - m_horizontal_scrollbar->step());
- m_vertical_scrollbar->set_range(0, excess_height);
+ m_vertical_scrollbar->set_range(0, excess_size().height());
m_vertical_scrollbar->set_page_step(visible_content_rect().height() - m_vertical_scrollbar->step());
}
diff --git a/Userland/Libraries/LibGUI/ScrollableWidget.h b/Userland/Libraries/LibGUI/ScrollableWidget.h
index 349a16a5c7..1ffa78ad24 100644
--- a/Userland/Libraries/LibGUI/ScrollableWidget.h
+++ b/Userland/Libraries/LibGUI/ScrollableWidget.h
@@ -57,6 +57,7 @@ public:
bool is_scrollbars_enabled() const { return m_scrollbars_enabled; }
Gfx::IntSize available_size() const;
+ Gfx::IntSize excess_size() const;
ScrollBar& vertical_scrollbar() { return *m_vertical_scrollbar; }
const ScrollBar& vertical_scrollbar() const { return *m_vertical_scrollbar; }