summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2018-11-11 20:24:41 +0000
committerGitHub <noreply@github.com>2018-11-11 20:24:41 +0000
commit6a0bd7409d098fac85c13f8f268adbb11c0a371e (patch)
tree92b229c03f92834e2ad26cb832a0cec8267dfe48 /src
parentdba3cccf6948fb993e02d03ca8891fbc7f6cd3e6 (diff)
Center the grid inside the window
Currently alacritty always puts the grid at the top-left position of the window. The only distance to the top-left window border is set by the padding in the config. However the grid always has a fixed size, and if a cell doesn't completely fit the screen anymore, the padding at the bottom right window corner can be significantly bigger than the padding at the top left. To fix this whenever there is more space left and there would usually be a bigger padding at the bottom right, the space is now split up and added to the padding. This should always center the grid inside the window and make sure all borders have the same padding from the text area. This screenshot shows how it has been until now: ![Before](https://u.teknik.io/kRJwg.png) Here is how it looks now: ![After](https://u.teknik.io/m4puV.png) This fixes #1065.
Diffstat (limited to 'src')
-rw-r--r--src/display.rs7
-rw-r--r--src/renderer/mod.rs38
2 files changed, 29 insertions, 16 deletions
diff --git a/src/display.rs b/src/display.rs
index 6ab622f2..5fbaf44a 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -163,7 +163,7 @@ impl Display {
f64::from(height + 2 * (f64::from(config.padding().y) * dpr) as u32) as f64);
window.set_inner_size(new_viewport_size.to_logical(dpr));
- renderer.resize(new_viewport_size, dpr);
+ renderer.resize(new_viewport_size, dpr, cell_width as i32, cell_height as i32);
viewport_size = new_viewport_size;
}
@@ -320,8 +320,11 @@ impl Display {
item.on_resize(size)
}
+ let cw = self.size_info.cell_width as i32;
+ let ch = self.size_info.cell_height as i32;
+
self.window.resize(psize);
- self.renderer.resize(psize, dpr);
+ self.renderer.resize(psize, dpr, cw, ch);
}
}
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index df219cf5..8e0fc60b 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -303,7 +303,7 @@ impl GlyphCache {
// Recompute font keys
let font = font.to_owned().with_size(size);
let (regular, bold, italic) = Self::compute_font_keys(&font, &mut self.rasterizer)?;
-
+
self.rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size() })?;
let metrics = self.rasterizer.metrics(regular, size)?;
@@ -748,20 +748,30 @@ impl QuadRenderer {
self.program = program;
}
- pub fn resize(&mut self, size: PhysicalSize, dpr: f64) {
- let (width, height) : (u32, u32) = size.into();
+ pub fn resize(&mut self, size: PhysicalSize, dpr: f64, cell_width: i32, cell_height: i32) {
+ let (width, height): (u32, u32) = size.into();
+ let (width, height) = (width as i32, height as i32);
+
+ let mut padding_x = (f64::from(self.program.padding_x) * dpr) as i32;
+ let mut padding_y = (f64::from(self.program.padding_y) * dpr) as i32;
- let padding_x = (f64::from(self.program.padding_x) * dpr) as i32;
- let padding_y = (f64::from(self.program.padding_y) * dpr) as i32;
+ // Add padding to center the grid inside the window
+ padding_y += ((height - 2 * padding_y) % cell_height) / 2;
+ padding_x += ((width - 2 * padding_x) % cell_width) / 2;
// viewport
unsafe {
- gl::Viewport(padding_x, padding_y, (width as i32) - 2 * padding_x, (height as i32) - 2 * padding_y);
+ gl::Viewport(padding_x, padding_y, width - 2 * padding_x, height - 2 * padding_y);
}
// update projection
self.program.activate();
- self.program.update_projection(width as f32, height as f32, dpr as f32);
+ self.program.update_projection(
+ width as f32,
+ height as f32,
+ padding_x as f32,
+ padding_y as f32,
+ );
self.program.deactivate();
}
}
@@ -1051,6 +1061,9 @@ impl ShaderProgram {
assert_uniform_valid!(projection, term_dim, cell_dim);
+ let padding_x = (f32::from(config.padding().x) * dpr as f32).floor();
+ let padding_y = (f32::from(config.padding().y) * dpr as f32).floor();
+
let shader = ShaderProgram {
id: program,
u_projection: projection,
@@ -1058,21 +1071,18 @@ impl ShaderProgram {
u_cell_dim: cell_dim,
u_visual_bell: visual_bell,
u_background: background,
- padding_x: config.padding().x,
- padding_y: config.padding().y,
+ padding_x: padding_x as u8,
+ padding_y: padding_y as u8,
};
- shader.update_projection(size.width as f32, size.height as f32, dpr as f32);
+ shader.update_projection(size.width as f32, size.height as f32, padding_x, padding_y);
shader.deactivate();
Ok(shader)
}
- fn update_projection(&self, width: f32, height: f32, dpr: f32) {
- let padding_x = (f32::from(self.padding_x) * dpr).floor();
- let padding_y = (f32::from(self.padding_y) * dpr).floor();
-
+ fn update_projection(&self, width: f32, height: f32, padding_x: f32, padding_y: f32) {
// Bounds check
if (width as u32) < (2 * padding_x as u32) ||
(height as u32) < (2 * padding_y as u32)