aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-12-14 12:12:00 +0100
committerdec05eba <dec05eba@protonmail.com>2024-12-14 12:12:00 +0100
commit846d3c4e813ecd981f4834ca5aca14d98f4e9fdf (patch)
treedfd0eeb12bfbb37a0099de14f63378df2dff97ff
parent3bd4572631778aa04d0bd1acd5d3c03bb82b17fa (diff)
Fix mouse events received for scrollablepage child widgets when mouse is outside scrollablepage area
-rw-r--r--TODO2
-rw-r--r--src/gui/CustomRendererWidget.cpp2
-rw-r--r--src/gui/GsrPage.cpp2
-rw-r--r--src/gui/ScrollablePage.cpp14
-rw-r--r--src/gui/StaticPage.cpp2
5 files changed, 18 insertions, 4 deletions
diff --git a/TODO b/TODO
index 7280767..9daa2bc 100644
--- a/TODO
+++ b/TODO
@@ -106,3 +106,5 @@ Use global shortcuts desktop portal protocol on wayland when available.
When support for window capture is enabled on x11 then make sure to not save the window except temporary while the program is open.
Support CJK.
+
+Move ui hover code from ::draw to ::on_event, to properly handle widget event stack. \ No newline at end of file
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}
};