mirror of
https://github.com/wez/wezterm.git
synced 2024-11-12 21:30:45 +03:00
always use own box glyphs for pane splits
This section of the code wasn't looking up the custom glyphs and would always use the font. We can make rendering a little more efficient if we skip the font resolution for this case, and the code is much simpler if we just use our own box drawing glyphs, so that's what we're doing here. refs: #584
This commit is contained in:
parent
843dd88bb5
commit
0b5444ccfd
@ -515,11 +515,12 @@ impl super::TermWindow {
|
||||
let mut vb = gl_state.glyph_vertex_buffer.borrow_mut();
|
||||
let mut quads = gl_state.quads.map(&mut vb);
|
||||
let config = &self.config;
|
||||
let text = if split.direction == SplitDirection::Horizontal {
|
||||
"│"
|
||||
let block = BlockKey::from_char(if split.direction == SplitDirection::Horizontal {
|
||||
'\u{2502}'
|
||||
} else {
|
||||
"─"
|
||||
};
|
||||
'\u{2500}'
|
||||
})
|
||||
.expect("to have box drawing glyph");
|
||||
let palette = pane.palette();
|
||||
let foreground = rgbcolor_to_window_color(palette.split);
|
||||
let background = rgbcolor_alpha_to_window_color(
|
||||
@ -531,114 +532,41 @@ impl super::TermWindow {
|
||||
},
|
||||
);
|
||||
|
||||
let style = self.fonts.match_style(&config, &CellAttributes::default());
|
||||
let glyph_info = {
|
||||
let key = BorrowedShapeCacheKey { style, text };
|
||||
match self.lookup_cached_shape(&key) {
|
||||
Some(Ok(info)) => info,
|
||||
Some(Err(err)) => return Err(err),
|
||||
None => {
|
||||
let font = self.fonts.resolve_font(style)?;
|
||||
let window = self.window.as_ref().unwrap().clone();
|
||||
match font.shape(
|
||||
text,
|
||||
move || window.notify(TermWindowNotif::InvalidateShapeCache),
|
||||
BlockKey::filter_out_synthetic,
|
||||
) {
|
||||
Ok(info) => {
|
||||
let line = Line::from_text(&text, &CellAttributes::default());
|
||||
let clusters = line.cluster();
|
||||
let glyphs = self.glyph_infos_to_glyphs(
|
||||
&clusters[0],
|
||||
&line,
|
||||
&style,
|
||||
&mut gl_state.glyph_cache.borrow_mut(),
|
||||
&info,
|
||||
)?;
|
||||
let shaped = ShapedInfo::process(
|
||||
&self.render_metrics,
|
||||
&clusters[0],
|
||||
&info,
|
||||
&glyphs,
|
||||
);
|
||||
self.shape_cache
|
||||
.borrow_mut()
|
||||
.put(key.to_owned(), Ok(Rc::new(shaped)));
|
||||
self.lookup_cached_shape(&key).unwrap().unwrap()
|
||||
}
|
||||
Err(err) => {
|
||||
if err.root_cause().downcast_ref::<ClearShapeCache>().is_some() {
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
let res = anyhow!("shaper error: {}", err);
|
||||
self.shape_cache.borrow_mut().put(key.to_owned(), Err(err));
|
||||
return Err(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let first_row_offset = if self.show_tab_bar && !self.config.tab_bar_at_bottom {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let white_space = gl_state.util_sprites.white_space.texture_coords();
|
||||
|
||||
for info in glyph_info.iter() {
|
||||
let glyph = &info.glyph;
|
||||
let left = info.pos.x_offset.get() as f32 + info.pos.bearing_x;
|
||||
let top = ((PixelLength::new(self.render_metrics.cell_size.height as f64)
|
||||
+ self.render_metrics.descender)
|
||||
- (glyph.y_offset + glyph.bearing_y))
|
||||
.get() as f32;
|
||||
|
||||
let texture = glyph
|
||||
.texture
|
||||
.as_ref()
|
||||
.unwrap_or(&gl_state.util_sprites.white_space);
|
||||
let underline_tex_rect = gl_state.util_sprites.white_space.texture_coords();
|
||||
|
||||
let x_y_iter: Box<dyn Iterator<Item = (usize, usize)>> = if split.direction
|
||||
== SplitDirection::Horizontal
|
||||
{
|
||||
let x_y_iter: Box<dyn Iterator<Item = (usize, usize)>> =
|
||||
if split.direction == SplitDirection::Horizontal {
|
||||
Box::new(std::iter::repeat(split.left).zip(split.top..split.top + split.size))
|
||||
} else {
|
||||
Box::new((split.left..split.left + split.size).zip(std::iter::repeat(split.top)))
|
||||
};
|
||||
for (x, y) in x_y_iter {
|
||||
let slice = SpriteSlice {
|
||||
cell_idx: 0,
|
||||
num_cells: info.pos.num_cells as usize,
|
||||
cell_width: self.render_metrics.cell_size.width as usize,
|
||||
scale: glyph.scale as f32,
|
||||
left_offset: left,
|
||||
};
|
||||
for (x, y) in x_y_iter {
|
||||
let sprite = gl_state
|
||||
.glyph_cache
|
||||
.borrow_mut()
|
||||
.cached_block(block)?
|
||||
.texture_coords();
|
||||
|
||||
let pixel_rect = slice.pixel_rect(texture);
|
||||
let texture_rect = texture.texture.to_texture_coords(pixel_rect);
|
||||
let mut quad = match quads.cell(x, y + first_row_offset) {
|
||||
Ok(quad) => quad,
|
||||
Err(_) => break,
|
||||
};
|
||||
|
||||
let bottom = (pixel_rect.size.height as f32 * glyph.scale as f32) + top
|
||||
- self.render_metrics.cell_size.height as f32;
|
||||
let right = pixel_rect.size.width as f32 + left
|
||||
- self.render_metrics.cell_size.width as f32;
|
||||
|
||||
let mut quad = match quads.cell(x, y + first_row_offset) {
|
||||
Ok(quad) => quad,
|
||||
Err(_) => break,
|
||||
};
|
||||
|
||||
quad.set_fg_color(foreground);
|
||||
quad.set_underline_color(foreground);
|
||||
quad.set_bg_color(background);
|
||||
quad.set_hsv(None);
|
||||
quad.set_texture(texture_rect);
|
||||
quad.set_texture_adjust(left, top, right, bottom);
|
||||
quad.set_underline(underline_tex_rect);
|
||||
quad.set_has_color(glyph.has_color);
|
||||
quad.set_cursor(underline_tex_rect);
|
||||
quad.set_cursor_color(background);
|
||||
}
|
||||
quad.set_fg_color(foreground);
|
||||
quad.set_underline_color(foreground);
|
||||
quad.set_bg_color(background);
|
||||
quad.set_hsv(None);
|
||||
quad.set_texture(sprite);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_underline(white_space);
|
||||
quad.set_has_color(false);
|
||||
quad.set_cursor(white_space);
|
||||
quad.set_cursor_color(background);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user