epaint stats: correctly count the impact of Shape::Text

This commit is contained in:
Emil Ernerfeldt 2021-08-26 20:44:42 +02:00
parent 7e9c3291bd
commit a9467fc5df

View file

@ -57,6 +57,19 @@ impl std::ops::AddAssign for AllocInfo {
} }
} }
impl std::iter::Sum for AllocInfo {
fn sum<I>(iter: I) -> Self
where
I: Iterator<Item = Self>,
{
let mut sum = Self::default();
for value in iter {
sum += value;
}
sum
}
}
impl AllocInfo { impl AllocInfo {
// pub fn from_shape(shape: &Shape) -> Self { // pub fn from_shape(shape: &Shape) -> Self {
// match shape { // match shape {
@ -72,7 +85,13 @@ impl AllocInfo {
// } // }
pub fn from_galley(galley: &Galley) -> Self { pub fn from_galley(galley: &Galley) -> Self {
Self::from_slice(galley.text.as_bytes()) + Self::from_slice(&galley.rows) Self::from_slice(galley.text.as_bytes())
+ Self::from_slice(&galley.rows)
+ galley.rows.iter().map(Self::from_galley_row).sum()
}
fn from_galley_row(row: &crate::text::Row) -> Self {
Self::from_slice(&row.x_offsets) + Self::from_slice(&row.uv_rects)
} }
pub fn from_mesh(mesh: &Mesh) -> Self { pub fn from_mesh(mesh: &Mesh) -> Self {