Skip to content

Update button docs v2#99

Open
slideglide wants to merge 5 commits intogeode-sdk:mainfrom
slideglide:main
Open

Update button docs v2#99
slideglide wants to merge 5 commits intogeode-sdk:mainfrom
slideglide:main

Conversation

@slideglide
Copy link
Contributor

  • Use CCMenuItemExt
  • Add a section to create buttons without menus by using geode::Button

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Geode SDK button documentation to use CCMenuItemExt instead of raw CCMenuItemSpriteExtra with menu_selector, and adds a new section documenting Geode's menuless Button class. It also expands the "Based button sprites" section with detailed examples for CircleButtonSprite, CategoryButtonSprite, AccountButtonSprite, and EditorButtonSprite.

Changes:

  • Replaces all CCMenuItemSpriteExtra + menu_selector examples with CCMenuItemExt::createSpriteExtra using lambda callbacks
  • Adds a new "Menuless buttons" section documenting geode::Button with usage examples, callbacks, click counter example, and parameter passing
  • Expands the "Based button sprites" section with detailed examples for all four button sprite types (Circle, Category, Account, Editor)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +319 to +322
By using [EditorButtonSprite](https://docs.geode-sdk.org/classes/geode/AccountButtonSprite/), you can create button sprites with the same base as the right-side action buttons in the level editor.

### Example
Here's an example on how you can create a editor button sprite programmatically:
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

"a editor" should be "an editor" — the word "editor" starts with a vowel sound.

Suggested change
By using [EditorButtonSprite](https://docs.geode-sdk.org/classes/geode/AccountButtonSprite/), you can create button sprites with the same base as the right-side action buttons in the level editor.
### Example
Here's an example on how you can create a editor button sprite programmatically:
## Editor button sprites
By using [EditorButtonSprite](https://docs.geode-sdk.org/classes/geode/AccountButtonSprite/), you can create button sprites with the same base as the right-side action buttons in the level editor.
### Example
Here's an example on how you can create an editor button sprite programmatically:

Copilot uses AI. Check for mistakes.
Comment on lines +96 to +103
size_t m_clicked = 0;

// Label that displays the number of clicks
CCLabelBMFont* m_label = nullptr;

void updateCounter(int delta) {
m_clicked += delta;
m_label->setString(fmt::format("Clicked: {}", m_clicked).c_str());
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

m_clicked is declared as size_t (unsigned), but updateCounter adds an int delta to it. When delta is -1 and m_clicked is 0, this will cause unsigned integer underflow/wraparound. Since this is tutorial code meant to teach best practices, consider changing m_clicked to int (or adding a bounds check) to avoid teaching a pattern that silently produces incorrect results.

Copilot uses AI. Check for mistakes.
Comment on lines +197 to +198
// getNormalImage returns the sprite of the button
auto spr = static_cast<ButtonSprite*>(sender->getNormalImage());
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The Button class does not inherit from CCMenuItem, so sender->getNormalImage() is likely not available on Button*. The getNormalImage() method belongs to CCMenuItemSprite (and its subclass CCMenuItemSpriteExtra). If Button doesn't expose a similar method, this example code would not compile. Please verify what method Button provides to access its child sprite, and update the example accordingly.

Suggested change
// getNormalImage returns the sprite of the button
auto spr = static_cast<ButtonSprite*>(sender->getNormalImage());
// getSprite returns the sprite of the button
auto spr = static_cast<ButtonSprite*>(sender->getSprite());

Copilot uses AI. Check for mistakes.

auto spr = ButtonSprite::create("Hi mom!");

// Create methods other than createWithNode requires giving the sprite as a string in the first parameter, this is why we should use this for our ButtonSprite.
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

"Create methods other than createWithNode requires giving the sprite as a string" has a subject-verb agreement error. "Methods" is plural, so it should be "require" instead of "requires". Also, the comment says sprites are given "as a string", but what it likely means is that the sprite is specified by its name (a string parameter). Consider rephrasing for clarity, e.g., "Create methods other than createWithNode require the sprite to be specified as a string name..."

Suggested change
// Create methods other than createWithNode requires giving the sprite as a string in the first parameter, this is why we should use this for our ButtonSprite.
// Create methods other than createWithNode require the sprite to be specified by its string name in the first parameter, so we should use this one for our ButtonSprite.

Copilot uses AI. Check for mistakes.

this->addChild(menu);
## Passing more parameters to callbacks
One common issue when working with button callbacks is handling situations where you want to pass additional parameters to a function. For example, what if in the click counter example we also wanted to add a decrement button? We could write a separate callback for each button, but that would be unnecessary duplication. Instead, we can simply pass parameters **directly through lambda captures**.
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

This "Passing more parameters to callbacks" section (lines 211-254) is nearly identical to the one in the CCMenuItemExt section (lines 88-135) — the introductory text at line 212 is word-for-word the same as line 89, and the code structure is the same with only CCMenuItemExt::createSpriteExtra replaced by Button::createWithNode. Consider either consolidating the two sections (e.g., explaining lambda captures once and noting it applies to both approaches) or at least differentiating the text to avoid verbatim duplication.

Suggested change
One common issue when working with button callbacks is handling situations where you want to pass additional parameters to a function. For example, what if in the click counter example we also wanted to add a decrement button? We could write a separate callback for each button, but that would be unnecessary duplication. Instead, we can simply pass parameters **directly through lambda captures**.
Just like in the earlier `CCMenuItemExt` example, you may run into cases where a `Button` callback needs extra information beyond the sender itself. For instance, suppose we want to extend the click counter with a decrement button as well; writing a separate function for each button would be redundant, so instead we rely on C++ **lambda captures** to pass in the needed parameters.

Copilot uses AI. Check for mistakes.
Comment on lines +218 to +225
size_t m_clicked = 0;

return true;
// Label that displays the number of clicks
CCLabelBMFont* m_label = nullptr;

void updateCounter(int delta) {
m_clicked += delta;
m_label->setString(fmt::format("Clicked: {}", m_clicked).c_str());
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

Same size_t + negative int underflow issue as in the CCMenuItemExt section. m_clicked is size_t (unsigned) but updateCounter accepts an int delta which can be -1. Consider using int for m_clicked instead.

Copilot uses AI. Check for mistakes.
1.0f, // The scale of the sprite (float)
EditorBaseColor::LightBlue, // Available options: LightBlue, Green, Orange, DarkGray, Gray, Pink, Teal, Aqua, Cyan, Magenta, DimGreen, BrightGreen, Salmon
EditorBaseSize::Normal
); No newline at end of file
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The code block opened at line 324 is never closed — the file ends without a closing ```. This will cause the markdown to render incorrectly, with everything after line 324 being treated as part of the code block.

Copilot uses AI. Check for mistakes.
);
```
## Editor button sprites
By using [EditorButtonSprite](https://docs.geode-sdk.org/classes/geode/AccountButtonSprite/), you can create button sprites with the same base as the right-side action buttons in the level editor.
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The link for EditorButtonSprite incorrectly points to AccountButtonSprite's documentation page (https://docs.geode-sdk.org/classes/geode/AccountButtonSprite/). It should point to the EditorButtonSprite documentation page instead (e.g., https://docs.geode-sdk.org/classes/geode/EditorButtonSprite/).

Suggested change
By using [EditorButtonSprite](https://docs.geode-sdk.org/classes/geode/AccountButtonSprite/), you can create button sprites with the same base as the right-side action buttons in the level editor.
By using [EditorButtonSprite](https://docs.geode-sdk.org/classes/geode/EditorButtonSprite/), you can create button sprites with the same base as the right-side action buttons in the level editor.

Copilot uses AI. Check for mistakes.
By using [AccountButtonSprite](https://docs.geode-sdk.org/classes/geode/AccountButtonSprite/), you can create button sprites with a cross base, like the buttons in the main menu.

### Example
Here's an example on how you can create a category button sprite programmatically:
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

This says "category button sprite" but it's in the Account button sprites section. It should say "account button sprite" instead.

Suggested change
Here's an example on how you can create a category button sprite programmatically:
Here's an example on how you can create an account button sprite programmatically:

Copilot uses AI. Check for mistakes.
@slideglide
Copy link
Contributor Author

thank you copilot

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.

2 participants