Checkpoint

This commit is contained in:
Nathan Sobo 2023-09-27 22:02:48 -06:00
parent 7524f7fbe8
commit 8be8047b8d
2 changed files with 51 additions and 21 deletions

View file

@ -29,13 +29,17 @@ impl<T: Clone + Debug> Point<T> {
} }
} }
impl<T: Clone + Debug + Mul<S, Output = T>, S: Clone> Mul<S> for Point<T> { impl<T, Rhs> Mul<Rhs> for Point<T>
type Output = Self; where
T: Mul<Rhs, Output = Rhs> + Clone + Debug,
Rhs: Clone + Debug,
{
type Output = Point<Rhs>;
fn mul(self, rhs: S) -> Self::Output { fn mul(self, rhs: Rhs) -> Self::Output {
Self { Point {
x: self.x.clone() * rhs.clone(), x: self.x * rhs.clone(),
y: self.y.clone() * rhs, y: self.y * rhs,
} }
} }
} }
@ -125,13 +129,17 @@ impl<T: Clone + Debug> Size<T> {
} }
} }
impl<T: Clone + Debug + Mul<S, Output = T>, S: Clone> Mul<S> for Size<T> { impl<T, Rhs> Mul<Rhs> for Size<T>
type Output = Self; where
T: Mul<Rhs, Output = Rhs> + Debug + Clone,
Rhs: Debug + Clone,
{
type Output = Size<Rhs>;
fn mul(self, rhs: S) -> Self::Output { fn mul(self, rhs: Rhs) -> Self::Output {
Self { Size {
width: self.width.clone() * rhs.clone(), width: self.width * rhs.clone(),
height: self.height.clone() * rhs, height: self.height * rhs,
} }
} }
} }
@ -190,14 +198,16 @@ pub struct Bounds<T: Clone + Debug> {
unsafe impl<T: Clone + Debug + Zeroable + Pod> Zeroable for Bounds<T> {} unsafe impl<T: Clone + Debug + Zeroable + Pod> Zeroable for Bounds<T> {}
unsafe impl<T: Clone + Debug + Zeroable + Pod> Pod for Bounds<T> {} unsafe impl<T: Clone + Debug + Zeroable + Pod> Pod for Bounds<T> {}
impl<T: Clone + Debug + Mul<S, Output = T>, S: Clone> Mul<S> for Bounds<T> // Bounds<f32> * Pixels = Bounds<Pixels>
impl<T, Rhs> Mul<Rhs> for Bounds<T>
where where
T: Mul<S, Output = T>, T: Mul<Rhs, Output = Rhs> + Clone + Debug,
Rhs: Clone + Debug,
{ {
type Output = Self; type Output = Bounds<Rhs>;
fn mul(self, rhs: S) -> Self::Output { fn mul(self, rhs: Rhs) -> Self::Output {
Self { Bounds {
origin: self.origin * rhs.clone(), origin: self.origin * rhs.clone(),
size: self.size * rhs, size: self.size * rhs,
} }
@ -404,6 +414,14 @@ impl Mul<f32> for Pixels {
} }
} }
impl Mul<Pixels> for f32 {
type Output = Pixels;
fn mul(self, rhs: Pixels) -> Self::Output {
Pixels(self * rhs.0)
}
}
impl Pixels { impl Pixels {
pub fn round(&self) -> Self { pub fn round(&self) -> Self {
Self(self.0.round()) Self(self.0.round())

View file

@ -8,7 +8,7 @@ use line_wrapper::*;
pub use text_layout_cache::*; pub use text_layout_cache::*;
use crate::{ use crate::{
px, Bounds, Hsla, Pixels, PlatformTextSystem, Point, Result, SharedString, UnderlineStyle, px, Bounds, Hsla, Pixels, PlatformTextSystem, Point, Result, SharedString, Size, UnderlineStyle,
}; };
use collections::HashMap; use collections::HashMap;
use core::fmt; use core::fmt;
@ -90,9 +90,21 @@ impl TextSystem {
}) })
} }
pub fn em_advance(&self, font_id: FontId, font_size: Pixels) -> Pixels { pub fn advance(&self, font: &Font, font_size: Pixels, ch: char) -> Result<Size<Pixels>> {
todo!() let font_id = self.font_id(font)?;
// self.font_cache.em_advance(font_id, font_size) let glyph_id = self
.platform_text_system
.glyph_for_char(font_id, ch)
.ok_or_else(|| anyhow!("glyph not found for character '{}'", ch))?;
let result =
self.platform_text_system.advance(font_id, glyph_id)? / self.units_per_em(font)? as f32;
let result = result * font_size;
Ok(todo!())
}
pub fn units_per_em(&self, font: &Font) -> Result<u32> {
self.read_metrics(font, |metrics| metrics.units_per_em as u32)
} }
pub fn line_height(&self, font_size: Pixels) -> Pixels { pub fn line_height(&self, font_size: Pixels) -> Pixels {