Fix UI font size changes not applying (#25307)

Related to #24857.

Release Notes:

- N/A
This commit is contained in:
João Marcos 2025-02-21 06:24:02 -03:00 committed by GitHub
parent 4871d3c9e7
commit 5e1dd91ee5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 35 additions and 25 deletions

View file

@ -2227,7 +2227,7 @@ impl PromptEditor {
}, },
font_family: settings.buffer_font.family.clone(), font_family: settings.buffer_font.family.clone(),
font_fallbacks: settings.buffer_font.fallbacks.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, font_weight: settings.buffer_font.weight,
line_height: relative(settings.buffer_line_height.value()), line_height: relative(settings.buffer_line_height.value()),
..Default::default() ..Default::default()

View file

@ -1049,7 +1049,7 @@ impl PromptEditor {
}, },
font_family: settings.buffer_font.family.clone(), font_family: settings.buffer_font.family.clone(),
font_fallbacks: settings.buffer_font.fallbacks.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, font_weight: settings.buffer_font.weight,
line_height: relative(settings.buffer_line_height.value()), line_height: relative(settings.buffer_line_height.value()),
..Default::default() ..Default::default()

View file

@ -56,7 +56,7 @@ impl<T: 'static> EventEmitter<PromptEditorEvent> for PromptEditor<T> {}
impl<T: 'static> Render for PromptEditor<T> { impl<T: 'static> Render for PromptEditor<T> {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { 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 mut buttons = Vec::new();
let left_gutter_width = match &self.mode { let left_gutter_width = match &self.mode {

View file

@ -210,7 +210,7 @@ impl Render for CommitTooltip {
.as_ref() .as_ref()
.and_then(|details| details.pull_request.clone()); .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); let message_max_height = window.line_height() * 12 + (ui_font_size / 0.4);
tooltip_container(window, cx, move |this, _, cx| { tooltip_container(window, cx, move |this, _, cx| {

View file

@ -125,8 +125,7 @@ impl EditableSettingControl for BufferFontSizeControl {
} }
fn read(cx: &App) -> Self::Value { fn read(cx: &App) -> Self::Value {
let settings = ThemeSettings::get_global(cx); ThemeSettings::get_global(cx).buffer_font_size(cx)
settings.buffer_font_size
} }
fn apply( fn apply(

View file

@ -339,7 +339,7 @@ fn show_hover(
base_text_style.refine(&TextStyleRefinement { base_text_style.refine(&TextStyleRefinement {
font_family: Some(settings.ui_font.family.clone()), font_family: Some(settings.ui_font.family.clone()),
font_fallbacks: settings.ui_font.fallbacks.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), color: Some(cx.theme().colors().editor_foreground),
background_color: Some(gpui::transparent_black()), background_color: Some(gpui::transparent_black()),

View file

@ -206,7 +206,7 @@ impl Editor {
color: cx.theme().colors().text, color: cx.theme().colors().text,
font_family: settings.buffer_font.family.clone(), font_family: settings.buffer_font.family.clone(),
font_fallbacks: settings.buffer_font.fallbacks.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, font_weight: settings.buffer_font.weight,
line_height: relative(settings.buffer_line_height.value()), line_height: relative(settings.buffer_line_height.value()),
..Default::default() ..Default::default()

View file

@ -141,7 +141,7 @@ impl CommitModal {
let settings = ThemeSettings::get_global(cx); let settings = ThemeSettings::get_global(cx);
let line_height = relative(settings.buffer_line_height.value()) 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() v_flex()
.justify_between() .justify_between()

View file

@ -186,7 +186,7 @@ impl SshPrompt {
let refinement = TextStyleRefinement { let refinement = TextStyleRefinement {
font_family: Some(theme.buffer_font.family.clone()), font_family: Some(theme.buffer_font.family.clone()),
font_features: Some(FontFeatures::disable_ligatures()), 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), color: Some(cx.theme().colors().editor_foreground),
background_color: Some(gpui::transparent_black()), background_color: Some(gpui::transparent_black()),
..Default::default() ..Default::default()

View file

@ -186,7 +186,7 @@ impl Cell {
let refinement = TextStyleRefinement { let refinement = TextStyleRefinement {
font_family: Some(theme.buffer_font.family.clone()), 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), color: Some(cx.theme().colors().editor_foreground),
background_color: Some(gpui::transparent_black()), background_color: Some(gpui::transparent_black()),
..Default::default() ..Default::default()

View file

@ -94,7 +94,7 @@ impl TableView {
let text_system = window.text_system(); let text_system = window.text_system();
let text_style = window.text_style(); let text_style = window.text_style();
let text_font = ThemeSettings::get_global(cx).buffer_font.clone(); 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 { let mut runs = [TextRun {
len: 0, len: 0,
font: text_font, font: text_font,

View file

@ -239,8 +239,7 @@ impl EditableSettingControl for UiFontSizeControl {
} }
fn read(cx: &App) -> Self::Value { fn read(cx: &App) -> Self::Value {
let settings = ThemeSettings::get_global(cx); ThemeSettings::get_global(cx).ui_font_size(cx)
settings.ui_font_size
} }
fn apply( fn apply(

View file

@ -95,13 +95,17 @@ pub struct ThemeSettings {
/// as well as the size of a [gpui::Rems] unit. /// as well as the size of a [gpui::Rems] unit.
/// ///
/// Changing this will impact the size of all UI elements. /// 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. /// The font used for UI elements.
pub ui_font: Font, pub ui_font: Font,
/// The font size used for buffers, and the terminal. /// The font size used for buffers, and the terminal.
/// ///
/// The terminal font size can be overridden using it's own setting. /// 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 font used for buffers, and the terminal.
/// ///
/// The terminal font family can be overridden using it's own setting. /// The terminal font family can be overridden using it's own setting.
@ -569,6 +573,14 @@ impl ThemeSettings {
clamp_font_size(font_size) 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` // TODO: Rename: `line_height` -> `buffer_line_height`
/// Returns the buffer's line height. /// Returns the buffer's line height.
pub fn line_height(&self) -> f32 { 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. /// Gets the adjusted UI font size.
pub fn get_ui_font_size(cx: &App) -> Pixels { 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>() cx.try_global::<AdjustedUiFontSize>()
.map_or(ui_font_size, |adjusted_size| adjusted_size.0) .map_or(ui_font_size, |adjusted_size| adjusted_size.0)
} }
/// Sets the adjusted UI font size. /// Sets the adjusted UI font size.
pub fn adjust_ui_font_size(cx: &mut App, mut f: impl FnMut(&mut Pixels)) { 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 let mut adjusted_size = cx
.try_global::<AdjustedUiFontSize>() .try_global::<AdjustedUiFontSize>()
.map_or(ui_font_size, |adjusted_size| adjusted_size.0); .map_or(ui_font_size, |adjusted_size| adjusted_size.0);

View file

@ -103,9 +103,9 @@ pub fn init(themes_to_load: LoadThemes, cx: &mut App) {
ThemeSettings::register(cx); ThemeSettings::register(cx);
FontFamilyCache::init_global(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| { 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 { if buffer_font_size != prev_buffer_font_size {
prev_buffer_font_size = buffer_font_size; prev_buffer_font_size = buffer_font_size;
reset_buffer_font_size(cx); reset_buffer_font_size(cx);

View file

@ -507,7 +507,7 @@ impl ContextMenuItem {
impl Render for ContextMenu { impl Render for ContextMenu {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { 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 let aside = self
.documentation_aside .documentation_aside

View file

@ -140,8 +140,8 @@ impl TextSize {
Self::Default => rems_from_px(14.), Self::Default => rems_from_px(14.),
Self::Small => rems_from_px(12.), Self::Small => rems_from_px(12.),
Self::XSmall => rems_from_px(10.), Self::XSmall => rems_from_px(10.),
Self::Ui => rems_from_px(theme_settings.ui_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.into()), Self::Editor => rems_from_px(theme_settings.buffer_font_size(cx).into()),
} }
} }
} }

View file

@ -157,7 +157,7 @@ pub fn derive_spacing(input: TokenStream) -> TokenStream {
/// Returns the spacing value in pixels. /// Returns the spacing value in pixels.
pub fn px(&self, cx: &App) -> 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)) px(ui_font_size_f32 * self.spacing_ratio(cx))
} }
} }

View file

@ -39,7 +39,7 @@ pub fn fallback_prompt_renderer(
let mut base_text_style = window.text_style(); let mut base_text_style = window.text_style();
base_text_style.refine(&TextStyleRefinement { base_text_style.refine(&TextStyleRefinement {
font_family: Some(settings.ui_font.family.clone()), 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)), color: Some(ui::Color::Muted.color(cx)),
..Default::default() ..Default::default()
}); });