pythonarcade / arcade

Easy to use Python library for creating 2D arcade games.
http://arcade.academy
Other
1.69k stars 319 forks source link

Bug report and Enhancement proposal for UIButtonRow class #2149

Open alej0varas opened 3 months ago

alej0varas commented 3 months ago

Summary

This issue report addresses two key points:

  1. A bug encountered when instantiating the UIButtonRow class with a callback argument.
  2. A request for an enhancement to allow setting button attributes like height and width when calling add_button.

If needed, I can split these into separate issues based on our discussion.

Bug Report

System Info

Arcade 3.0.0.dev27

vendor: Intel renderer: Mesa Intel(R) HD Graphics 530 (SKL GT2) version: (4, 6) python: 3.11.9 (main, Jun 17 2024, 15:35:00) [GCC 13.2.1 20240210] platform: linux pyglet version: 2.1.dev2 PIL version: 10.2.0

Description

Instantiating the UIButtonRow class with the callback argument raises a TypeError.

Actual Behavior

When using the callback argument, the following error occurs:

TypeError: UIButtonRow.__init__() got an unexpected keyword argument 'callback'

Expected Behavior

Instantiating the UIButtonRow class with a callback argument should assign the callback to self.on_action.

Steps to Reproduce

def callback(event):
    pass

button_row = arcade.gui.constructs.UIButtonRow(callback=callback)

Enhancement Request

Description

There is a need to set button attributes like height and width when calling add_button.

Proposed Change

Allow the add_button method to accept additional arguments for button attributes such as height and width.

Example Implementation

I have included a small patch below to illustrate the changes made locally. Note that this is not a definitive proposal but an example of what works for my use case.

3a4
> 
6c7
< from typing import Any, Optional
---
> from typing import Any, Callable, Optional
121a123
>         height=1,
129a132
>         callback: Callable[UIOnClickEvent, None] = None,
131a135
>             height=height,
142a147
>         self.on_action = callback
149a155
>         height=1,
151c157,159
<         button = self.button_factory(text=label, style=style, multiline=multiline)
---
>         button = self.button_factory(
>             text=label, style=style, multiline=multiline, height=height
>         )
einarf commented 3 months ago

Did you also try with 3.0.0.dev29?

alej0varas commented 3 months ago

I've tried with 3.0.0.dev29 now and I get the same results.

eruvanos commented 3 months ago

Looking into it