Add window padding

This commit is contained in:
mars 2022-10-06 20:59:14 -06:00
parent b538c108b5
commit d16dc50d4d
3 changed files with 41 additions and 11 deletions

View File

@ -27,6 +27,18 @@ pub struct ColorConfig {
pub bright_white: HexColor,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct DrawConfig {
pub pad_x: u8,
pub pad_y: u8,
}
impl Default for DrawConfig {
fn default() -> Self {
Self { pad_x: 2, pad_y: 2 }
}
}
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct FontConfig {
pub normal: PathBuf,
@ -37,6 +49,7 @@ pub struct FontConfig {
pub struct Config {
pub cursor: CursorConfig,
pub colors: ColorConfig,
pub draw: DrawConfig,
pub fonts: FontConfig,
}

View File

@ -29,6 +29,14 @@ impl std::ops::Add for Point {
}
}
impl std::ops::Sub for Point {
type Output = Self;
fn sub(self, rhs: Self) -> Self {
Self(self.0 - rhs.0, self.1 - rhs.1)
}
}
impl std::ops::Mul for Point {
type Output = Self;
@ -246,6 +254,8 @@ pub struct Graphics {
pub canvas: Canvas,
pub cell_width: usize,
pub cell_height: usize,
pub pad_x: usize,
pub pad_y: usize,
pub colors: Colors,
glyph_cache: GlyphCache,
cell_cache: HashMap<Point, GlyphInfo>,
@ -269,6 +279,8 @@ impl Graphics {
canvas,
cell_width: glyph_cache.renderer.cell_width,
cell_height: glyph_cache.renderer.cell_height,
pad_x: config.draw.pad_x as usize,
pad_y: config.draw.pad_y as usize,
glyph_cache,
cell_cache,
colors,
@ -347,13 +359,16 @@ impl Graphics {
let cell_size = Point(self.cell_width, self.cell_height);
let content = term.renderable_content();
let pad_offset = Point(self.pad_x, self.pad_y);
let inner_bounds = Point(width, height) - pad_offset - pad_offset;
for cell in content.display_iter.into_iter() {
let term_col = cell.point.column.0 as usize;
let term_row = cell.point.line.0 as usize;
let term_coords = Point(term_col, term_row);
if (term_row + 1) * self.cell_height >= height
|| (term_col + 1) * self.cell_width >= width
if (term_row + 1) * self.cell_height >= inner_bounds.1
|| (term_col + 1) * self.cell_width >= inner_bounds.0
{
continue;
}
@ -370,7 +385,7 @@ impl Graphics {
self.cell_cache.insert(term_coords, glyph_info.clone());
}
let xy = term_coords * cell_size;
let xy = term_coords * cell_size + pad_offset;
let glyph = self.glyph_cache.lookup(&glyph_info);
self.canvas.blit_from_slice(xy, glyph, cell_size);
}
@ -379,23 +394,25 @@ impl Graphics {
let term_row = content.cursor.point.line.0 as usize;
let term_coords = Point(term_col, term_row);
if (term_row + 1) * self.cell_height < height && (term_col + 1) * self.cell_width < width {
if (term_row + 1) * self.cell_height < inner_bounds.1
&& (term_col + 1) * self.cell_width < inner_bounds.0
{
let mut px_row = term_row * width * self.cell_height + term_col * self.cell_width;
use alacritty_terminal::ansi::CursorShape;
match content.cursor.shape {
CursorShape::Block => {
let tl = term_coords * cell_size;
let tl = term_coords * cell_size + pad_offset;
let br = tl + cell_size;
self.canvas.draw_rect(cursor_color, tl, br);
}
CursorShape::Beam => {
let tl = term_coords * cell_size;
let tl = term_coords * cell_size + pad_offset;
let br = tl + Point(2, cell_size.1);
self.canvas.draw_rect(cursor_color, tl, br);
}
CursorShape::Underline => {
let mut tl = term_coords * cell_size;
let mut tl = term_coords * cell_size + pad_offset;
let br = tl + cell_size;
tl.1 = br.1 - 2;
self.canvas.draw_rect(cursor_color, tl, br);

View File

@ -61,8 +61,8 @@ impl App {
graphics.canvas.height as f32,
graphics.cell_width as f32,
graphics.cell_height as f32,
0.0,
0.0,
graphics.pad_x as f32,
graphics.pad_y as f32,
false,
);
@ -191,8 +191,8 @@ impl App {
height as f32,
self.graphics.cell_width as f32,
self.graphics.cell_height as f32,
0.0,
0.0,
self.graphics.pad_x as f32,
self.graphics.pad_y as f32,
false,
);