ppizarror / pygame-menu

A menu for pygame. Simple, and easy to use
https://pygame-menu.readthedocs.io/
Other
544 stars 141 forks source link

image onselect like button action #442

Closed JaskRendix closed 1 year ago

JaskRendix commented 1 year ago

Hello, there!

Is your feature request related to a problem? Please describe. I'm trying to implement onselect (image > menu.add.image()) as action, so it can be triggered by clicking on it. My issue is that I use the keyboard, not the mouse, and as soon as I move over the image, it triggers the function.

Describe the solution you'd like hybrid, banner (menu.add.banner), it would be exactly as image, but instead of onselect there is action (like the button > menu.add.button()). Something like this:

    def banner(
            self,
            image_path: Union[str, 'Path', 'pygame_menu.BaseImage', 'BytesIO'],
            angle: NumberType = 0,
            banner_id: str = '',
            action: Optional[Union['pygame_menu.Menu', '_events.MenuAction', Callable, int]] = None,
            scale: Vector2NumberType = (1, 1),
            scale_smooth: bool = True,
            selectable: bool = False,
            **kwargs
    ) -> 'pygame_menu.widgets.Banner':

[...]

        widget = Banner(
            angle=angle,
            banner_id=banner_id,
            image_path=image_path,
            action=action,
            scale=scale,
            scale_smooth=scale_smooth
        )
        widget.is_selectable = selectable
ppizarror commented 1 year ago

Hi! That is a nice addition. I've added a new method to the Widgetmanager named menu.add.banner which does exactly the same.


menu = ...

# We create the image
image = pygame_menu.BaseImage(
    image_path=pygame_menu.baseimage.IMAGE_EXAMPLE_PYGAME_MENU
).scale(0.25, 0.25)

btn = menu.add.banner(image, test)
ppizarror commented 1 year ago

In this case, add.banner returns a Button object, thus, it responds to apply, the mouse, cursors, etc.

ppizarror commented 1 year ago

Version updated to v4.3.6. Check out and let me if this solves your issue.

JaskRendix commented 1 year ago

That's perfect! Thank you so much, it solves my issue!