gui: cache shaping and layout of fancy tab bar, allow placing at bottom

We only need to recompute when the tab content changes, or when
the window is resized, plus invalidations of the shape cache
of texture atlas filling up.

Hover events don't need to re-shape.

We can now also place the tab bar at the bottom of the screen again.
This commit is contained in:
Wez Furlong committed 2021-12-28 12:29:54 -07:00
1 parent cc2bbced82
commit 494a0983ee
6 files changed
+49 -55

No files matched your search

-7
View File
@@ -1598,13 +1598,6 @@ impl Config {
Self::default().compute_extra_defaults(None)
}
/// Compute effective value of tab_bar_at_bottom.
/// If use_fancy_tab_bar is enabled, we cannot put the tab bar at
/// the bottom.
pub fn tab_bar_at_bottom(&self) -> bool {
self.tab_bar_at_bottom && !self.use_fancy_tab_bar
}
pub fn key_bindings(&self) -> HashMap<(KeyCode, Modifiers), KeyAssignment> {
let mut map = HashMap::new();
+1 -1
View File
@@ -13,7 +13,7 @@ As features stabilize some brief notes about them will accumulate here.
#### New
* Fancy Tab Bars are now the default. The default tab bar colors have changed to accommodate the new more native look. They are not compatible with `tab_bar_at_bottom`. You can turn them off by setting `use_fancy_tab_bar = false`.
* Fancy Tab Bars are now the default. The default tab bar colors have changed to accommodate the new more native look. You can turn them off by setting `use_fancy_tab_bar = false`.
* Support for the [Kitty Image Protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/) is now enabled by default. Most of the protocol is supported; animation support is not yet implemented. Try the amazing [notcurses](https://notcurses.com/) if you want to see what modern terminal graphics can do! [#986](https://github.com/wez/wezterm/issues/986)
* unix domains now support an optional `proxy_command` to use in place of a direct unix socket connection. [Read more about multiplexing unix domains](multiplexing.html#unix-domains)
* [ScrollToTop](config/lua/keyassignment/ScrollToTop.md) and [ScrollToBottom](config/lua/keyassignment/ScrollToBottom.md) key assignments [#1360](https://github.com/wez/wezterm/issues/1360)
+1 -1
View File
@@ -375,7 +375,7 @@ pub struct ComputedElement {
}
impl ComputedElement {
fn translate(&mut self, delta: euclid::Vector2D<f32, PixelUnit>) {
pub fn translate(&mut self, delta: euclid::Vector2D<f32, PixelUnit>) {
self.bounds = self.bounds.translate(delta);
self.border_rect = self.border_rect.translate(delta);
self.padding = self.padding.translate(delta);
+5 -1
View File
@@ -281,6 +281,7 @@ pub struct TermWindow {
show_tab_bar: bool,
show_scroll_bar: bool,
tab_bar: TabBarState,
fancy_tab_bar: Option<box_model::ComputedElement>,
pub right_status: String,
last_ui_item: Option<UIItem>,
/// Tracks whether the current mouse-down event is part of click-focus.
@@ -698,6 +699,7 @@ impl TermWindow {
show_tab_bar,
show_scroll_bar: config.enable_scroll_bar,
tab_bar: TabBarState::default(),
fancy_tab_bar: None,
right_status: String::new(),
last_mouse_coords: (0, -1),
last_mouse_terminal_coords: (0, 0),
@@ -1302,6 +1304,7 @@ impl TermWindow {
self.show_scroll_bar = config.enable_scroll_bar;
self.shape_cache.borrow_mut().clear();
self.fancy_tab_bar.take();
self.input_map = InputMap::new(&config);
self.leader_is_down = None;
let dimensions = self.dimensions;
@@ -1389,7 +1392,7 @@ impl TermWindow {
.bottom
.evaluate_as_pixels(v_context) as u16;
let tab_bar_y = if self.config.tab_bar_at_bottom() {
let tab_bar_y = if self.config.tab_bar_at_bottom {
let avail_height = self
.dimensions
.pixel_height
@@ -1417,6 +1420,7 @@ impl TermWindow {
);
if new_tab_bar != self.tab_bar {
self.tab_bar = new_tab_bar;
self.invalidate_fancy_tab_bar();
if let Some(window) = self.window.as_ref() {
window.invalidate();
}
+2 -2
View File
@@ -58,7 +58,7 @@ impl super::TermWindow {
self.current_mouse_event.replace(event.clone());
let first_line_offset = if self.show_tab_bar && !self.config.tab_bar_at_bottom() {
let first_line_offset = if self.show_tab_bar && !self.config.tab_bar_at_bottom {
self.tab_bar_pixel_height().unwrap_or(0.) as isize
} else {
0
@@ -224,7 +224,7 @@ impl super::TermWindow {
current_viewport,
&self.dimensions,
self.tab_bar_pixel_height().unwrap_or(0.),
self.config.tab_bar_at_bottom(),
self.config.tab_bar_at_bottom,
);
self.set_viewport(pane.pane_id(), Some(row), dims);
context.invalidate();
+40 -43
View File
@@ -1,3 +1,4 @@
use super::box_model::*;
use crate::customglyph::BlockKey;
use crate::customglyph::*;
use crate::glium::texture::SrgbTexture2d;
@@ -20,7 +21,8 @@ use ::window::glium::{uniform, BlendingFunction, LinearBlendingFactor, Surface};
use ::window::{PointF, RectF, Size, WindowOps};
use anyhow::anyhow;
use config::{
ConfigHandle, DimensionContext, HsbTransform, TabBarColors, TextStyle, VisualBellTarget,
ConfigHandle, Dimension, DimensionContext, HsbTransform, TabBarColors, TextStyle,
VisualBellTarget,
};
use euclid::num::Zero;
use mux::pane::Pane;
@@ -215,6 +217,7 @@ impl super::TermWindow {
log::trace!("grow texture atlas to {}", size);
self.recreate_texture_atlas(Some(size))
};
self.invalidate_fancy_tab_bar();
if let Err(err) = result {
if self.allow_images {
@@ -234,6 +237,7 @@ impl super::TermWindow {
}
}
} else if err.root_cause().downcast_ref::<ClearShapeCache>().is_some() {
self.invalidate_fancy_tab_bar();
self.shape_cache.borrow_mut().clear();
} else {
log::error!("paint_opengl_pass failed: {:#}", err);
@@ -422,10 +426,11 @@ impl super::TermWindow {
Self::tab_bar_pixel_height_impl(&self.config, &self.fonts, &self.render_metrics)
}
fn paint_fancy_tab_bar(&self, palette: &ColorPalette) -> anyhow::Result<Vec<UIItem>> {
use super::box_model::*;
use config::Dimension;
pub fn invalidate_fancy_tab_bar(&mut self) {
self.fancy_tab_bar.take();
}
pub fn build_fancy_tab_bar(&self, palette: &ColorPalette) -> anyhow::Result<ComputedElement> {
let font = self.fonts.title_font()?;
let items = self.tab_bar.items();
let colors = self
@@ -665,9 +670,10 @@ impl super::TermWindow {
.display(DisplayType::Block)
.item_type(UIItemType::TabBar(TabBarItem::None))
.colors(bar_colors);
let metrics = RenderMetrics::with_font_metrics(&font.metrics());
let computed = self.compute_element(
let mut computed = self.compute_element(
&LayoutContext {
height: DimensionContext {
dpi: self.dimensions.dpi as f32,
@@ -691,56 +697,47 @@ impl super::TermWindow {
&tabs,
)?;
if false {
fn summarize(ele: &ComputedElement) {
log::info!(
"ele {:?} with bounds={:?} content_rect={:?} padding={:?} border={:?}",
ele.item_type,
ele.bounds,
ele.content_rect,
ele.padding,
ele.border_rect,
);
match &ele.content {
ComputedElementContent::Text(_) => {}
ComputedElementContent::Children(kids) => {
for kid in kids {
summarize(kid);
}
}
}
}
log::info!("Computed:");
summarize(&computed);
if self.config.tab_bar_at_bottom {
computed.translate(euclid::vec2(
0.,
self.dimensions.pixel_height as f32 - computed.bounds.height(),
));
}
Ok(computed)
}
fn paint_fancy_tab_bar(&self) -> anyhow::Result<Vec<UIItem>> {
let computed = self
.fancy_tab_bar
.as_ref()
.ok_or_else(|| anyhow::anyhow!("paint_tab_bar called but fancy_tab_bar is None"))?;
let ui_items = computed.ui_items();
let gl_state = self.render_state.as_ref().unwrap();
let vb = [&gl_state.vb[0], &gl_state.vb[1], &gl_state.vb[2]];
let mut vb_mut0 = vb[0].current_vb_mut();
let mut vb_mut1 = vb[1].current_vb_mut();
let mut vb_mut2 = vb[2].current_vb_mut();
let mut layers = [
vb[0].map(&mut vb_mut0),
vb[1].map(&mut vb_mut1),
vb[2].map(&mut vb_mut2),
];
self.render_element(&computed, &mut layers[1], None)?;
let vb = &gl_state.vb[1];
let mut vb_mut = vb.current_vb_mut();
let mut layer1 = vb.map(&mut vb_mut);
self.render_element(&computed, &mut layer1, None)?;
Ok(ui_items)
}
fn paint_tab_bar(&mut self) -> anyhow::Result<()> {
let palette = self.palette().clone();
if self.config.use_fancy_tab_bar {
self.ui_items
.append(&mut self.paint_fancy_tab_bar(&palette)?);
if self.fancy_tab_bar.is_none() {
let palette = self.palette().clone();
self.fancy_tab_bar
.replace(self.build_fancy_tab_bar(&palette)?);
}
self.ui_items.append(&mut self.paint_fancy_tab_bar()?);
return Ok(());
}
let palette = self.palette().clone();
let tab_bar_height = self.tab_bar_pixel_height()?;
let tab_bar_y = if self.config.tab_bar_at_bottom() {
let tab_bar_y = if self.config.tab_bar_at_bottom {
((self.dimensions.pixel_height as f32) - tab_bar_height).max(0.)
} else {
0.
@@ -847,7 +844,7 @@ impl super::TermWindow {
let (padding_left, padding_top) = self.padding_left_top();
let tab_bar_height = if self.show_tab_bar && !self.config.tab_bar_at_bottom() {
let tab_bar_height = if self.show_tab_bar && !self.config.tab_bar_at_bottom {
self.tab_bar_pixel_height()?
} else {
0.
@@ -1115,7 +1112,7 @@ impl super::TermWindow {
current_viewport,
&self.dimensions,
tab_bar_height,
config.tab_bar_at_bottom(),
config.tab_bar_at_bottom,
);
let thumb_top = info.top as f32;
let thumb_size = info.height as f32;
@@ -1360,7 +1357,7 @@ impl super::TermWindow {
let cell_width = self.render_metrics.cell_size.width as f32;
let cell_height = self.render_metrics.cell_size.height as f32;
let first_row_offset = if self.show_tab_bar && !self.config.tab_bar_at_bottom() {
let first_row_offset = if self.show_tab_bar && !self.config.tab_bar_at_bottom {
self.tab_bar_pixel_height()?
} else {
0.