From 846d3c4e813ecd981f4834ca5aca14d98f4e9fdf Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 14 Dec 2024 12:12:00 +0100 Subject: Fix mouse events received for scrollablepage child widgets when mouse is outside scrollablepage area --- src/gui/CustomRendererWidget.cpp | 2 +- src/gui/GsrPage.cpp | 2 +- src/gui/ScrollablePage.cpp | 14 +++++++++++++- src/gui/StaticPage.cpp | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/CustomRendererWidget.cpp b/src/gui/CustomRendererWidget.cpp index cfb113b..4cb7adf 100644 --- a/src/gui/CustomRendererWidget.cpp +++ b/src/gui/CustomRendererWidget.cpp @@ -20,7 +20,7 @@ namespace gsr { mgl_scissor prev_scissor; mgl_window_get_scissor(window.internal_window(), &prev_scissor); - mgl_scissor new_scissor = { + const mgl_scissor new_scissor = { mgl_vec2i{(int)draw_pos.x, (int)draw_pos.y}, mgl_vec2i{(int)size.x, (int)size.y} }; diff --git a/src/gui/GsrPage.cpp b/src/gui/GsrPage.cpp index e6ee5fc..68ee292 100644 --- a/src/gui/GsrPage.cpp +++ b/src/gui/GsrPage.cpp @@ -106,7 +106,7 @@ namespace gsr { mgl_window_get_scissor(window.internal_window(), &prev_scissor); const mgl::vec2f inner_size = get_inner_size(); - mgl_scissor new_scissor = { + const mgl_scissor new_scissor = { mgl_vec2i{(int)position.x, (int)position.y}, mgl_vec2i{(int)inner_size.x, (int)inner_size.y} }; diff --git a/src/gui/ScrollablePage.cpp b/src/gui/ScrollablePage.cpp index 74dd715..6b3116b 100644 --- a/src/gui/ScrollablePage.cpp +++ b/src/gui/ScrollablePage.cpp @@ -22,6 +22,18 @@ namespace gsr { offset = position + offset + mgl::vec2f(0.0f, scroll_y); Widget *selected_widget = selected_child_widget; + const mgl::vec2f content_size = get_inner_size(); + const mgl::vec2i scissor_pos(offset.x, offset.y); + const mgl::vec2i scissor_size(content_size.x, content_size.y); + + if(event.type == mgl::Event::MouseButtonPressed || event.type == mgl::Event::MouseButtonReleased) { + if(!mgl::IntRect(scissor_pos, scissor_pos).contains({event.mouse_button.x, event.mouse_button.y})) + return true; + } else if(event.type == mgl::Event::MouseMoved) { + if(!mgl::IntRect(scissor_pos, scissor_pos).contains({event.mouse_move.x, event.mouse_move.y})) + return true; + } + if(event.type == mgl::Event::MouseButtonReleased && moving_scrollbar_with_cursor) { moving_scrollbar_with_cursor = false; remove_widget_as_selected_in_parent(); @@ -79,7 +91,7 @@ namespace gsr { mgl_window_get_scissor(window.internal_window(), &prev_scissor); const mgl::vec2f content_size = get_inner_size(); - mgl_scissor new_scissor = { + const mgl_scissor new_scissor = { mgl_vec2i{(int)offset.x, (int)offset.y}, mgl_vec2i{(int)content_size.x, (int)content_size.y} }; diff --git a/src/gui/StaticPage.cpp b/src/gui/StaticPage.cpp index a89fc42..c014f38 100644 --- a/src/gui/StaticPage.cpp +++ b/src/gui/StaticPage.cpp @@ -39,7 +39,7 @@ namespace gsr { mgl_scissor prev_scissor; mgl_window_get_scissor(window.internal_window(), &prev_scissor); - mgl_scissor new_scissor = { + const mgl_scissor new_scissor = { mgl_vec2i{(int)draw_pos.x, (int)draw_pos.y}, mgl_vec2i{(int)size.x, (int)size.y} }; -- cgit v1.2.3