settings_ui: Add UI and buffer font weight controls (#15104)
This PR adds settings controls for the UI and buffer font weight settings. It also does some work around grouping the settings into related sections. Release Notes: - N/A
This commit is contained in:
parent
7fb906d774
commit
274e56b086
16 changed files with 557 additions and 272 deletions
|
@ -13,10 +13,9 @@ path = "src/settings_ui.rs"
|
|||
|
||||
[dependencies]
|
||||
command_palette_hooks.workspace = true
|
||||
editor.workspace = true
|
||||
feature_flags.workspace = true
|
||||
fs.workspace = true
|
||||
gpui.workspace = true
|
||||
project.workspace = true
|
||||
settings.workspace = true
|
||||
theme.workspace = true
|
||||
ui.workspace = true
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
mod theme_settings_ui;
|
||||
mod theme_settings_controls;
|
||||
|
||||
use std::any::TypeId;
|
||||
|
||||
use command_palette_hooks::CommandPaletteFilter;
|
||||
use editor::EditorSettingsControls;
|
||||
use feature_flags::{FeatureFlag, FeatureFlagViewExt};
|
||||
use gpui::{actions, AppContext, EventEmitter, FocusHandle, FocusableView, View};
|
||||
use ui::prelude::*;
|
||||
use workspace::item::{Item, ItemEvent};
|
||||
use workspace::Workspace;
|
||||
|
||||
use crate::theme_settings_ui::{
|
||||
BufferFontSizeSetting, EditableSetting, InlineGitBlameSetting, UiFontSizeSetting,
|
||||
};
|
||||
use crate::theme_settings_controls::ThemeSettingsControls;
|
||||
|
||||
pub struct SettingsUiFeatureFlag;
|
||||
|
||||
|
@ -101,16 +100,23 @@ impl Item for SettingsPage {
|
|||
}
|
||||
|
||||
impl Render for SettingsPage {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
v_flex()
|
||||
.p_4()
|
||||
.size_full()
|
||||
.gap_4()
|
||||
.child(Label::new("Settings").size(LabelSize::Large))
|
||||
.child(Label::new(
|
||||
"Nothing to see here yet. Feature-flagged for staff.",
|
||||
))
|
||||
.child(UiFontSizeSetting::new(cx))
|
||||
.child(BufferFontSizeSetting::new(cx))
|
||||
.child(InlineGitBlameSetting::new(cx))
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_1()
|
||||
.child(Label::new("Appearance"))
|
||||
.child(ThemeSettingsControls::new()),
|
||||
)
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_1()
|
||||
.child(Label::new("Editor"))
|
||||
.child(EditorSettingsControls::new()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
112
crates/settings_ui/src/theme_settings_controls.rs
Normal file
112
crates/settings_ui/src/theme_settings_controls.rs
Normal file
|
@ -0,0 +1,112 @@
|
|||
use gpui::{AppContext, FontWeight};
|
||||
use settings::{EditableSettingControl, Settings};
|
||||
use theme::ThemeSettings;
|
||||
use ui::{prelude::*, ContextMenu, DropdownMenu, NumericStepper, SettingsContainer, SettingsGroup};
|
||||
|
||||
#[derive(IntoElement)]
|
||||
pub struct ThemeSettingsControls {}
|
||||
|
||||
impl ThemeSettingsControls {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for ThemeSettingsControls {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
SettingsContainer::new().child(
|
||||
SettingsGroup::new("Font")
|
||||
.child(UiFontSizeControl)
|
||||
.child(UiFontWeightControl),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(IntoElement)]
|
||||
struct UiFontSizeControl;
|
||||
|
||||
impl EditableSettingControl for UiFontSizeControl {
|
||||
type Value = Pixels;
|
||||
type Settings = ThemeSettings;
|
||||
|
||||
fn name(&self) -> SharedString {
|
||||
"UI Font Size".into()
|
||||
}
|
||||
|
||||
fn read(cx: &AppContext) -> Self::Value {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
settings.ui_font_size
|
||||
}
|
||||
|
||||
fn apply(settings: &mut <Self::Settings as Settings>::FileContent, value: Self::Value) {
|
||||
settings.ui_font_size = Some(value.into());
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for UiFontSizeControl {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
let value = Self::read(cx);
|
||||
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.child(Icon::new(IconName::FontSize))
|
||||
.child(NumericStepper::new(
|
||||
value.to_string(),
|
||||
move |_, cx| {
|
||||
Self::write(value - px(1.), cx);
|
||||
},
|
||||
move |_, cx| {
|
||||
Self::write(value + px(1.), cx);
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(IntoElement)]
|
||||
struct UiFontWeightControl;
|
||||
|
||||
impl EditableSettingControl for UiFontWeightControl {
|
||||
type Value = FontWeight;
|
||||
type Settings = ThemeSettings;
|
||||
|
||||
fn name(&self) -> SharedString {
|
||||
"UI Font Weight".into()
|
||||
}
|
||||
|
||||
fn read(cx: &AppContext) -> Self::Value {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
settings.ui_font.weight
|
||||
}
|
||||
|
||||
fn apply(settings: &mut <Self::Settings as Settings>::FileContent, value: Self::Value) {
|
||||
settings.ui_font_weight = Some(value.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for UiFontWeightControl {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
let value = Self::read(cx);
|
||||
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.child(Icon::new(IconName::FontWeight))
|
||||
.child(DropdownMenu::new(
|
||||
"ui-font-weight",
|
||||
value.0.to_string(),
|
||||
ContextMenu::build(cx, |mut menu, _cx| {
|
||||
for weight in FontWeight::ALL {
|
||||
menu = menu.custom_entry(
|
||||
move |_cx| Label::new(weight.0.to_string()).into_any_element(),
|
||||
{
|
||||
move |cx| {
|
||||
Self::write(weight, cx);
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
menu
|
||||
}),
|
||||
))
|
||||
}
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
use fs::Fs;
|
||||
use gpui::AppContext;
|
||||
use project::project_settings::{InlineBlameSettings, ProjectSettings};
|
||||
use settings::{update_settings_file, Settings};
|
||||
use theme::ThemeSettings;
|
||||
use ui::{prelude::*, CheckboxWithLabel, NumericStepper};
|
||||
|
||||
pub trait EditableSetting: RenderOnce {
|
||||
/// The type of the setting value.
|
||||
type Value: Send;
|
||||
|
||||
/// The settings type to which this setting belongs.
|
||||
type Settings: Settings;
|
||||
|
||||
/// Returns the name of this setting.
|
||||
fn name(&self) -> SharedString;
|
||||
|
||||
/// Returns the icon to be displayed in place of the setting name.
|
||||
fn icon(&self) -> Option<IconName> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Returns a new instance of this setting.
|
||||
fn new(cx: &AppContext) -> Self;
|
||||
|
||||
/// Applies the given setting file to the settings file contents.
|
||||
///
|
||||
/// This will be called when writing the setting value back to the settings file.
|
||||
fn apply(settings: &mut <Self::Settings as Settings>::FileContent, value: Self::Value);
|
||||
|
||||
/// Writes the given setting value to the settings files.
|
||||
fn write(value: Self::Value, cx: &AppContext) {
|
||||
let fs = <dyn Fs>::global(cx);
|
||||
|
||||
update_settings_file::<Self::Settings>(fs, cx, move |settings, _cx| {
|
||||
Self::apply(settings, value);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(IntoElement)]
|
||||
pub struct UiFontSizeSetting(Pixels);
|
||||
|
||||
impl EditableSetting for UiFontSizeSetting {
|
||||
type Value = Pixels;
|
||||
type Settings = ThemeSettings;
|
||||
|
||||
fn name(&self) -> SharedString {
|
||||
"UI Font Size".into()
|
||||
}
|
||||
|
||||
fn icon(&self) -> Option<IconName> {
|
||||
Some(IconName::FontSize)
|
||||
}
|
||||
|
||||
fn new(cx: &AppContext) -> Self {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
|
||||
Self(settings.ui_font_size)
|
||||
}
|
||||
|
||||
fn apply(settings: &mut <Self::Settings as Settings>::FileContent, value: Self::Value) {
|
||||
settings.ui_font_size = Some(value.into());
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for UiFontSizeSetting {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
let value = self.0;
|
||||
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.map(|el| {
|
||||
if let Some(icon) = self.icon() {
|
||||
el.child(Icon::new(icon))
|
||||
} else {
|
||||
el.child(Label::new(self.name()))
|
||||
}
|
||||
})
|
||||
.child(NumericStepper::new(
|
||||
self.0.to_string(),
|
||||
move |_, cx| {
|
||||
Self::write(value - px(1.), cx);
|
||||
},
|
||||
move |_, cx| {
|
||||
Self::write(value + px(1.), cx);
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(IntoElement)]
|
||||
pub struct BufferFontSizeSetting(Pixels);
|
||||
|
||||
impl EditableSetting for BufferFontSizeSetting {
|
||||
type Value = Pixels;
|
||||
type Settings = ThemeSettings;
|
||||
|
||||
fn name(&self) -> SharedString {
|
||||
"Buffer Font Size".into()
|
||||
}
|
||||
|
||||
fn icon(&self) -> Option<IconName> {
|
||||
Some(IconName::FontSize)
|
||||
}
|
||||
|
||||
fn new(cx: &AppContext) -> Self {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
|
||||
Self(settings.buffer_font_size)
|
||||
}
|
||||
|
||||
fn apply(settings: &mut <Self::Settings as Settings>::FileContent, value: Self::Value) {
|
||||
settings.buffer_font_size = Some(value.into());
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for BufferFontSizeSetting {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
let value = self.0;
|
||||
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.map(|el| {
|
||||
if let Some(icon) = self.icon() {
|
||||
el.child(Icon::new(icon))
|
||||
} else {
|
||||
el.child(Label::new(self.name()))
|
||||
}
|
||||
})
|
||||
.child(NumericStepper::new(
|
||||
self.0.to_string(),
|
||||
move |_, cx| {
|
||||
Self::write(value - px(1.), cx);
|
||||
},
|
||||
move |_, cx| {
|
||||
Self::write(value + px(1.), cx);
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(IntoElement)]
|
||||
pub struct InlineGitBlameSetting(bool);
|
||||
|
||||
impl EditableSetting for InlineGitBlameSetting {
|
||||
type Value = bool;
|
||||
type Settings = ProjectSettings;
|
||||
|
||||
fn name(&self) -> SharedString {
|
||||
"Inline Git Blame".into()
|
||||
}
|
||||
|
||||
fn new(cx: &AppContext) -> Self {
|
||||
let settings = ProjectSettings::get_global(cx);
|
||||
Self(settings.git.inline_blame_enabled())
|
||||
}
|
||||
|
||||
fn apply(settings: &mut <Self::Settings as Settings>::FileContent, value: Self::Value) {
|
||||
if let Some(inline_blame) = settings.git.inline_blame.as_mut() {
|
||||
inline_blame.enabled = value;
|
||||
} else {
|
||||
settings.git.inline_blame = Some(InlineBlameSettings {
|
||||
enabled: false,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for InlineGitBlameSetting {
|
||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
||||
let value = self.0;
|
||||
|
||||
CheckboxWithLabel::new(
|
||||
"inline-git-blame",
|
||||
Label::new(self.name()),
|
||||
value.into(),
|
||||
|selection, cx| {
|
||||
Self::write(
|
||||
match selection {
|
||||
Selection::Selected => true,
|
||||
Selection::Unselected | Selection::Indeterminate => false,
|
||||
},
|
||||
cx,
|
||||
);
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue