Enable buffer font size adjustment in zed2
Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
parent
f7c995c4a0
commit
89c8a7c242
5 changed files with 24 additions and 28 deletions
|
@ -9291,7 +9291,7 @@ impl Render for 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_features: settings.buffer_font.features,
|
font_features: settings.buffer_font.features,
|
||||||
font_size: settings.buffer_font_size.into(),
|
font_size: settings.buffer_font_size(cx).into(),
|
||||||
font_weight: FontWeight::NORMAL,
|
font_weight: FontWeight::NORMAL,
|
||||||
font_style: FontStyle::Normal,
|
font_style: FontStyle::Normal,
|
||||||
line_height: relative(settings.buffer_line_height.value()),
|
line_height: relative(settings.buffer_line_height.value()),
|
||||||
|
|
|
@ -860,7 +860,6 @@ impl AppContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove the global of the given type from the app context. Does not notify global observers.
|
/// Remove the global of the given type from the app context. Does not notify global observers.
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
|
||||||
pub fn remove_global<G: Any>(&mut self) -> G {
|
pub fn remove_global<G: Any>(&mut self) -> G {
|
||||||
let global_type = TypeId::of::<G>();
|
let global_type = TypeId::of::<G>();
|
||||||
*self
|
*self
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub struct ThemeSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AdjustedBufferFontSize(Option<Pixels>);
|
pub struct AdjustedBufferFontSize(Pixels);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||||
pub struct ThemeSettingsContent {
|
pub struct ThemeSettingsContent {
|
||||||
|
@ -69,12 +69,10 @@ impl BufferLineHeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThemeSettings {
|
impl ThemeSettings {
|
||||||
pub fn buffer_font_size(&self, cx: &mut AppContext) -> Pixels {
|
pub fn buffer_font_size(&self, cx: &AppContext) -> Pixels {
|
||||||
let font_size = *cx
|
cx.try_global::<AdjustedBufferFontSize>()
|
||||||
.default_global::<AdjustedBufferFontSize>()
|
.map_or(self.buffer_font_size, |size| size.0)
|
||||||
.0
|
.max(MIN_FONT_SIZE)
|
||||||
.get_or_insert(self.buffer_font_size.into());
|
|
||||||
font_size.max(MIN_FONT_SIZE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn line_height(&self) -> f32 {
|
pub fn line_height(&self) -> f32 {
|
||||||
|
@ -83,9 +81,9 @@ impl ThemeSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn adjusted_font_size(size: Pixels, cx: &mut AppContext) -> Pixels {
|
pub fn adjusted_font_size(size: Pixels, cx: &mut AppContext) -> Pixels {
|
||||||
if let Some(adjusted_size) = cx.default_global::<AdjustedBufferFontSize>().0 {
|
if let Some(AdjustedBufferFontSize(adjusted_size)) = cx.try_global::<AdjustedBufferFontSize>() {
|
||||||
let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;
|
let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;
|
||||||
let delta = adjusted_size - buffer_font_size;
|
let delta = *adjusted_size - buffer_font_size;
|
||||||
size + delta
|
size + delta
|
||||||
} else {
|
} else {
|
||||||
size
|
size
|
||||||
|
@ -95,18 +93,19 @@ pub fn adjusted_font_size(size: Pixels, cx: &mut AppContext) -> Pixels {
|
||||||
|
|
||||||
pub fn adjust_font_size(cx: &mut AppContext, f: fn(&mut Pixels)) {
|
pub fn adjust_font_size(cx: &mut AppContext, f: fn(&mut Pixels)) {
|
||||||
let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;
|
let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;
|
||||||
let adjusted_size = cx
|
let mut adjusted_size = cx
|
||||||
.default_global::<AdjustedBufferFontSize>()
|
.try_global::<AdjustedBufferFontSize>()
|
||||||
.0
|
.map_or(buffer_font_size, |adjusted_size| adjusted_size.0);
|
||||||
.get_or_insert(buffer_font_size);
|
|
||||||
f(adjusted_size);
|
f(&mut adjusted_size);
|
||||||
*adjusted_size = (*adjusted_size).max(MIN_FONT_SIZE - buffer_font_size);
|
adjusted_size = adjusted_size.max(MIN_FONT_SIZE);
|
||||||
|
cx.set_global(AdjustedBufferFontSize(adjusted_size));
|
||||||
cx.refresh();
|
cx.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset_font_size(cx: &mut AppContext) {
|
pub fn reset_font_size(cx: &mut AppContext) {
|
||||||
if cx.has_global::<AdjustedBufferFontSize>() {
|
if cx.has_global::<AdjustedBufferFontSize>() {
|
||||||
cx.global_mut::<AdjustedBufferFontSize>().0 = None;
|
cx.remove_global::<AdjustedBufferFontSize>();
|
||||||
cx.refresh();
|
cx.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,8 +70,7 @@ pub trait StyledExt: Styled + Sized {
|
||||||
/// or other places that text needs to match the user's buffer font size.
|
/// or other places that text needs to match the user's buffer font size.
|
||||||
fn text_buffer(self, cx: &mut WindowContext) -> Self {
|
fn text_buffer(self, cx: &mut WindowContext) -> Self {
|
||||||
let settings = ThemeSettings::get_global(cx);
|
let settings = ThemeSettings::get_global(cx);
|
||||||
|
self.text_size(settings.buffer_font_size(cx))
|
||||||
self.text_size(settings.buffer_font_size)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [`Surface`](ui2::ElevationIndex::Surface) elevation level, located above the app background, is the standard level for all elements
|
/// The [`Surface`](ui2::ElevationIndex::Surface) elevation level, located above the app background, is the standard level for all elements
|
||||||
|
|
|
@ -235,14 +235,13 @@ pub fn initialize_workspace(app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||||
.open_urls(&[action.url.clone()])
|
.open_urls(&[action.url.clone()])
|
||||||
})
|
})
|
||||||
.register_action(|_, action: &OpenBrowser, cx| cx.open_url(&action.url))
|
.register_action(|_, action: &OpenBrowser, cx| cx.open_url(&action.url))
|
||||||
//todo!(buffer font size)
|
.register_action(move |_, _: &IncreaseBufferFontSize, cx| {
|
||||||
// cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| {
|
theme::adjust_font_size(cx, |size| *size += px(1.0))
|
||||||
// theme::adjust_font_size(cx, |size| *size += 1.0)
|
})
|
||||||
// });
|
.register_action(move |_, _: &DecreaseBufferFontSize, cx| {
|
||||||
// cx.add_global_action(move |_: &DecreaseBufferFontSize, cx| {
|
theme::adjust_font_size(cx, |size| *size -= px(1.0))
|
||||||
// theme::adjust_font_size(cx, |size| *size -= 1.0)
|
})
|
||||||
// });
|
.register_action(move |_, _: &ResetBufferFontSize, cx| theme::reset_font_size(cx))
|
||||||
// cx.add_global_action(move |_: &ResetBufferFontSize, cx| theme::reset_font_size(cx));
|
|
||||||
.register_action(|_, _: &install_cli::Install, cx| {
|
.register_action(|_, _: &install_cli::Install, cx| {
|
||||||
cx.spawn(|_, cx| async move {
|
cx.spawn(|_, cx| async move {
|
||||||
install_cli::install_cli(cx.deref())
|
install_cli::install_cli(cx.deref())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue