aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-07 11:08:31 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-07 11:08:31 +0000
commitba48109a9b6c4d125567eb75d7a9fe29d6640385 (patch)
tree9cb01b860fb62033f0ee1f2145814a4355101ff2 /render.c
parentrender: sixel: fix assertion: x/y coords may be outside visible area (diff)
parentconfig: add optional ‘center’ argument to ‘pad’ (diff)
Merge branch 'center-grid-content'
Closes #273
Diffstat (limited to 'render.c')
-rw-r--r--render.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/render.c b/render.c
index 669b7f67..16198589 100644
--- a/render.c
+++ b/render.c
@@ -2638,10 +2638,20 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
assert(new_rows >= 1);
/* Margins */
- term->margins.left = pad_x;
- term->margins.top = pad_y;
- term->margins.right = term->width - new_cols * term->cell_width - term->margins.left;
- term->margins.bottom = term->height - new_rows * term->cell_height - term->margins.top;
+ const int grid_width = new_cols * term->cell_width;
+ const int grid_height = new_rows * term->cell_height;
+ const int total_x_pad = term->width - grid_width;
+ const int total_y_pad = term->height - grid_height;
+
+ if (term->conf->center) {
+ term->margins.left = total_x_pad / 2;
+ term->margins.top = total_y_pad / 2;
+ } else {
+ term->margins.left = pad_x;
+ term->margins.top = pad_y;
+ }
+ term->margins.right = total_x_pad - term->margins.left;
+ term->margins.bottom = total_y_pad - term->margins.top;
assert(term->margins.left >= pad_x);
assert(term->margins.right >= pad_x);