LucasPilla / Sorting-Algorithms-Visualizer

Program made with Python and Pygame module for visualizing sorting algorithms
MIT License
426 stars 164 forks source link

Delay, algorithm, and play/stop buttons are too responsive #187

Closed chenrbin closed 1 month ago

chenrbin commented 9 months ago

Description These update function for boxes currently check if the mouse button is pressed and if the mouse position collides with the rectangle. They can be registered as active by moving the mouse over the boxes while the mouse button is held down, which produces some unnatural-seeming behavior. This can be observed by dragging the mouse across the bottom menu. Notably, dragging the mouse across the play button results in the algorithm running multiple times.

Solution Adjust the update function for these boxes to check for a mouse button down event, which will let them register as active only once per click. Additionally, the slide box logic can be reworked such that the slider will match the held mouse's x position while within the box horizontal bounds if the box is clicked but unresponsive if the box is not clicked.

I would like to implement this. Thanks!