settings ui: Improve setting proc macro and add scroll to UI (#37581)

This PR improves the settings_ui proc macro by taking into account more
serde attributes
1. rename_all
2. rename
3. flatten

We also pass field documentation to the UI layer now too. This allows ui
elements to have more information like the switch field description.

We got the scrollbar working and started getting language settings to
show up.

Release Notes:

- N/A

---------

Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
Anthony Eid
2025-09-04 22:30:48 +00:00
committed by GitHub
co-authored by Ben Kunkle
parent c7902478c1
commit 0cb8a8983c
5 changed files with 257 additions and 82 deletions
+9
View File
@@ -19,6 +19,7 @@ pub trait SettingsUi {
path: None,
title: "None entry",
item: SettingsUiItem::None,
documentation: None,
}
}
}
@@ -29,6 +30,8 @@ pub struct SettingsUiEntry {
pub path: Option<&'static str>,
/// What is displayed for the text for this entry
pub title: &'static str,
/// documentation for this entry. Constructed from the documentation comment above the struct or field
pub documentation: Option<&'static str>,
pub item: SettingsUiItem,
}
@@ -54,6 +57,7 @@ pub enum SettingsUiItemSingle {
pub struct SettingsValue<T> {
pub title: &'static str,
pub documentation: Option<&'static str>,
pub path: SmallVec<[&'static str; 1]>,
pub value: Option<T>,
pub default_value: T,
@@ -128,7 +132,9 @@ pub enum NumType {
U64 = 0,
U32 = 1,
F32 = 2,
USIZE = 3,
}
pub static NUM_TYPE_NAMES: std::sync::LazyLock<[&'static str; NumType::COUNT]> =
std::sync::LazyLock::new(|| NumType::ALL.map(NumType::type_name));
pub static NUM_TYPE_IDS: std::sync::LazyLock<[TypeId; NumType::COUNT]> =
@@ -143,6 +149,7 @@ impl NumType {
NumType::U64 => TypeId::of::<u64>(),
NumType::U32 => TypeId::of::<u32>(),
NumType::F32 => TypeId::of::<f32>(),
NumType::USIZE => TypeId::of::<usize>(),
}
}
@@ -151,6 +158,7 @@ impl NumType {
NumType::U64 => std::any::type_name::<u64>(),
NumType::U32 => std::any::type_name::<u32>(),
NumType::F32 => std::any::type_name::<f32>(),
NumType::USIZE => std::any::type_name::<usize>(),
}
}
}
@@ -175,3 +183,4 @@ numeric_stepper_for_num_type!(u64, U64);
numeric_stepper_for_num_type!(u32, U32);
// todo(settings_ui) is there a better ui for f32?
numeric_stepper_for_num_type!(f32, F32);
numeric_stepper_for_num_type!(usize, USIZE);