Conversation
There was a problem hiding this comment.
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_selectorexamples withCCMenuItemExt::createSpriteExtrausing lambda callbacks - Adds a new "Menuless buttons" section documenting
geode::Buttonwith 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.
tutorials/buttons.md
Outdated
| 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: |
There was a problem hiding this comment.
"a editor" should be "an editor" — the word "editor" starts with a vowel sound.
| 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: |
tutorials/buttons.md
Outdated
| 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()); |
There was a problem hiding this comment.
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.
tutorials/buttons.md
Outdated
| // getNormalImage returns the sprite of the button | ||
| auto spr = static_cast<ButtonSprite*>(sender->getNormalImage()); |
There was a problem hiding this comment.
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.
| // 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()); |
tutorials/buttons.md
Outdated
|
|
||
| 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. |
There was a problem hiding this comment.
"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..."
| // 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. |
tutorials/buttons.md
Outdated
|
|
||
| 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**. |
There was a problem hiding this comment.
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.
| 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. |
tutorials/buttons.md
Outdated
| 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()); |
There was a problem hiding this comment.
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.
tutorials/buttons.md
Outdated
| 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 |
There was a problem hiding this comment.
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.
tutorials/buttons.md
Outdated
| ); | ||
| ``` | ||
| ## 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. |
There was a problem hiding this comment.
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/).
| 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. |
tutorials/buttons.md
Outdated
| 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: |
There was a problem hiding this comment.
This says "category button sprite" but it's in the Account button sprites section. It should say "account button sprite" instead.
| 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: |
|
thank you copilot |
CCMenuItemExtgeode::Button