AustL / PygameWidgets

A module for use with Pygame. Includes fully customisable buttons, textboxes, sliders and many more, as well as the ability to create and run animations on these widgets.
MIT License
57 stars 16 forks source link

Buttons get clicked when the mouse is pressed outside the button and then dragged into the button area. #40

Closed tgonzalez89 closed 3 years ago

tgonzalez89 commented 3 years ago

How to reproduce: 1) Press the mouse button outside any widget button area. 2) Drag the mouse (with the mouse button still pressed) into a widget button num. 1 area. 3) Observe that the onClick function is called for button num. 1. 4) With the mouse button still pressed keep dragging into another button. 5) Observe that the onClick function is called for button num. 2.

Video illustrating the issue

slashformotion commented 3 years ago

hhhmmmmm that's a problem

AustL commented 3 years ago

I just realised this is a larger issue dealing with how the program handles mouse input. I'm currently in the process of fixing this. This will change the use of the program, unfortunately, so will probably in be a new release (v1.0.0).

tgonzalez89 commented 3 years ago

I was going to file another issue, but I think it is probably related to this one. If I click on an item of a dropdown menu and another widget is positioned behind the dropped dropdown menu, the widget behind also gets clicked. The workaround I did was to hide the button that was getting clicked while the dropdown is dropped and then show the hidden button once the dropdown is no longer dropped.

slashformotion commented 3 years ago

perhaps the best way is to implement a layer-ish way of displaying the widgets aka putting them in an ordered list. Then search from the end which widget have been clicked on

slashformotion commented 3 years ago

perhaps the best way is to implement a layer-ish way of displaying the widgets aka putting them in an ordered list. Then search from the end which widget have been clicked on

@AustL is that's the case we need to implement a new Window class that handle this like this perhaps

class Window: 
    def __init__(self, size) -> None:
        self.__widgets = list()

    def _add_widgets(self, new_widget, pos =None):
        """add widget to the window

        :param new_widget: the new widget to add to 'self'
        :type new_widget: widget    
        :param pos: position of the widget in the list, defaults to None
        :type pos: intor None, optional
        """
        self.__widgets.append(new_widget)

    def close(self):
        pass # close the window 

The main problem I see with this is that the module is going to be transformed to become an ui framework and not a library you can easily use in your project

AustL commented 3 years ago

@slashformotion I've already started doing this. Most of this will occur automatically, so changes to the usage will be minimal.

slashformotion commented 3 years ago

@AustL i looked the branch, it's pretty smart

AustL commented 3 years ago

I was going to file another issue, but I think it is probably related to this one. If I click on an item of a dropdown menu and another widget is positioned behind the dropped dropdown menu, the widget behind also gets clicked. The workaround I did was to hide the button that was getting clicked while the dropdown is dropped and then show the hidden button once the dropdown is no longer dropped.

This issue is fixed for the dropdown, however, it still occurs for the combobox widget. This is due to the combobox being triggered on 'click', while the dropdown is triggered on 'release'. Based on the implementation of the combo-box, I can't find an easy fix. I think when the dropdown menu closes, the mouse click somehow still registers for the button, although it does not when one widget covers another (like two buttons overlapping).

AustL commented 3 years ago

The mouse and widget handling system is now working, so I will create a beta-release until I can document it properly.