Detailed changes
@@ -2227,7 +2227,7 @@ impl PromptEditor {
},
font_family: settings.buffer_font.family.clone(),
font_fallbacks: settings.buffer_font.fallbacks.clone(),
- font_size: settings.buffer_font_size.into(),
+ font_size: settings.buffer_font_size(cx).into(),
font_weight: settings.buffer_font.weight,
line_height: relative(settings.buffer_line_height.value()),
..Default::default()
@@ -1049,7 +1049,7 @@ impl PromptEditor {
},
font_family: settings.buffer_font.family.clone(),
font_fallbacks: settings.buffer_font.fallbacks.clone(),
- font_size: settings.buffer_font_size.into(),
+ font_size: settings.buffer_font_size(cx).into(),
font_weight: settings.buffer_font.weight,
line_height: relative(settings.buffer_line_height.value()),
..Default::default()
@@ -56,7 +56,7 @@ impl<T: 'static> EventEmitter<PromptEditorEvent> for PromptEditor<T> {}
impl<T: 'static> Render for PromptEditor<T> {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
- let ui_font_size = ThemeSettings::get_global(cx).ui_font_size;
+ let ui_font_size = ThemeSettings::get_global(cx).ui_font_size(cx);
let mut buttons = Vec::new();
let left_gutter_width = match &self.mode {
@@ -210,7 +210,7 @@ impl Render for CommitTooltip {
.as_ref()
.and_then(|details| details.pull_request.clone());
- let ui_font_size = ThemeSettings::get_global(cx).ui_font_size;
+ let ui_font_size = ThemeSettings::get_global(cx).ui_font_size(cx);
let message_max_height = window.line_height() * 12 + (ui_font_size / 0.4);
tooltip_container(window, cx, move |this, _, cx| {
@@ -125,8 +125,7 @@ impl EditableSettingControl for BufferFontSizeControl {
}
fn read(cx: &App) -> Self::Value {
- let settings = ThemeSettings::get_global(cx);
- settings.buffer_font_size
+ ThemeSettings::get_global(cx).buffer_font_size(cx)
}
fn apply(
@@ -339,7 +339,7 @@ fn show_hover(
base_text_style.refine(&TextStyleRefinement {
font_family: Some(settings.ui_font.family.clone()),
font_fallbacks: settings.ui_font.fallbacks.clone(),
- font_size: Some(settings.ui_font_size.into()),
+ font_size: Some(settings.ui_font_size(cx).into()),
color: Some(cx.theme().colors().editor_foreground),
background_color: Some(gpui::transparent_black()),
@@ -206,7 +206,7 @@ impl Editor {
color: cx.theme().colors().text,
font_family: settings.buffer_font.family.clone(),
font_fallbacks: settings.buffer_font.fallbacks.clone(),
- font_size: settings.buffer_font_size.into(),
+ font_size: settings.buffer_font_size(cx).into(),
font_weight: settings.buffer_font.weight,
line_height: relative(settings.buffer_line_height.value()),
..Default::default()
@@ -141,7 +141,7 @@ impl CommitModal {
let settings = ThemeSettings::get_global(cx);
let line_height = relative(settings.buffer_line_height.value())
- .to_pixels(settings.buffer_font_size.into(), window.rem_size());
+ .to_pixels(settings.buffer_font_size(cx).into(), window.rem_size());
v_flex()
.justify_between()
@@ -186,7 +186,7 @@ impl SshPrompt {
let refinement = TextStyleRefinement {
font_family: Some(theme.buffer_font.family.clone()),
font_features: Some(FontFeatures::disable_ligatures()),
- font_size: Some(theme.buffer_font_size.into()),
+ font_size: Some(theme.buffer_font_size(cx).into()),
color: Some(cx.theme().colors().editor_foreground),
background_color: Some(gpui::transparent_black()),
..Default::default()
@@ -186,7 +186,7 @@ impl Cell {
let refinement = TextStyleRefinement {
font_family: Some(theme.buffer_font.family.clone()),
- font_size: Some(theme.buffer_font_size.into()),
+ font_size: Some(theme.buffer_font_size(cx).into()),
color: Some(cx.theme().colors().editor_foreground),
background_color: Some(gpui::transparent_black()),
..Default::default()
@@ -94,7 +94,7 @@ impl TableView {
let text_system = window.text_system();
let text_style = window.text_style();
let text_font = ThemeSettings::get_global(cx).buffer_font.clone();
- let font_size = ThemeSettings::get_global(cx).buffer_font_size;
+ let font_size = ThemeSettings::get_global(cx).buffer_font_size(cx);
let mut runs = [TextRun {
len: 0,
font: text_font,
@@ -239,8 +239,7 @@ impl EditableSettingControl for UiFontSizeControl {
}
fn read(cx: &App) -> Self::Value {
- let settings = ThemeSettings::get_global(cx);
- settings.ui_font_size
+ ThemeSettings::get_global(cx).ui_font_size(cx)
}
fn apply(
@@ -95,13 +95,17 @@ pub struct ThemeSettings {
/// as well as the size of a [gpui::Rems] unit.
///
/// Changing this will impact the size of all UI elements.
- pub ui_font_size: Pixels,
+ ///
+ /// Use [ThemeSettings::ui_font_size] to access this.
+ ui_font_size: Pixels,
/// The font used for UI elements.
pub ui_font: Font,
/// The font size used for buffers, and the terminal.
///
/// The terminal font size can be overridden using it's own setting.
- pub buffer_font_size: Pixels,
+ ///
+ /// Use [ThemeSettings::buffer_font_size] to access this.
+ buffer_font_size: Pixels,
/// The font used for buffers, and the terminal.
///
/// The terminal font family can be overridden using it's own setting.
@@ -569,6 +573,14 @@ impl ThemeSettings {
clamp_font_size(font_size)
}
+ /// Returns the UI font size.
+ pub fn ui_font_size(&self, cx: &App) -> Pixels {
+ let font_size = cx
+ .try_global::<AdjustedUiFontSize>()
+ .map_or(self.ui_font_size, |size| size.0);
+ clamp_font_size(font_size)
+ }
+
// TODO: Rename: `line_height` -> `buffer_line_height`
/// Returns the buffer's line height.
pub fn line_height(&self) -> f32 {
@@ -715,14 +727,14 @@ pub fn setup_ui_font(window: &mut Window, cx: &mut App) -> gpui::Font {
/// Gets the adjusted UI font size.
pub fn get_ui_font_size(cx: &App) -> Pixels {
- let ui_font_size = ThemeSettings::get_global(cx).ui_font_size;
+ let ui_font_size = ThemeSettings::get_global(cx).ui_font_size(cx);
cx.try_global::<AdjustedUiFontSize>()
.map_or(ui_font_size, |adjusted_size| adjusted_size.0)
}
/// Sets the adjusted UI font size.
pub fn adjust_ui_font_size(cx: &mut App, mut f: impl FnMut(&mut Pixels)) {
- let ui_font_size = ThemeSettings::get_global(cx).ui_font_size;
+ let ui_font_size = ThemeSettings::get_global(cx).ui_font_size(cx);
let mut adjusted_size = cx
.try_global::<AdjustedUiFontSize>()
.map_or(ui_font_size, |adjusted_size| adjusted_size.0);
@@ -103,9 +103,9 @@ pub fn init(themes_to_load: LoadThemes, cx: &mut App) {
ThemeSettings::register(cx);
FontFamilyCache::init_global(cx);
- let mut prev_buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;
+ let mut prev_buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size(cx);
cx.observe_global::<SettingsStore>(move |cx| {
- let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;
+ let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size(cx);
if buffer_font_size != prev_buffer_font_size {
prev_buffer_font_size = buffer_font_size;
reset_buffer_font_size(cx);
@@ -507,7 +507,7 @@ impl ContextMenuItem {
impl Render for ContextMenu {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
- let ui_font_size = ThemeSettings::get_global(cx).ui_font_size;
+ let ui_font_size = ThemeSettings::get_global(cx).ui_font_size(cx);
let aside = self
.documentation_aside
@@ -140,8 +140,8 @@ impl TextSize {
Self::Default => rems_from_px(14.),
Self::Small => rems_from_px(12.),
Self::XSmall => rems_from_px(10.),
- Self::Ui => rems_from_px(theme_settings.ui_font_size.into()),
- Self::Editor => rems_from_px(theme_settings.buffer_font_size.into()),
+ Self::Ui => rems_from_px(theme_settings.ui_font_size(cx).into()),
+ Self::Editor => rems_from_px(theme_settings.buffer_font_size(cx).into()),
}
}
}
@@ -157,7 +157,7 @@ pub fn derive_spacing(input: TokenStream) -> TokenStream {
/// Returns the spacing value in pixels.
pub fn px(&self, cx: &App) -> Pixels {
- let ui_font_size_f32: f32 = ThemeSettings::get_global(cx).ui_font_size.into();
+ let ui_font_size_f32: f32 = ThemeSettings::get_global(cx).ui_font_size(cx).into();
px(ui_font_size_f32 * self.spacing_ratio(cx))
}
}
@@ -39,7 +39,7 @@ pub fn fallback_prompt_renderer(
let mut base_text_style = window.text_style();
base_text_style.refine(&TextStyleRefinement {
font_family: Some(settings.ui_font.family.clone()),
- font_size: Some(settings.ui_font_size.into()),
+ font_size: Some(settings.ui_font_size(cx).into()),
color: Some(ui::Color::Muted.color(cx)),
..Default::default()
});