impl std::fmt::Debug for TexturesDelta

This commit is contained in:
Emil Ernerfeldt 2022-02-22 13:21:41 +01:00
parent 745f209c61
commit 2e1a4cf08a

View file

@ -157,6 +157,10 @@ pub struct TexturesDelta {
} }
impl TexturesDelta { impl TexturesDelta {
pub fn is_empty(&self) -> bool {
self.set.is_empty() && self.free.is_empty()
}
pub fn append(&mut self, mut newer: TexturesDelta) { pub fn append(&mut self, mut newer: TexturesDelta) {
self.set.extend(newer.set.into_iter()); self.set.extend(newer.set.into_iter());
self.free.append(&mut newer.free); self.free.append(&mut newer.free);
@ -167,3 +171,32 @@ impl TexturesDelta {
self.free.clear(); self.free.clear();
} }
} }
impl std::fmt::Debug for TexturesDelta {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut debug_struct = f.debug_struct("TexturesDelta");
if !self.set.is_empty() {
let mut string = String::new();
for (tex_id, delta) in &self.set {
let size = delta.image.size();
if let Some(pos) = delta.pos {
string += &format!(
"{:?} partial ([{} {}] - [{} {}]), ",
tex_id,
pos[0],
pos[1],
pos[0] + size[0],
pos[1] + size[1]
);
} else {
string += &format!("{:?} full {}x{}, ", tex_id, size[0], size[1]);
}
}
debug_struct.field("set", &string);
}
if !self.free.is_empty() {
debug_struct.field("free", &self.free);
}
debug_struct.finish()
}
}