DirectOptionMenu button does not resize on items modification


#1

For a card game, I’m using a DirectOptionMenu to show the human player his/her options when it’s his/her turn such that he can select one from the popup menu in order to make a play.

The menu updates its items at the beginning of the human player’s turn through a call

self['items'] = [str(action) for action in self._actions]

where self._actions is a list of action objects that have appropriate str methods.

The display of the popup menu and the selection and action triggering work.

I initialize the DirectOptionMenu object with an empty list (as there are no options to choose from at the beginning of the game).
Now, when I update the list, the main button representing the DirectOptionMenu does not resize with the texts of the items (in contrasts to the popup, which does so correctly).

Is there any method I should call after modifying the items?

Best
Niklas


#2

For reference, this is what it looks like right now:

DirectOptionMenu: direct_option_menu

Popup: direct_option_menu_popup


#3

https://www.panda3d.org/manual/?title=DirectOptionMenu

Did you pass in textMayChange=1? “Whether the text on the menu changes with the selection”


#4

If that alone doesn’t work, try calling “resetFrameSize”, as described here: https://www.panda3d.org/manual/?title=DirectGUI


#5

I tried both suggestions in conjunction and on their own. Unfortunately, neither changed the behavior of the DirectOptionMenu.

However, I did some more fiddling. In my current design, I was subclassing DirectOptionMenu. It turns out that this does not work well, not even with a fixed and constructor time initialized items list.
Changing the design such that my ActionsMenu uses a child property to hold the DirectOptionMenu fixed the behavior with a static items list.

Then I found out that if I additionally initialize the DirectOptionMenu with a one-item list (items=[""]) in the constructor and immediately after change the items to whatever I need (empty list or list of actual actions) it does work.

In this sense my problem is resolved now. But I conclude that the behaviour of the DirectOptionMenu is a little worrisome.

Best
Niklas


#6

Ah–Subclassing DirectGUI elements can be tricky at times. There are a few steps that it expects to be taken, such as calling “initialiseoptions” in the “init” method, I think.

I thought that we had some information somewhere regarding the sub-classing of DirectGUI elements, but I don’t seem to be finding it at the moment, I’m afraid. :/