settings ui: Use font picker element from onboarding instead of editor for font components (#39593)

The font picker from onboarding is a lot friendlier to interact with and
makes it impossible for a user to select an invalid font from the
settings ui.

I also moved the font picker from the onboarding crate to the ui_input
crate

## New Look
<img width="1136" height="812" alt="image"
src="https://github.com/user-attachments/assets/7436682c-6a41-4860-a18b-13e15b8f3f31"
/>

Release Notes:

- N/A
This commit is contained in:
Anthony Eid
2025-10-06 13:04:43 -04:00
committed by GitHub
parent a67a55d81a
commit ea60a7b172
8 changed files with 272 additions and 183 deletions
+71 -4
View File
@@ -24,8 +24,8 @@ use std::{
sync::{Arc, atomic::AtomicBool},
};
use ui::{
ContextMenu, Divider, DropdownMenu, DropdownStyle, IconButtonShape, Switch, SwitchColor,
TreeViewItem, WithScrollbar, prelude::*,
ButtonLike, ContextMenu, Divider, DropdownMenu, DropdownStyle, IconButtonShape, PopoverMenu,
Switch, SwitchColor, TreeViewItem, WithScrollbar, prelude::*,
};
use ui_input::{NumericStepper, NumericStepperStyle, NumericStepperType};
use util::{ResultExt as _, paths::PathStyle, rel_path::RelPath};
@@ -2758,9 +2758,9 @@ fn init_renderers(cx: &mut App) {
.add_renderer::<CloseWindowWhenNoItems>(|settings_field, file, _, window, cx| {
render_dropdown(*settings_field, file, window, cx)
})
.add_renderer::<settings::FontFamilyName>(|settings_field, file, metadata, _, cx| {
.add_renderer::<settings::FontFamilyName>(|settings_field, file, _, window, cx| {
// todo(settings_ui): We need to pass in a validator for this to ensure that users that type in invalid font names
render_text_field(settings_field.clone(), file, metadata, cx)
render_font_picker(settings_field.clone(), file, window, cx)
})
.add_renderer::<settings::BufferLineHeight>(|settings_field, file, _, window, cx| {
// todo(settings_ui): Do we want to expose the custom variant of buffer line height?
@@ -3127,6 +3127,16 @@ impl SettingsUiFile {
impl SettingsWindow {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let font_family_cache = theme::FontFamilyCache::global(cx);
cx.spawn(async move |this, cx| {
font_family_cache.prefetch(cx).await;
this.update(cx, |_, cx| {
cx.notify();
})
})
.detach();
let current_file = SettingsUiFile::User;
let search_bar = cx.new(|cx| {
let mut editor = Editor::single_line(window, cx);
@@ -3770,6 +3780,63 @@ fn render_toggle_button<B: Into<bool> + From<bool> + Copy>(
.into_any_element()
}
fn render_font_picker(
field: SettingField<settings::FontFamilyName>,
file: SettingsUiFile,
window: &mut Window,
cx: &mut App,
) -> AnyElement {
let current_value = SettingsStore::global(cx)
.get_value_from_file(file.to_settings(), field.pick)
.1
.clone();
let font_picker = cx.new(|cx| {
ui_input::font_picker(
current_value.clone().into(),
move |font_name, cx| {
update_settings_file(file.clone(), cx, move |settings, _cx| {
*(field.pick_mut)(settings) = Some(font_name.into());
})
.log_err(); // todo(settings_ui) don't log err
},
window,
cx,
)
});
div()
.child(
PopoverMenu::new("font-picker")
.menu(move |_window, _cx| Some(font_picker.clone()))
.trigger(
ButtonLike::new("font-family-button")
.style(ButtonStyle::Outlined)
.size(ButtonSize::Medium)
.full_width()
.child(
h_flex()
.w_full()
.justify_between()
.child(Label::new(current_value))
.child(
Icon::new(IconName::ChevronUpDown)
.color(Color::Muted)
.size(IconSize::XSmall),
),
),
)
.full_width(true)
.anchor(gpui::Corner::TopLeft)
.offset(gpui::Point {
x: px(0.0),
y: px(4.0),
})
.with_handle(ui::PopoverMenuHandle::default()),
)
.into_any_element()
}
fn render_numeric_stepper<T: NumericStepperType + Send + Sync>(
field: SettingField<T>,
file: SettingsUiFile,