Skip to content

Enum support in SettingsGroup derive macro, implemented key attribute#23719

Open
mpowell90 wants to merge 5 commits intobevyengine:mainfrom
mpowell90:feat/extend-settings-group
Open

Enum support in SettingsGroup derive macro, implemented key attribute#23719
mpowell90 wants to merge 5 commits intobevyengine:mainfrom
mpowell90:feat/extend-settings-group

Conversation

@mpowell90
Copy link
Copy Markdown

@mpowell90 mpowell90 commented Apr 8, 2026

Objective

Implements part of #23302

For background on bevy settings see the initial PR:
#23034

Solution

Supports unit-like Enum resources:

#[derive(Resource, SettingsGroup, Reflect, Debug, Default)]
#[reflect(Resource, SettingsGroup, Default)]
enum CounterRefreshRateSettings {
    #[default]
    Slow,
    Fast,
}

Assuming the above is initialised as CounterRefreshRateSettings::Slow, results in:

[counter_refresh_rate_settings]
counter_refresh_rate_settings = "Slow"

Setting the group attribute works the same as structs:

#[settings_group(group = "counter_settings")]

Results in:

[counter_settings]
counter_refresh_rate_settings = "Slow"

This PR adds a key attribute which can only be used on enums (for now), otherwise a compile-time error is thrown:

#[settings_group(key = "refresh_rate")]

Results in:

[counter_refresh_rate_settings]
refresh_rate = "Slow"

Testing

  • Added tests that checks merging enums into groups and round trip serialisation.
  • Added a "cheat sheet" for the derive syntax, immitating other derive macros in the file.

@alice-i-cecile alice-i-cecile requested a review from viridia April 8, 2026 16:42
@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Dev-Tools Tools used to debug Bevy applications. labels Apr 8, 2026
@alice-i-cecile alice-i-cecile added this to the 0.19 milestone Apr 8, 2026
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Apr 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-23719

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

Copy link
Copy Markdown
Contributor

@viridia viridia left a comment

Choose a reason for hiding this comment

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

Awesome work!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-23719

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@mpowell90 mpowell90 force-pushed the feat/extend-settings-group branch from 24abb12 to 6b56f1f Compare April 8, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Dev-Tools Tools used to debug Bevy applications. C-Feature A new feature, making something new possible S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants