Skip to main content

beamterm_data/
cell_size.rs

1/// Dimensions of a terminal cell in pixels.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub struct CellSize {
4    /// Cell width in pixels.
5    pub width: i32,
6    /// Cell height in pixels.
7    pub height: i32,
8}
9
10impl CellSize {
11    /// Creates a new cell size with the given width and height in pixels.
12    #[must_use]
13    pub fn new(width: i32, height: i32) -> Self {
14        Self { width, height }
15    }
16
17    /// Scales each dimension by the given factor, rounding to the nearest integer.
18    #[must_use]
19    pub fn scale(self, factor: f32) -> Self {
20        Self {
21            width: (self.width as f32 * factor).round() as i32,
22            height: (self.height as f32 * factor).round() as i32,
23        }
24    }
25}