mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-14 04:27:57 -05:00
render: fix rounding errors when setting initial window size and scale != 1
An odd cell width/height sometimes resulted in an odd grid size. Combined with a scaling factor of e.g. 2, that led to a rounding error when converting pixel sizes to logical window sizes. As a result, the _next_ configure event would cause us to loose a pixel, which led to us dropping a row from the grid.
This commit is contained in:
parent
185a6048a7
commit
2e7102c956
1 changed files with 16 additions and 4 deletions
20
render.c
20
render.c
|
|
@ -2056,11 +2056,23 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
|
|||
break;
|
||||
|
||||
case CONF_SIZE_CELLS:
|
||||
width = 2 * term->conf->pad_x * scale;
|
||||
height = 2 * term->conf->pad_y * scale;
|
||||
width = term->conf->size.cells.width * term->cell_width;
|
||||
height = term->conf->size.cells.height * term->cell_height;
|
||||
|
||||
width += term->conf->size.cells.width * term->cell_width;
|
||||
height += term->conf->size.cells.height * term->cell_height;
|
||||
width += 2 * term->conf->pad_x * scale;
|
||||
height += 2 * term->conf->pad_y * scale;
|
||||
|
||||
/*
|
||||
* Ensure we can scale to logical size, and back to
|
||||
* pixels without truncating.
|
||||
*/
|
||||
if (width % scale)
|
||||
width += scale - width % scale;
|
||||
if (height % scale)
|
||||
height += scale - height % scale;
|
||||
|
||||
assert(width % scale == 0);
|
||||
assert(height % scale == 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue