diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-12-29 20:51:56 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-12-29 20:51:56 +0100 |
commit | fdeebe22003faefe3de5e3bc61acdf5a9f071d42 (patch) | |
tree | fbb56bb5de667447063b495512ddee01cb9d1cd6 | |
parent | a119220961d3df6d8f5f96d3a646adedb5d99554 (diff) |
Fix scrollbar not working with mouse, fix being able to click filechooser items outside area
-rw-r--r-- | src/gui/FileChooser.cpp | 7 | ||||
-rw-r--r-- | src/gui/ScrollablePage.cpp | 28 |
2 files changed, 20 insertions, 15 deletions
diff --git a/src/gui/FileChooser.cpp b/src/gui/FileChooser.cpp index 03a44c1..2612365 100644 --- a/src/gui/FileChooser.cpp +++ b/src/gui/FileChooser.cpp @@ -96,7 +96,12 @@ namespace gsr { selected_item_background.set_color(get_color_theme().tint_color); window.draw(selected_item_background); } - if(!has_parent_with_selected_child_widget() && mouse_over_item == -1 && mgl::FloatRect(item_pos, item_size).contains(mouse_pos)) { + + if(!has_parent_with_selected_child_widget() && mouse_over_item == -1 && + mouse_pos.x >= scissor.position.x && mouse_pos.x <= scissor.position.x + scissor.size.x && + mouse_pos.y >= scissor.position.y && mouse_pos.y <= scissor.position.y + scissor.size.y && + mgl::FloatRect(item_pos, item_size).contains(mouse_pos)) + { // mgl::Rectangle selected_item_background(item_size.floor()); // selected_item_background.set_position(item_pos.floor()); // selected_item_background.set_color(mgl::Color(20, 20, 20, 150)); diff --git a/src/gui/ScrollablePage.cpp b/src/gui/ScrollablePage.cpp index 94da907..923a0c8 100644 --- a/src/gui/ScrollablePage.cpp +++ b/src/gui/ScrollablePage.cpp @@ -28,12 +28,12 @@ namespace gsr { offset.y += scroll_y; Widget *selected_widget = selected_child_widget; - if(event.type == mgl::Event::MouseButtonPressed || event.type == mgl::Event::MouseButtonReleased) { - if(!mgl::IntRect(scissor_pos, scissor_size).contains({event.mouse_button.x, event.mouse_button.y})) - return true; - } else if(event.type == mgl::Event::MouseMoved) { - if(!mgl::IntRect(scissor_pos, scissor_size).contains({event.mouse_move.x, event.mouse_move.y})) - return true; + if(event.type == mgl::Event::MouseButtonPressed && scrollbar_rect.contains(mgl::vec2f(event.mouse_button.x, event.mouse_button.y))) { + set_widget_as_selected_in_parent(); + moving_scrollbar_with_cursor = true; + scrollbar_move_cursor_start_pos = mgl::vec2f(event.mouse_button.x, event.mouse_button.y); + scrollbar_move_cursor_scroll_y_start = scroll_y; + return false; } if(event.type == mgl::Event::MouseButtonReleased && moving_scrollbar_with_cursor) { @@ -42,6 +42,14 @@ namespace gsr { return false; } + if(event.type == mgl::Event::MouseButtonPressed || event.type == mgl::Event::MouseButtonReleased) { + if(!mgl::IntRect(scissor_pos, scissor_size).contains({event.mouse_button.x, event.mouse_button.y})) + return true; + } else if(event.type == mgl::Event::MouseMoved) { + if(!mgl::IntRect(scissor_pos, scissor_size).contains({event.mouse_move.x, event.mouse_move.y})) + return true; + } + if(selected_widget) { if(!selected_widget->on_event(event, window, offset)) return false; @@ -65,14 +73,6 @@ namespace gsr { return false; } - if(event.type == mgl::Event::MouseButtonPressed && scrollbar_rect.contains(mgl::vec2f(event.mouse_button.x, event.mouse_button.y))) { - set_widget_as_selected_in_parent(); - moving_scrollbar_with_cursor = true; - scrollbar_move_cursor_start_pos = mgl::vec2f(event.mouse_button.x, event.mouse_button.y); - scrollbar_move_cursor_scroll_y_start = scroll_y; - return false; - } - return true; } |