Update approach to settings

Co-Authored-By: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
This commit is contained in:
Nate Butler 2023-10-18 16:16:58 -04:00
parent 289255d67a
commit 8b637e194e
7 changed files with 59 additions and 83 deletions

View file

@ -1,102 +1,70 @@
use std::ops::Deref;
use gpui3::{rems, AbsoluteLength};
use crate::DisclosureControlStyle;
// This is a fake static example of user settings overriding the default settings
pub fn user_settings() -> Settings {
let mut settings = Settings::new();
settings.list_indent_depth = Some(rems(0.5).into());
let mut settings = Settings::default();
settings.list_indent_depth = SettingValue::UserDefined(rems(0.5).into());
settings
}
#[derive(Clone, Copy)]
#[derive(Clone)]
pub enum SettingValue<T> {
UserDefined(T),
Default(T),
}
impl<T> Deref for SettingValue<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
match self {
Self::UserDefined(value) => value,
Self::Default(value) => value,
}
}
}
#[derive(Clone)]
pub struct TitlebarSettings {
pub show_project_owner: Option<bool>,
pub show_git_status: Option<bool>,
pub show_git_controls: Option<bool>,
pub show_project_owner: SettingValue<bool>,
pub show_git_status: SettingValue<bool>,
pub show_git_controls: SettingValue<bool>,
}
impl Default for TitlebarSettings {
fn default() -> Self {
Self {
show_project_owner: Some(true),
show_git_status: Some(true),
show_git_controls: Some(true),
show_project_owner: SettingValue::Default(true),
show_git_status: SettingValue::Default(true),
show_git_controls: SettingValue::Default(true),
}
}
}
#[derive(Clone, Copy)]
pub struct Settings {
pub default_panel_size: Option<AbsoluteLength>,
pub list_disclosure_style: Option<DisclosureControlStyle>,
pub list_indent_depth: Option<AbsoluteLength>,
pub titlebar: TitlebarSettings,
pub ui_scale: Option<f32>,
}
// These should be merged into settings
impl Settings {
pub fn new() -> Self {
Self {
titlebar: TitlebarSettings::default(),
list_disclosure_style: None,
list_indent_depth: None,
default_panel_size: None,
ui_scale: None,
}
}
pub fn titlebar_show_project_owner(&self) -> bool {
self.titlebar.show_project_owner.unwrap_or(
Settings::default()
.titlebar
.show_project_owner
.expect("titlebar_show_project_owner default not set."),
)
}
pub fn list_disclosure_style(&self) -> DisclosureControlStyle {
self.list_disclosure_style.unwrap_or(
Settings::default()
.list_disclosure_style
.expect("list_disclosure_style default not set."),
)
}
pub fn list_indent_depth(&self) -> AbsoluteLength {
self.list_indent_depth.unwrap_or(
Settings::default()
.list_indent_depth
.expect("list_indent_depth default not set."),
)
}
pub fn default_panel_size(&self) -> AbsoluteLength {
self.default_panel_size.unwrap_or(
Settings::default()
.default_panel_size
.expect("default_panel_size default not set."),
)
}
pub fn ui_scale(&self) -> f32 {
self.ui_scale.unwrap_or(
Settings::default()
.ui_scale
.expect("ui_scale default not set."),
)
}
#[derive(Clone)]
pub struct Settings {
pub default_panel_size: SettingValue<AbsoluteLength>,
pub list_disclosure_style: SettingValue<DisclosureControlStyle>,
pub list_indent_depth: SettingValue<AbsoluteLength>,
pub titlebar: TitlebarSettings,
pub ui_scale: SettingValue<f32>,
}
impl Default for Settings {
fn default() -> Self {
Self {
titlebar: TitlebarSettings::default(),
list_disclosure_style: Some(DisclosureControlStyle::ChevronOnHover),
list_indent_depth: Some(rems(0.3).into()),
default_panel_size: Some(rems(16.).into()),
ui_scale: Some(1.),
list_disclosure_style: SettingValue::Default(DisclosureControlStyle::ChevronOnHover),
list_indent_depth: SettingValue::Default(rems(0.3).into()),
default_panel_size: SettingValue::Default(rems(16.).into()),
ui_scale: SettingValue::Default(1.),
}
}
}
impl Settings {}