1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 22:01:47 +03:00

gui: vertically center cell within adjusted line height

When line_height is specified, rather than applying the offset
to just the top of the cell, apply it in equal parts to the top
and the bottom so that the cell is vertically centered.

closes: https://github.com/wez/wezterm/issues/582
This commit is contained in:
Wez Furlong 2021-04-03 10:41:28 -07:00
parent 4112b74f8a
commit b441be3ac9

View File

@ -33,16 +33,21 @@ impl RenderMetrics {
metrics.cell_width.get().ceil() as usize,
);
// When line_height != 1.0, we want to adjust the baseline position
// such that we are horizontally centered.
let line_height_y_adjust = (cell_height as f64 - metrics.cell_height.get()) / 2.;
let underline_height = metrics.underline_thickness.get().round().max(1.) as isize;
let descender_row =
(cell_height as f64 + (metrics.descender - metrics.underline_position).get()) as isize;
let descender_row = (cell_height as f64
+ (metrics.descender - metrics.underline_position).get()
- line_height_y_adjust) as isize;
let descender_plus_two =
(2 * underline_height + descender_row).min(cell_height as isize - underline_height);
let strike_row = descender_row / 2;
Ok(Self {
descender: metrics.descender,
descender: metrics.descender - PixelLength::new(line_height_y_adjust),
descender_row,
descender_plus_two,
strike_row,