settings_ui: Add UI and buffer font family controls (#15124)
This PR adds settings controls for changing the UI and buffer font families. Release Notes: - N/A
This commit is contained in:
parent
001376fd6d
commit
659f34bf21
4 changed files with 191 additions and 6 deletions
52
crates/theme/src/font_family_cache.rs
Normal file
52
crates/theme/src/font_family_cache.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
|
||||
use gpui::{AppContext, Global, ReadGlobal, SharedString};
|
||||
use parking_lot::RwLock;
|
||||
|
||||
#[derive(Default)]
|
||||
struct FontFamilyCacheState {
|
||||
loaded_at: Option<Instant>,
|
||||
font_families: Vec<SharedString>,
|
||||
}
|
||||
|
||||
/// A cache for the list of font families.
|
||||
///
|
||||
/// Listing the available font families from the text system is expensive,
|
||||
/// so we do it once and then use the cached values each render.
|
||||
#[derive(Default)]
|
||||
pub struct FontFamilyCache {
|
||||
state: RwLock<FontFamilyCacheState>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct GlobalFontFamilyCache(Arc<FontFamilyCache>);
|
||||
|
||||
impl Global for GlobalFontFamilyCache {}
|
||||
|
||||
impl FontFamilyCache {
|
||||
pub fn init_global(cx: &mut AppContext) {
|
||||
cx.default_global::<GlobalFontFamilyCache>();
|
||||
}
|
||||
|
||||
pub fn global(cx: &AppContext) -> Arc<Self> {
|
||||
GlobalFontFamilyCache::global(cx).0.clone()
|
||||
}
|
||||
|
||||
pub fn list_font_families(&self, cx: &AppContext) -> Vec<SharedString> {
|
||||
if self.state.read().loaded_at.is_some() {
|
||||
return self.state.read().font_families.clone();
|
||||
}
|
||||
|
||||
let mut lock = self.state.write();
|
||||
lock.font_families = cx
|
||||
.text_system()
|
||||
.all_font_names()
|
||||
.into_iter()
|
||||
.map(SharedString::from)
|
||||
.collect();
|
||||
lock.loaded_at = Some(Instant::now());
|
||||
|
||||
lock.font_families.clone()
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
mod default_colors;
|
||||
mod default_theme;
|
||||
mod font_family_cache;
|
||||
mod one_themes;
|
||||
pub mod prelude;
|
||||
mod registry;
|
||||
|
@ -21,6 +22,7 @@ use std::sync::Arc;
|
|||
use ::settings::{Settings, SettingsStore};
|
||||
pub use default_colors::*;
|
||||
pub use default_theme::*;
|
||||
pub use font_family_cache::*;
|
||||
pub use registry::*;
|
||||
pub use scale::*;
|
||||
pub use schema::*;
|
||||
|
@ -82,6 +84,7 @@ pub fn init(themes_to_load: LoadThemes, cx: &mut AppContext) {
|
|||
}
|
||||
|
||||
ThemeSettings::register(cx);
|
||||
FontFamilyCache::init_global(cx);
|
||||
|
||||
let mut prev_buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;
|
||||
cx.observe_global::<SettingsStore>(move |cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue