settings_ui: Handle enums with fields (#37945)

Closes #ISSUE

Adds handling for Enums with fields (i.e. not `enum Foo { Yes, No }`) in
Settings UI. Accomplished by creating default values for each element
with fields (in the derive macro), and rendering a toggle button group
with a button for each variant where switching the active variant sets
the value in the settings JSON to the default for the new active
variant.

Release Notes:

- N/A *or* Added/Fixed/Improved ...

---------

Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
Ben Kunkle
2025-09-10 18:02:08 -04:00
committed by GitHub
co-authored by Conrad
parent 95ccce3095
commit 2ce0641fe0
6 changed files with 472 additions and 300 deletions
+11 -1
View File
@@ -108,10 +108,19 @@ impl<T: serde::Serialize> SettingsValue<T> {
#[derive(Clone)]
pub struct SettingsUiItemUnion {
pub options: Vec<SettingsUiEntry>,
/// Must be the same length as `labels` and `options`
pub defaults: Box<[serde_json::Value]>,
/// Must be the same length as defaults` and `options`
pub labels: &'static [&'static str],
/// Must be the same length as `defaults` and `labels`
pub options: Box<[Option<SettingsUiEntry>]>,
pub determine_option: fn(&serde_json::Value, &App) -> usize,
}
// todo(settings_ui): use in ToggleGroup and Dropdown
#[derive(Clone)]
pub struct SettingsEnumVariants {}
pub struct SettingsUiEntryMetaData {
pub title: SharedString,
pub path: SharedString,
@@ -136,6 +145,7 @@ pub enum SettingsUiItem {
Single(SettingsUiItemSingle),
Union(SettingsUiItemUnion),
DynamicMap(SettingsUiItemDynamicMap),
// Array(SettingsUiItemArray), // code-actions: array of objects, array of string
None,
}