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:
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user