From ad35df242c140b42d634f6bcac62cbd50bac8329 Mon Sep 17 00:00:00 2001 From: Mounir Tohami <53877170+WhalesState@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:02:52 +0300 Subject: [PATCH] Fix `ScrollBar` grabber mouse ignores scroll margin (cherry picked from commit blazium-engine/blazium@ca09c1d606e876d527ef0d67a40dbf94860050a7) --- scene/gui/scroll_bar.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 57a9641d7bf..f97dff98e13 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -95,7 +95,7 @@ void ScrollBar::gui_input(const Ref &p_event) { return; } - ofs -= decr_size; + ofs -= decr_size + (orientation == VERTICAL ? theme_cache.scroll_style->get_margin(SIDE_TOP) : theme_cache.scroll_style->get_margin(SIDE_LEFT)); if (ofs < grabber_ofs) { if (scrolling) { @@ -153,7 +153,7 @@ void ScrollBar::gui_input(const Ref &p_event) { Ref decr = theme_cache.decrement_icon; double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); - ofs -= decr_size; + ofs -= decr_size + (orientation == VERTICAL ? theme_cache.scroll_style->get_margin(SIDE_TOP) : theme_cache.scroll_style->get_margin(SIDE_LEFT)); double diff = (ofs - drag.pos_at_click) / get_area_size(); @@ -250,8 +250,6 @@ void ScrollBar::_notification(int p_what) { incr = theme_cache.increment_icon; } - Ref bg = has_focus() ? theme_cache.scroll_focus_style : theme_cache.scroll_style; - Ref grabber; if (drag.active) { grabber = theme_cache.grabber_pressed_style; @@ -279,7 +277,11 @@ void ScrollBar::_notification(int p_what) { area.height -= incr->get_height() + decr->get_height(); } - bg->draw(ci, Rect2(ofs, area)); + if (has_focus()) { + theme_cache.scroll_focus_style->draw(ci, Rect2(ofs, area)); + } else { + theme_cache.scroll_style->draw(ci, Rect2(ofs, area)); + } if (orientation == HORIZONTAL) { ofs.width += area.width; @@ -294,11 +296,11 @@ void ScrollBar::_notification(int p_what) { grabber_rect.size.width = get_grabber_size(); grabber_rect.size.height = get_size().height; grabber_rect.position.y = 0; - grabber_rect.position.x = get_grabber_offset() + decr->get_width() + bg->get_margin(SIDE_LEFT); + grabber_rect.position.x = get_grabber_offset() + decr->get_width() + theme_cache.scroll_style->get_margin(SIDE_LEFT); } else { grabber_rect.size.width = get_size().width; grabber_rect.size.height = get_grabber_size(); - grabber_rect.position.y = get_grabber_offset() + decr->get_height() + bg->get_margin(SIDE_TOP); + grabber_rect.position.y = get_grabber_offset() + decr->get_height() + theme_cache.scroll_style->get_margin(SIDE_TOP); grabber_rect.position.x = 0; }