mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -05:00
Combine FontOffset and GlyphOffset structs into Delta struct
The two structs are very similar, so there is no reason for them to be separate. Instead combine them into a single Delta struct, which can be used to shift a point in a two dimensional plane.
This commit is contained in:
parent
0a1dc56bcf
commit
f06be732a2
3 changed files with 15 additions and 51 deletions
|
@ -1163,54 +1163,18 @@ impl Dpi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modifications to font spacing
|
/// A delta for a point in a 2 dimensional plane
|
||||||
///
|
|
||||||
/// The way Alacritty calculates vertical and horizontal cell sizes may not be
|
|
||||||
/// ideal for all fonts. This gives the user a way to tweak those values.
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct FontOffset {
|
|
||||||
/// Extra horizontal spacing between letters
|
|
||||||
x: f32,
|
|
||||||
/// Extra vertical spacing between lines
|
|
||||||
y: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FontOffset {
|
|
||||||
/// Get letter spacing
|
|
||||||
#[inline]
|
|
||||||
pub fn x(&self) -> f32 {
|
|
||||||
self.x
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get line spacing
|
|
||||||
#[inline]
|
|
||||||
pub fn y(&self) -> f32 {
|
|
||||||
self.y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for FontOffset {
|
|
||||||
fn default() -> FontOffset {
|
|
||||||
FontOffset { x: 0.0, y: 0.0 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Modifications to glyph positions within their cells
|
|
||||||
///
|
|
||||||
/// By default the glyphs are located at the bottom of the cell which can be
|
|
||||||
/// undesirable. This gives the user a way to shift where the glyphs are
|
|
||||||
/// displayed in their cells.
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize)]
|
#[derive(Clone, Copy, Debug, Deserialize)]
|
||||||
pub struct GlyphOffset {
|
pub struct Delta {
|
||||||
/// Horizontal position
|
/// Horizontal change
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
/// Vertical position
|
/// Vertical change
|
||||||
pub y: f32,
|
pub y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GlyphOffset {
|
impl Default for Delta {
|
||||||
fn default() -> GlyphOffset {
|
fn default() -> Delta {
|
||||||
GlyphOffset { x: 0.0, y: 0.0 }
|
Delta { x: 0.0, y: 0.0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1273,11 +1237,11 @@ pub struct Font {
|
||||||
size: Size,
|
size: Size,
|
||||||
|
|
||||||
/// Extra spacing per character
|
/// Extra spacing per character
|
||||||
offset: FontOffset,
|
offset: Delta,
|
||||||
|
|
||||||
/// Glyph offset within character cell
|
/// Glyph offset within character cell
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
glyph_offset: GlyphOffset,
|
glyph_offset: Delta,
|
||||||
|
|
||||||
#[serde(default="true_bool")]
|
#[serde(default="true_bool")]
|
||||||
use_thin_strokes: bool
|
use_thin_strokes: bool
|
||||||
|
@ -1316,13 +1280,13 @@ impl Font {
|
||||||
|
|
||||||
/// Get offsets to font metrics
|
/// Get offsets to font metrics
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn offset(&self) -> &FontOffset {
|
pub fn offset(&self) -> &Delta {
|
||||||
&self.offset
|
&self.offset
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get cell offsets for glyphs
|
/// Get cell offsets for glyphs
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn glyph_offset(&self) -> &GlyphOffset {
|
pub fn glyph_offset(&self) -> &Delta {
|
||||||
&self.glyph_offset
|
&self.glyph_offset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,8 +171,8 @@ impl Display {
|
||||||
// font metrics should be computed before creating the window in the first
|
// font metrics should be computed before creating the window in the first
|
||||||
// place so that a resize is not needed.
|
// place so that a resize is not needed.
|
||||||
let metrics = glyph_cache.font_metrics();
|
let metrics = glyph_cache.font_metrics();
|
||||||
let cell_width = (metrics.average_advance + font.offset().x() as f64) as u32;
|
let cell_width = (metrics.average_advance + font.offset().x as f64) as u32;
|
||||||
let cell_height = (metrics.line_height + font.offset().y() as f64) as u32;
|
let cell_height = (metrics.line_height + font.offset().y as f64) as u32;
|
||||||
|
|
||||||
// Resize window to specified dimensions
|
// Resize window to specified dimensions
|
||||||
let dimensions = options.dimensions()
|
let dimensions = options.dimensions()
|
||||||
|
|
|
@ -28,7 +28,7 @@ use gl;
|
||||||
use index::{Line, Column, RangeInclusive};
|
use index::{Line, Column, RangeInclusive};
|
||||||
use notify::{Watcher as WatcherApi, RecommendedWatcher as Watcher, op};
|
use notify::{Watcher as WatcherApi, RecommendedWatcher as Watcher, op};
|
||||||
|
|
||||||
use config::{Config, GlyphOffset};
|
use config::{Config, Delta};
|
||||||
use term::{self, cell, RenderableCell};
|
use term::{self, cell, RenderableCell};
|
||||||
use window::{Size, Pixels};
|
use window::{Size, Pixels};
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ pub struct GlyphCache {
|
||||||
font_size: font::Size,
|
font_size: font::Size,
|
||||||
|
|
||||||
/// glyph offset
|
/// glyph offset
|
||||||
glyph_offset: GlyphOffset,
|
glyph_offset: Delta,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlyphCache {
|
impl GlyphCache {
|
||||||
|
|
Loading…
Reference in a new issue