Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose PopupMenu get_item_multistate() and set/get_item_multistate_max() #87395

Merged
merged 1 commit into from
Jan 24, 2024

Conversation

mrcdk
Copy link
Contributor

@mrcdk mrcdk commented Jan 20, 2024

I noticed that while you can set and toggle a PopupMenu multistate item with PopupMenu.set_item_multistate() and PopupMenu.toggle_item_multistate() there was no way to get the state of the item. I also noticed that there was no way to get or set the max_states so I've exposed them to the scripting languages.

@AThousandShips
Copy link
Member

Please open a proposal to track the support and details of this feature 🙂

@mrcdk
Copy link
Contributor Author

mrcdk commented Jan 20, 2024

Please open a proposal to track the support and details of this feature 🙂

Opened here godotengine/godot-proposals#8918

Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely these items were not exposed since it's not entirely obvious how to use them. Unlike checked property, multistate is not auto updated or validated on menu item clicks, so you need to handle it manually. It's OK to expose them, but a usage example probably should be added to the documentation.

@mrcdk
Copy link
Contributor Author

mrcdk commented Jan 20, 2024

Most likely these items were not exposed since it's not entirely obvious how to use them. Unlike checked property, multistate is not auto updated or validated on menu item clicks, so you need to handle it manually. It's OK to expose them, but a usage example probably should be added to the documentation.

I've updated the PR with an example usage

Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If existing exposed methods have multistate in their name, these new ones should too. Specifically when you consider the pair set_item_multistate/get_item_state. I don't see the underlying properties used outside of this multistate functionality, so I don't think there is a reason to use a disassociated name.

The max state methods could be called set_item_multistate_max/get_item_multistate_max, but they are probably fine as is. They also currently match the global menu API. So up to you.

@YuriSizov YuriSizov modified the milestones: 4.x, 4.3 Jan 22, 2024
@mrcdk
Copy link
Contributor Author

mrcdk commented Jan 22, 2024

If existing exposed methods have multistate in their name, these new ones should too. Specifically when you consider the pair set_item_multistate/get_item_state. I don't see the underlying properties used outside of this multistate functionality, so I don't think there is a reason to use a disassociated name.

The max state methods could be called set_item_multistate_max/get_item_multistate_max, but they are probably fine as is. They also currently match the global menu API. So up to you.

I thought about that but internally in the engine the PopupMenu API was using get_item_state() and there's also DisplayServer.global_menu_get_item_state() so I kept it like that. Technically any item can be a multistate item by setting the max_states variable with set_item_max_states() (added in this PR). DisplayServer's global_menu exposes them like DisplayServer.global_menu_get_item_max_states() and DisplayServer.global_menu_set_item_max_states()

I would personally rename set_item_multistate() to set_item_state() like what global_menu does (DisplayServer.global_menu_set_item_state()) and toggle_item_multistate() to advance_item_state() or something similar but that would break compatibility. Maybe we could deprecate those functions and rename them?

@YuriSizov
Copy link
Contributor

YuriSizov commented Jan 22, 2024

@mrcdk The internal name doesn't really matter as it wasn't added with the public name in mind, clearly. Us exposing it now is the perfect time to consider the name. This is also a very minor reason to break compatibility, so I would rather we named one new method to match the existing one.

Matching DisplayServer exactly would be nice, but not critical.

@mrcdk
Copy link
Contributor Author

mrcdk commented Jan 22, 2024

Okay! Done! Renamed:

  • get_item_state() to get_item_multistate()
  • get_item_max_states() to get_item_multistate_max()
  • set_item_max_states() to set_item_multistate_max()

@YuriSizov YuriSizov changed the title Expose PopupMenu get_item_state(), get_item_max_states() and set_item_max_states() Expose PopupMenu get_item_multistate() and set/get_item_multistate_max() Jan 24, 2024
An [param id] can optionally be provided, as well as an accelerator ([param accel]). If no [param id] is provided, one will be created from the index. If no [param accel] is provided, then the default value of 0 (corresponding to [constant @GlobalScope.KEY_NONE]) will be assigned to the item (which means it won't have any accelerator). See [method get_item_accelerator] for more info on accelerators.
[b]Note:[/b] Multistate items don't update their state automatically and must be done manually. See [method toggle_item_multistate], [method set_item_multistate] and [method get_item_multistate] for more info on how to control it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[b]Note:[/b] Multistate items don't update their state automatically and must be done manually. See [method toggle_item_multistate], [method set_item_multistate] and [method get_item_multistate] for more info on how to control it.
[b]Note:[/b] Multistate items don't update their state automatically and must be done manually. See [method toggle_item_multistate], [method set_item_multistate], and [method get_item_multistate] for more info on how to control it.

Please use Oxford comma.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this can be resolved later 🙃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were too late :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 11 minutes should be enough, I'll endeavour to be faster next time :þ

Copy link
Contributor

@YuriSizov YuriSizov Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd think so, but between me checking out this PR and queuing it up, then 20 others, then building it all to test everything is superficially okay, and then merging — it's nothing 😄

@YuriSizov YuriSizov merged commit d454fcc into godotengine:master Jan 24, 2024
16 checks passed
@YuriSizov
Copy link
Contributor

Thanks!

@mrcdk mrcdk deleted the popupmenu_get_state branch January 24, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Be able to access the PopupMenu item's state and get and set the item's max_state
4 participants