mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
Enable buffer font size adjustment in zed2 (#3523)
This commit is contained in:
commit
a8d96790cf
@ -9291,7 +9291,7 @@ impl Render for Editor {
|
||||
color: cx.theme().colors().text,
|
||||
font_family: settings.buffer_font.family.clone(),
|
||||
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_style: FontStyle::Normal,
|
||||
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.
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub fn remove_global<G: Any>(&mut self) -> G {
|
||||
let global_type = TypeId::of::<G>();
|
||||
*self
|
||||
|
@ -27,7 +27,7 @@ pub struct ThemeSettings {
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct AdjustedBufferFontSize(Option<Pixels>);
|
||||
pub struct AdjustedBufferFontSize(Pixels);
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct ThemeSettingsContent {
|
||||
@ -69,12 +69,10 @@ impl BufferLineHeight {
|
||||
}
|
||||
|
||||
impl ThemeSettings {
|
||||
pub fn buffer_font_size(&self, cx: &mut AppContext) -> Pixels {
|
||||
let font_size = *cx
|
||||
.default_global::<AdjustedBufferFontSize>()
|
||||
.0
|
||||
.get_or_insert(self.buffer_font_size.into());
|
||||
font_size.max(MIN_FONT_SIZE)
|
||||
pub fn buffer_font_size(&self, cx: &AppContext) -> Pixels {
|
||||
cx.try_global::<AdjustedBufferFontSize>()
|
||||
.map_or(self.buffer_font_size, |size| size.0)
|
||||
.max(MIN_FONT_SIZE)
|
||||
}
|
||||
|
||||
pub fn line_height(&self) -> f32 {
|
||||
@ -83,9 +81,9 @@ impl ThemeSettings {
|
||||
}
|
||||
|
||||
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 delta = adjusted_size - buffer_font_size;
|
||||
let delta = *adjusted_size - buffer_font_size;
|
||||
size + delta
|
||||
} else {
|
||||
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)) {
|
||||
let buffer_font_size = ThemeSettings::get_global(cx).buffer_font_size;
|
||||
let adjusted_size = cx
|
||||
.default_global::<AdjustedBufferFontSize>()
|
||||
.0
|
||||
.get_or_insert(buffer_font_size);
|
||||
f(adjusted_size);
|
||||
*adjusted_size = (*adjusted_size).max(MIN_FONT_SIZE - buffer_font_size);
|
||||
let mut adjusted_size = cx
|
||||
.try_global::<AdjustedBufferFontSize>()
|
||||
.map_or(buffer_font_size, |adjusted_size| adjusted_size.0);
|
||||
|
||||
f(&mut adjusted_size);
|
||||
adjusted_size = adjusted_size.max(MIN_FONT_SIZE);
|
||||
cx.set_global(AdjustedBufferFontSize(adjusted_size));
|
||||
cx.refresh();
|
||||
}
|
||||
|
||||
pub fn reset_font_size(cx: &mut AppContext) {
|
||||
if cx.has_global::<AdjustedBufferFontSize>() {
|
||||
cx.global_mut::<AdjustedBufferFontSize>().0 = None;
|
||||
cx.remove_global::<AdjustedBufferFontSize>();
|
||||
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.
|
||||
fn text_buffer(self, cx: &mut WindowContext) -> Self {
|
||||
let settings = ThemeSettings::get_global(cx);
|
||||
|
||||
self.text_size(settings.buffer_font_size)
|
||||
self.text_size(settings.buffer_font_size(cx))
|
||||
}
|
||||
|
||||
/// 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()])
|
||||
})
|
||||
.register_action(|_, action: &OpenBrowser, cx| cx.open_url(&action.url))
|
||||
//todo!(buffer font size)
|
||||
// cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| {
|
||||
// theme::adjust_font_size(cx, |size| *size += 1.0)
|
||||
// });
|
||||
// cx.add_global_action(move |_: &DecreaseBufferFontSize, cx| {
|
||||
// theme::adjust_font_size(cx, |size| *size -= 1.0)
|
||||
// });
|
||||
// cx.add_global_action(move |_: &ResetBufferFontSize, cx| theme::reset_font_size(cx));
|
||||
.register_action(move |_, _: &IncreaseBufferFontSize, cx| {
|
||||
theme::adjust_font_size(cx, |size| *size += px(1.0))
|
||||
})
|
||||
.register_action(move |_, _: &DecreaseBufferFontSize, cx| {
|
||||
theme::adjust_font_size(cx, |size| *size -= px(1.0))
|
||||
})
|
||||
.register_action(move |_, _: &ResetBufferFontSize, cx| theme::reset_font_size(cx))
|
||||
.register_action(|_, _: &install_cli::Install, cx| {
|
||||
cx.spawn(|_, cx| async move {
|
||||
install_cli::install_cli(cx.deref())
|
||||
|
Loading…
Reference in New Issue
Block a user