1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-27 12:23:46 +03:00

tab bar: constrain to constant height

The tab bar height could vary by a couple of pixels depending on the
text shown inside it, which results in visual jitter as the title bar
changes.

Avoid that: always return our constant reserved amount of space for the
tab bar, even if it means that there are a couple of pixels "wasted".

cc: @davidrios
This commit is contained in:
Wez Furlong 2022-04-01 09:31:59 -07:00
parent dc414dfde0
commit bd02d33bf5
2 changed files with 6 additions and 17 deletions

View File

@ -639,7 +639,7 @@ impl TermWindow {
// for the tab bar state. // for the tab bar state.
let show_tab_bar = config.enable_tab_bar && !config.hide_tab_bar_if_only_one_tab; let show_tab_bar = config.enable_tab_bar && !config.hide_tab_bar_if_only_one_tab;
let tab_bar_height = if show_tab_bar { let tab_bar_height = if show_tab_bar {
Self::tab_bar_pixel_height_impl(&config, &fontconfig, &render_metrics, None)? as usize Self::tab_bar_pixel_height_impl(&config, &fontconfig, &render_metrics)? as usize
} else { } else {
0 0
}; };

View File

@ -442,29 +442,17 @@ impl super::TermWindow {
config: &ConfigHandle, config: &ConfigHandle,
fontconfig: &wezterm_font::FontConfiguration, fontconfig: &wezterm_font::FontConfiguration,
render_metrics: &RenderMetrics, render_metrics: &RenderMetrics,
fancy_tab_bar_height: Option<f32>,
) -> anyhow::Result<f32> { ) -> anyhow::Result<f32> {
if config.use_fancy_tab_bar { if config.use_fancy_tab_bar {
if let Some(tab_bar_height) = fancy_tab_bar_height {
Ok(tab_bar_height)
} else {
let font = fontconfig.title_font()?; let font = fontconfig.title_font()?;
Ok((font.metrics().cell_height.get() as f32 * 1.75).ceil()) Ok((font.metrics().cell_height.get() as f32 * 1.75).ceil())
}
} else { } else {
Ok(render_metrics.cell_size.height as f32) Ok(render_metrics.cell_size.height as f32)
} }
} }
pub fn tab_bar_pixel_height(&self) -> anyhow::Result<f32> { pub fn tab_bar_pixel_height(&self) -> anyhow::Result<f32> {
Self::tab_bar_pixel_height_impl( Self::tab_bar_pixel_height_impl(&self.config, &self.fonts, &self.render_metrics)
&self.config,
&self.fonts,
&self.render_metrics,
self.fancy_tab_bar
.as_ref()
.map(|elem| elem.content_rect.size.height),
)
} }
pub fn invalidate_fancy_tab_bar(&mut self) { pub fn invalidate_fancy_tab_bar(&mut self) {
@ -472,6 +460,7 @@ impl super::TermWindow {
} }
pub fn build_fancy_tab_bar(&self, palette: &ColorPalette) -> anyhow::Result<ComputedElement> { pub fn build_fancy_tab_bar(&self, palette: &ColorPalette) -> anyhow::Result<ComputedElement> {
let tab_bar_height = self.tab_bar_pixel_height()?;
let font = self.fonts.title_font()?; let font = self.fonts.title_font()?;
let metrics = RenderMetrics::with_font_metrics(&font.metrics()); let metrics = RenderMetrics::with_font_metrics(&font.metrics());
let items = self.tab_bar.items(); let items = self.tab_bar.items();
@ -807,7 +796,7 @@ impl super::TermWindow {
border.left.get() as f32, border.left.get() as f32,
0., 0.,
self.dimensions.pixel_width as f32 - (border.left + border.right).get() as f32, self.dimensions.pixel_width as f32 - (border.left + border.right).get() as f32,
self.dimensions.pixel_height as f32 - (border.top + border.bottom).get() as f32, tab_bar_height,
), ),
metrics: &metrics, metrics: &metrics,
gl_state: self.render_state.as_ref().unwrap(), gl_state: self.render_state.as_ref().unwrap(),