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 bindings for the Playdate System Menu API #16

Closed
wants to merge 1 commit into from

Conversation

adamsoutar
Copy link
Contributor

👋 This PR adds bindings for interacting with the System Menu.

For example:

unsafe extern "C" fn callback (_: *mut c_void) {
    log_to_console!("Hello, system menu!")
}
        
system.add_menu_item("say hi", Some(callback))?;

It also supports "checkmark" and "options" menu items:

let checkbox = system.add_checkmark_menu_item("cool?", true, Some(callback))?;

let is_cool = checkbox.get_checked()?; // true/false


let options = system.add_options_menu_item("choice", vec![
    "one", "two", "three"
], Some(callback))?; 

let selected_index = options.get_value(); // 0, 1, or 2

Totally open to feedback/thoughts on this one since it's a bit bigger than my previous PRs and involves a bit of API design 🙂

This adds functions for interacting with the System Menu,
including regular, checkmark, and options items, as well as manipulating
them after creation.
@rtsuk
Copy link
Collaborator

rtsuk commented Apr 25, 2022

I feel we need to figure out a safe mechanism to put in place of the unsafe callback before adding this.

Does the SKD doc say anything about when this callback will be called, relative to the other callbacks Crankstart is already handling?

@adamsoutar
Copy link
Contributor Author

adamsoutar commented Apr 25, 2022

Hmm, I think you're right. Initially I couldn't figure out a way to pass in a Rust function with any useful context since closures etc. can't be passed as simple function pointers. However, this SO question seems to provide some ways to do it - I'll look into it.

In terms of timing, the docs say that pressing a menu item

  • Fires the menu item callback
  • Closes the system menu
  • Calls eventHandler() with kEventResume

in that order

@rtsuk
Copy link
Collaborator

rtsuk commented Apr 25, 2022

As long as we are reasonably certain that none of the other callbacks ever get called while the menu is open, we could handle it the way we handle the other callbacks and perhaps add a method to the Game trait.

@rtsuk
Copy link
Collaborator

rtsuk commented Apr 25, 2022

Reading the system menu docs I think that there are two ways to go; either make menu items like sprites or design an API for Rust that doesn't require an immediate callback per item and keep all the references to menu items internal to Crankstart.

@rtsuk
Copy link
Collaborator

rtsuk commented Feb 26, 2023

Closing this as it is quite old. Please feel free to re-open.

@rtsuk rtsuk closed this Feb 26, 2023
@tjkirch
Copy link
Contributor

tjkirch commented Feb 26, 2023

I'd really like to have system menu access for my game. @rtsuk would you mind if I create an issue to track this, and try to summarize the issues under consideration above?

@rtsuk
Copy link
Collaborator

rtsuk commented Feb 27, 2023

Go for it!

@tjkirch tjkirch mentioned this pull request Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants